JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / structure / AtomSpecTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.structure;
22
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNull;
25 import static org.testng.Assert.fail;
26
27 import org.testng.annotations.Test;
28
29 public class AtomSpecTest
30 {
31   @Test
32   public void testFromChimeraAtomSpec()
33   {
34     AtomSpec as = AtomSpec.fromChimeraAtomspec("#1:12.B");
35     assertEquals(as.getModelNumber(), 1);
36     assertEquals(as.getPdbResNum(), 12);
37     assertEquals(as.getChain(), "B");
38     assertNull(as.getPdbFile());
39
40     // no model - default to zero
41     as = AtomSpec.fromChimeraAtomspec(":13.C");
42     assertEquals(as.getModelNumber(), 0);
43     assertEquals(as.getPdbResNum(), 13);
44     assertEquals(as.getChain(), "C");
45     assertNull(as.getPdbFile());
46
47     // model.submodel
48     as = AtomSpec.fromChimeraAtomspec("#3.2:15");
49     assertEquals(as.getModelNumber(), 3);
50     assertEquals(as.getPdbResNum(), 15);
51     assertEquals(as.getChain(), "");
52     assertNull(as.getPdbFile());
53
54     String spec = "3:12.B";
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 = "#3:12-14.B";
65     try
66     {
67       as = AtomSpec.fromChimeraAtomspec(spec);
68       fail("Expected exception for " + spec);
69     } catch (IllegalArgumentException e)
70     {
71       // ok
72     }
73
74     spec = "";
75     try
76     {
77       as = AtomSpec.fromChimeraAtomspec(spec);
78       fail("Expected exception for " + spec);
79     } catch (IllegalArgumentException e)
80     {
81       // ok
82     }
83
84     spec = null;
85     try
86     {
87       as = AtomSpec.fromChimeraAtomspec(spec);
88       fail("Expected exception for " + spec);
89     } catch (NullPointerException e)
90     {
91       // ok
92     }
93   }
94
95   @Test
96   public void testFromChimeraXAtomSpec()
97   {
98     AtomSpec as = AtomSpec.fromChimeraXAtomspec("#1/B:12");
99     assertEquals(as.getModelNumber(), 1);
100     assertEquals(as.getPdbResNum(), 12);
101     assertEquals(as.getChain(), "B");
102     assertNull(as.getPdbFile());
103
104     // no model - default to zero
105     as = AtomSpec.fromChimeraXAtomspec("/C:13");
106     assertEquals(as.getModelNumber(), 0);
107     assertEquals(as.getPdbResNum(), 13);
108     assertEquals(as.getChain(), "C");
109     assertNull(as.getPdbFile());
110
111     // model.submodel
112     as = AtomSpec.fromChimeraXAtomspec("#3.2/:15");
113     assertEquals(as.getModelNumber(), 3);
114     assertEquals(as.getPdbResNum(), 15);
115     assertEquals(as.getChain(), "");
116     assertNull(as.getPdbFile());
117
118     String spec = "3:12.B";
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 = "#3:12-14.B";
129     try
130     {
131       as = AtomSpec.fromChimeraXAtomspec(spec);
132       fail("Expected exception for " + spec);
133     } catch (IllegalArgumentException e)
134     {
135       // ok
136     }
137
138     spec = "";
139     try
140     {
141       as = AtomSpec.fromChimeraXAtomspec(spec);
142       fail("Expected exception for " + spec);
143     } catch (IllegalArgumentException e)
144     {
145       // ok
146     }
147
148     spec = null;
149     try
150     {
151       as = AtomSpec.fromChimeraXAtomspec(spec);
152       fail("Expected exception for " + spec);
153     } catch (NullPointerException e)
154     {
155       // ok
156     }
157   }
158 }