33d332add5ba8e123eb1c9bf91bbb49f0d5ccda9
[jalview.git] / test / MCview / AtomTest.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 MCview;
22
23 import static org.testng.AssertJUnit.assertEquals;
24
25 import org.testng.Assert;
26 import org.testng.annotations.Test;
27
28 public class AtomTest
29 {
30
31   /**
32    * Test the constructor that parses a PDB file format ATOM line. Fields are in
33    * fixed column positions
34    */
35   @Test(groups = { "Functional" })
36   public void testStringConstructor()
37   {
38     Atom a = new Atom(
39             "ATOM    349  NE2 GLN A  48      22.290   8.595  17.680  1.00 14.30           N");
40     assertEquals(349, a.atomIndex);
41     assertEquals("NE", a.name);
42     assertEquals("GLN", a.resName);
43     assertEquals("A", a.chain);
44     assertEquals(48, a.resNumber);
45     assertEquals("  48 ", a.resNumIns);
46     assertEquals(' ', a.insCode);
47     assertEquals(22.290, a.x, 0.00001);
48     assertEquals(8.595, a.y, 0.00001);
49     assertEquals(17.680, a.z, 0.00001);
50     assertEquals(1f, a.occupancy, 0.00001);
51     assertEquals(14.3, a.tfactor, 0.00001);
52   }
53
54   /**
55    * Test the case where occupancy and temp factor are blank - should default to
56    * 1
57    */
58   @Test(groups = { "Functional" })
59   public void testStringConstructor_blankOccupancyTempFactor()
60   {
61     Atom a = new Atom(
62             "ATOM    349  NE2 GLN A  48      22.290   8.595  17.680                       N");
63     assertEquals(1f, a.occupancy, 0.00001);
64     assertEquals(1f, a.tfactor, 0.00001);
65   }
66
67   /**
68    * Parsing non-numeric data as Atom throws an exception
69    */
70   @Test(groups = { "Functional" })
71   public void testStringConstructor_malformed()
72   {
73     try
74     {
75       new Atom(
76               "ATOM    34N  NE2 GLN A  48      22.290   8.595  17.680  1.00 14.30           N");
77       Assert.fail("Expected exception");
78     } catch (NumberFormatException e)
79     {
80       // expected
81     }
82   }
83 }