View Javadoc
1   //******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2024.
6   //
7   // This file is part of Force Field X.
8   //
9   // Force Field X is free software; you can redistribute it and/or modify it
10  // under the terms of the GNU General Public License version 3 as published by
11  // the Free Software Foundation.
12  //
13  // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  // details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA 02111-1307 USA
21  //
22  // Linking this library statically or dynamically with other modules is making a
23  // combined work based on this library. Thus, the terms and conditions of the
24  // GNU General Public License cover the whole combination.
25  //
26  // As a special exception, the copyright holders of this library give you
27  // permission to link this library with independent modules to produce an
28  // executable, regardless of the license terms of these independent modules, and
29  // to copy and distribute the resulting executable under terms of your choice,
30  // provided that you also meet, for each linked independent module, the terms
31  // and conditions of the license of that module. An independent module is a
32  // module which is not derived from or based on this library. If you modify this
33  // library, you may extend this exception to your version of the library, but
34  // you are not obligated to do so. If you do not wish to do so, delete this
35  // exception statement from your version.
36  //
37  //******************************************************************************
38  package ffx.potential.bonded;
39  
40  import static org.junit.Assert.assertEquals;
41  import static org.junit.Assert.assertNull;
42  import static org.junit.Assert.assertTrue;
43  
44  import ffx.potential.parameters.AtomType;
45  import org.jogamp.vecmath.Vector3d;
46  import org.junit.After;
47  import org.junit.Before;
48  import org.junit.Test;
49  
50  /** Unit tests for the Atom class. */
51  public class AtomTest {
52  
53    private final double d[] = {0.0, 0.0, 0.0};
54    private Atom atom = null;
55    private Atom atom2 = null;
56    private Atom atom3 = null;
57    private Bond b = null;
58  
59    @Test(timeout = 500)
60    public void Atom_addTrajectoryCoords() {
61      int position = 1;
62      Vector3d v3d = new Vector3d(1.0, 2.0, 3.0);
63      atom.addTrajectoryCoords(v3d, position);
64      atom.setCurrentCycle(2);
65      atom.getV3D(v3d);
66      assertEquals(1.0, v3d.x, 0.0);
67      assertEquals(2.0, v3d.y, 0.0);
68      assertEquals(3.0, v3d.z, 0.0);
69    }
70  
71    @Test(timeout = 500)
72    public void Atom_constructor() {
73      String s = "Carbon";
74      Atom actualReturn = new Atom(s);
75      assertEquals("return value", s, actualReturn.getName());
76    }
77  
78    @Test(timeout = 500)
79    public void Atom_constructor3() {
80      int index = 0;
81      String i = "N";
82      AtomType mmdata = null;
83      Atom actualReturn = new Atom(index, i, mmdata, d);
84      assertEquals("return value", 0, actualReturn.getIndex());
85    }
86  
87    @Test(timeout = 500)
88    public void Atom_constructor4() {
89      int xyznum = 0;
90      String id = "O";
91      Character altLoc = 'A';
92      String r = "GLY";
93      int n = 1;
94      Character c = 'A';
95      Atom actualReturn = new Atom(xyznum, id, altLoc, d, r, n, c, 0.0, 0.0, "A");
96      assertEquals("return value", "GLY", actualReturn.getResidueName());
97    }
98  
99    @Test(timeout = 500)
100   public void Atom_destroy() {
101     boolean expectedReturn = true;
102     boolean actualReturn = atom.destroy();
103     assertEquals("return value", expectedReturn, actualReturn);
104   }
105 
106   @Test(timeout = 500)
107   public void Atom_equals() {
108     boolean expectedReturn = true;
109     boolean actualReturn = atom.equals(atom);
110     assertEquals("return value", expectedReturn, actualReturn);
111     expectedReturn = false;
112     actualReturn = atom.equals(null);
113     assertEquals("return value", expectedReturn, actualReturn);
114     Atom atom4 = new Atom(atom.getName());
115     expectedReturn = false;
116     actualReturn = atom.equals(atom4);
117     assertEquals("return value", expectedReturn, actualReturn);
118   }
119 
120   @Test(timeout = 500)
121   public void Atom_getBond() {
122     Bond expectedReturn = b;
123     Bond actualReturn = atom.getBond(atom2);
124     assertEquals("return value", expectedReturn, actualReturn);
125     actualReturn = atom.getBond(null);
126     assertNull(actualReturn);
127     actualReturn = atom.getBond(atom3);
128     assertNull(actualReturn);
129   }
130 
131   @Test(timeout = 500)
132   public void Atom_getNumBonds() {
133     int expectedReturn = 1;
134     int actualReturn = atom.getNumBonds();
135     assertEquals("return value", expectedReturn, actualReturn);
136   }
137 
138   @Test(timeout = 500)
139   public void Atom_isBonded() {
140     boolean expectedReturn = true;
141     boolean actualReturn = atom.isBonded(atom2);
142     assertEquals("return value", expectedReturn, actualReturn);
143     expectedReturn = false;
144     actualReturn = atom.isBonded(atom3);
145     assertEquals("return value", expectedReturn, actualReturn);
146     expectedReturn = false;
147     actualReturn = atom.isBonded(null);
148     assertEquals("return value", expectedReturn, actualReturn);
149   }
150 
151   @Before
152   public void setUp() {
153     atom = new Atom(1, "C", 'A', d, "GLY", 1, 'A', 0.0, 0.0, "A");
154     atom2 = new Atom("C");
155     atom3 = new Atom("O");
156     b = new Bond(atom, atom2);
157   }
158 
159   @After
160   public void tearDown() {
161     assertTrue(atom.destroy());
162     assertTrue(atom2.destroy());
163     assertTrue(atom3.destroy());
164     assertTrue(b.destroy());
165     atom = null;
166     atom2 = null;
167     atom3 = null;
168     b = null;
169   }
170 }