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