7c13c0fad77f980ba33b5a7756fddd0dc0f636fe
[jalview.git] / test / jalview / structure / AtomSpecTest.java
1 package jalview.structure;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNull;
5 import static org.testng.Assert.fail;
6
7 import org.testng.annotations.Test;
8
9 public class AtomSpecTest
10 {
11   @Test
12   public void testFromChimeraAtomSpec()
13   {
14     AtomSpec as = AtomSpec.fromChimeraAtomspec("#1:12.B");
15     assertEquals(as.getModelNumber(), 1);
16     assertEquals(as.getPdbResNum(), 12);
17     assertEquals(as.getChain(), "B");
18     assertNull(as.getPdbFile());
19
20     // no model - default to zero
21     as = AtomSpec.fromChimeraAtomspec(":13.C");
22     assertEquals(as.getModelNumber(), 0);
23     assertEquals(as.getPdbResNum(), 13);
24     assertEquals(as.getChain(), "C");
25     assertNull(as.getPdbFile());
26
27     // model.submodel
28     as = AtomSpec.fromChimeraAtomspec("#3.2:15");
29     assertEquals(as.getModelNumber(), 3);
30     assertEquals(as.getPdbResNum(), 15);
31     assertEquals(as.getChain(), "");
32     assertNull(as.getPdbFile());
33
34     String spec = "3:12.B";
35     try
36     {
37       as = AtomSpec.fromChimeraAtomspec(spec);
38       fail("Expected exception for " + spec);
39     } catch (IllegalArgumentException e)
40     {
41       // ok
42     }
43
44     spec = "#3:12-14.B";
45     try
46     {
47       as = AtomSpec.fromChimeraAtomspec(spec);
48       fail("Expected exception for " + spec);
49     } catch (IllegalArgumentException e)
50     {
51       // ok
52     }
53
54     spec = "";
55     try
56     {
57       as = AtomSpec.fromChimeraAtomspec(spec);
58       fail("Expected exception for " + spec);
59     } catch (IllegalArgumentException e)
60     {
61       // ok
62     }
63
64     spec = null;
65     try
66     {
67       as = AtomSpec.fromChimeraAtomspec(spec);
68       fail("Expected exception for " + spec);
69     } catch (NullPointerException e)
70     {
71       // ok
72     }
73   }
74
75   @Test
76   public void testFromChimeraXAtomSpec()
77   {
78     AtomSpec as = AtomSpec.fromChimeraXAtomspec("#1/B:12");
79     assertEquals(as.getModelNumber(), 1);
80     assertEquals(as.getPdbResNum(), 12);
81     assertEquals(as.getChain(), "B");
82     assertNull(as.getPdbFile());
83
84     // no model - default to zero
85     as = AtomSpec.fromChimeraXAtomspec("/C:13");
86     assertEquals(as.getModelNumber(), 0);
87     assertEquals(as.getPdbResNum(), 13);
88     assertEquals(as.getChain(), "C");
89     assertNull(as.getPdbFile());
90
91     // model.submodel
92     as = AtomSpec.fromChimeraXAtomspec("#3.2/:15");
93     assertEquals(as.getModelNumber(), 3);
94     assertEquals(as.getPdbResNum(), 15);
95     assertEquals(as.getChain(), "");
96     assertNull(as.getPdbFile());
97
98     String spec = "3:12.B";
99     try
100     {
101       as = AtomSpec.fromChimeraXAtomspec(spec);
102       fail("Expected exception for " + spec);
103     } catch (IllegalArgumentException e)
104     {
105       // ok
106     }
107
108     spec = "#3:12-14.B";
109     try
110     {
111       as = AtomSpec.fromChimeraXAtomspec(spec);
112       fail("Expected exception for " + spec);
113     } catch (IllegalArgumentException e)
114     {
115       // ok
116     }
117
118     spec = "";
119     try
120     {
121       as = AtomSpec.fromChimeraXAtomspec(spec);
122       fail("Expected exception for " + spec);
123     } catch (IllegalArgumentException e)
124     {
125       // ok
126     }
127
128     spec = null;
129     try
130     {
131       as = AtomSpec.fromChimeraXAtomspec(spec);
132       fail("Expected exception for " + spec);
133     } catch (NullPointerException e)
134     {
135       // ok
136     }
137   }
138 }