JAL-1270 JUnit to TestNG refactoring
[jalview.git] / test / MCview / AtomTest.java
1 package MCview;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import org.testng.annotations.Test;
5 import org.testng.Assert;
6
7 public class AtomTest
8 {
9
10   /**
11    * Test the constructor that parses a PDB file format ATOM line. Fields are in
12    * fixed column positions
13    */
14   @Test
15   public void testStringConstructor()
16   {
17     Atom a = new Atom(
18             "ATOM    349  NE2 GLN A  48      22.290   8.595  17.680  1.00 14.30           N");
19     assertEquals(349, a.atomIndex);
20     assertEquals("NE", a.name);
21     assertEquals("GLN", a.resName);
22     assertEquals("A", a.chain);
23     assertEquals(48, a.resNumber);
24     assertEquals("48", a.resNumIns);
25     assertEquals(' ', a.insCode);
26     assertEquals(22.290, a.x, 0.00001);
27     assertEquals(8.595, a.y, 0.00001);
28     assertEquals(17.680, a.z, 0.00001);
29     assertEquals(1f, a.occupancy, 0.00001);
30     assertEquals(14.3, a.tfactor, 0.00001);
31   }
32
33   /**
34    * Test the case where occupancy and temp factor are blank - should default to
35    * 1
36    */
37   @Test
38   public void testStringConstructor_blankOccupancyTempFactor()
39   {
40     Atom a = new Atom(
41             "ATOM    349  NE2 GLN A  48      22.290   8.595  17.680                       N");
42     assertEquals(1f, a.occupancy, 0.00001);
43     assertEquals(1f, a.tfactor, 0.00001);
44   }
45
46   /**
47    * Parsing non-numeric data as Atom throws an exception
48    */
49   @Test
50   public void testStringConstructor_malformed()
51   {
52     try
53     {
54       new Atom(
55               "ATOM    34N  NE2 GLN A  48      22.290   8.595  17.680  1.00 14.30           N");
56       Assert.fail("Expected exception");
57     } catch (NumberFormatException e)
58     {
59       // expected
60     }
61   }
62 }