$darkmode
DENOPTIM
ZMatrixAtomTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2024 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.molecularmodeling.zmatrix;
20
21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertNotEquals;
24import static org.junit.jupiter.api.Assertions.assertTrue;
25
26import org.junit.jupiter.api.Test;
27
34public class ZMatrixAtomTest
35{
36//------------------------------------------------------------------------------
37
39 {
40 ZMatrixAtom atom1 = new ZMatrixAtom(0, "C", "C.3", null, null, null,
41 1.5, 109.47, 180.0, 0);
42 ZMatrixAtom atom2 = new ZMatrixAtom(1, "C", "C.3", null, null, null,
43 1.5, 109.47, 180.0, 0);
44 ZMatrixAtom atom3 = new ZMatrixAtom(2, "C", "C.3", null, null, null,
45 1.5, 109.47, 180.0, 0);
46 ZMatrixAtom atom4 = new ZMatrixAtom(3, "H", "H.1", atom1, atom2, atom3,
47 1.0, 109.47, 180.0, -1);
48 return atom4;
49 }
50
51//------------------------------------------------------------------------------
52
53 @Test
54 public void testEquals() throws Exception
55 {
58
59 assertEquals(atom1, atom1);
60 assertEquals(atom1, atom2);
61 assertNotEquals(atom1, null);
62
63 atom2.setId(1);
64 assertNotEquals(atom1, atom2);
65
66 atom2 = getTestZMatrixAtom();
67 atom2.setSymbol("Cl");
68 assertNotEquals(atom1, atom2);
69
70 atom2 = getTestZMatrixAtom();
71 atom2.setType("XX.3");
72 assertNotEquals(atom1, atom2);
73
74 atom2 = getTestZMatrixAtom();
75 atom2.setBondLength(2.0);
76 assertNotEquals(atom1, atom2);
77
78 atom2 = getTestZMatrixAtom();
79 atom2.setAngleValue(120.0);
80 assertNotEquals(atom1, atom2);
81
82 atom2 = getTestZMatrixAtom();
83 atom2.setAngle2Value(120.0);
84 assertNotEquals(atom1, atom2);
85
86 atom2 = getTestZMatrixAtom();
87 atom2.setChiralFlag(1);
88 assertNotEquals(atom1, atom2);
89
90 atom2 = getTestZMatrixAtom();
91 atom2.setBondRefAtom(atom1);
92 assertNotEquals(atom1, atom2);
93
94 atom2 = getTestZMatrixAtom();
95 atom2.setAngleRefAtom(atom1);
96 assertNotEquals(atom1, atom2);
97
98 atom2 = getTestZMatrixAtom();
99 atom2.setAngle2RefAtom(atom1);
100 assertNotEquals(atom1, atom2);
101 }
102
103//------------------------------------------------------------------------------
104
105 @Test
106 public void testZMatrixAtomHashCode() throws Exception
107 {
108 ZMatrixAtom atom1 = new ZMatrixAtom(0, "C", "C.3", null, null, null,
109 1.5, 109.47, 180.0, 0);
110 ZMatrixAtom atom2 = new ZMatrixAtom(0, "C", "C.3", null, null, null,
111 1.5, 109.47, 180.0, 0);
112
113 assertEquals(atom1.hashCode(), atom2.hashCode(),
114 "Equal atoms should have same hash code");
115
116 atom2 = getTestZMatrixAtom();
117 atom2.setId(1);
118 assertNotEquals(atom1.hashCode(), atom2.hashCode());
119 }
120
121//------------------------------------------------------------------------------
122
123 @Test
124 public void testZMatrixBondEquals() throws Exception
125 {
126 ZMatrixAtom atom1 = new ZMatrixAtom(0, "C", "C.3", null, null, null,
127 null, null, null, null);
128 ZMatrixAtom atom2 = new ZMatrixAtom(1, "C", "C.3", null, null, null,
129 null, null, null, null);
130 ZMatrixAtom atom3 = new ZMatrixAtom(2, "H", "H.1", null, null, null,
131 null, null, null, null);
132
133 ZMatrixBond bond1 = new ZMatrixBond(atom1, atom2);
134 ZMatrixBond bond2 = new ZMatrixBond(atom1, atom2);
135 ZMatrixBond bond3 = new ZMatrixBond(atom2, atom1); // Reversed order
136 ZMatrixBond bond4 = new ZMatrixBond(atom1, atom3);
137
138 assertTrue(bond1.equals(bond2), "Identical bonds should be equal");
139 assertTrue(bond1.equals(bond3),
140 "Bonds with reversed atom order should be equal (undirected)");
141 assertFalse(bond1.equals(bond4),
142 "Bonds with different atoms should not be equal");
143 assertTrue(bond1.equals(bond1), "Bond should equal itself");
144 assertFalse(bond1.equals(null), "Bond should not equal null");
145 assertFalse(bond1.equals("not a bond"), "Bond should not equal different type");
146 }
147
148//------------------------------------------------------------------------------
149
150 @Test
151 public void testZMatrixBondHashCode() throws Exception
152 {
153 ZMatrixAtom atom1 = new ZMatrixAtom(0, "C", "C.3", null, null, null,
154 null, null, null, null);
155 ZMatrixAtom atom2 = new ZMatrixAtom(1, "C", "C.3", null, null, null,
156 null, null, null, null);
157
158 ZMatrixBond bond1 = new ZMatrixBond(atom1, atom2);
159 ZMatrixBond bond2 = new ZMatrixBond(atom2, atom1); // Reversed order
160
161 assertEquals(bond1.hashCode(), bond2.hashCode(),
162 "Bonds with reversed order should have same hash code");
163 }
164
165//------------------------------------------------------------------------------
166
167}
168
Representation of an atom in the ZMatrix.
Definition: ZMatrixAtom.java:9
void setBondLength(Double bondLength)
Set the bond length.
void setId(int id)
Set the id of the atom.
void setChiralFlag(Integer chiralFlag)
Set the chiral flag.
void setBondRefAtom(ZMatrixAtom bondRefAtom)
Package-private setter for bond reference atom (used for cloning).
void setType(String type)
Set the type of the atom.
void setAngleValue(Double angleValue)
Set the angle value.
void setAngle2Value(Double angle2Value)
Set the angle2 value.
void setSymbol(String symbol)
Set the symbol of the atom.
void setAngle2RefAtom(ZMatrixAtom angle2RefAtom)
Package-private setter for angle2 reference atom (used for cloning).
void setAngleRefAtom(ZMatrixAtom angleRefAtom)
Package-private setter for angle reference atom (used for cloning).
Representation of a bond in the ZMatrix.
Definition: ZMatrixBond.java:7