/
AbstractAtomTest.java
237 lines (208 loc) · 7.51 KB
/
AbstractAtomTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* $RCSfile$
* $Author$
* $Date$
* $Revision$
*
* Copyright (C) 2002-2007 The Chemistry Development Kit (CDK) project
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.interfaces;
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.tools.diff.AtomDiff;
/**
* Checks the functionality of {@link IAtom} implementations.
*
* @cdk.module test-interfaces
*/
public abstract class AbstractAtomTest extends AbstractAtomTypeTest {
/**
* Method to test the get/setCharge() methods.
*/
@Test public void testSetCharge_Double() {
double charge = 0.15;
IAtom a = (IAtom)newChemObject();
a.setCharge(charge);
Assert.assertEquals(charge, a.getCharge(), 0.001);
}
@Test public void testGetCharge() {
testSetCharge_Double();
}
/**
* Method to test the get/setHydrogenCount() methods.
*/
@Test public void testSetImplicitHydrogenCount_Integer() {
Integer count = 1;
IAtom a = (IAtom)newChemObject();
a.setImplicitHydrogenCount(count);
Assert.assertEquals(count, a.getImplicitHydrogenCount());
}
@Test public void testGetImplicitHydrogenCount() {
// should be null by default
IAtom a = (IAtom)newChemObject();
Assert.assertNull(a.getImplicitHydrogenCount());
}
/**
* Method to test the setFractional3D() methods.
*/
@Test public void testSetFractionalPoint3d_Point3d() {
IAtom a = (IAtom)newChemObject();
a.setFractionalPoint3d(new Point3d(0.5, 0.5, 0.5));
Point3d fract = a.getFractionalPoint3d();
Assert.assertNotNull(fract);
Assert.assertEquals(0.5, fract.x, 0.001);
Assert.assertEquals(0.5, fract.y, 0.001);
Assert.assertEquals(0.5, fract.z, 0.001);
}
@Test public void testGetFractionalPoint3d() {
testSetFractionalPoint3d_Point3d();
}
@Test public void testGetPoint3d() {
Point3d point3d = new Point3d(1.0, 2.0, 3.0);
IAtom a = (IAtom)newChemObject();
a.setPoint3d(point3d);
Assert.assertNotNull(a.getPoint3d());
assertEquals(point3d, a.getPoint3d(), 0.001);
}
@Test public void testSetPoint3d_Point3d() {
Point3d point3d = new Point3d(1.0, 2.0, 3.0);
IAtom a = (IAtom)newChemObject();
a.setPoint3d(point3d);
Assert.assertEquals(point3d, a.getPoint3d());
}
@Test public void testGetPoint2d() {
Point2d point2d = new Point2d(1.0, 2.0);
IAtom a = (IAtom)newChemObject();
a.setPoint2d(point2d);
Assert.assertNotNull(a.getPoint2d());
Assert.assertEquals(point2d.x, a.getPoint2d().x, 0.001);
Assert.assertEquals(point2d.y, a.getPoint2d().y, 0.001);
}
@Test public void testSetPoint2d_Point2d() {
Point2d point2d = new Point2d(1.0, 2.0);
IAtom a = (IAtom)newChemObject();
a.setPoint2d(point2d);
Assert.assertEquals(point2d, a.getPoint2d());
}
/**
* Method to test the get/setHydrogenCount() methods.
*/
@Test public void testSetStereoParity_Integer() {
int parity = CDKConstants.STEREO_ATOM_PARITY_PLUS;
IAtom a = (IAtom)newChemObject();
a.setStereoParity(parity);
Assert.assertEquals(parity, a.getStereoParity().intValue());
}
@Test public void testGetStereoParity() {
testSetStereoParity_Integer();
}
/**
* Method to test the clone() method
*/
@Test public void testClone() throws Exception {
IAtom atom = (IAtom)newChemObject();
Object clone = atom.clone();
Assert.assertTrue(clone instanceof IAtom);
// test that everything has been cloned properly
String diff = AtomDiff.diff(atom, (IAtom)clone);
Assert.assertNotNull(diff);
Assert.assertEquals(0, diff.length());
}
/**
* Method to test the clone() method
*/
@Test public void testClone_Point2d() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setPoint2d(new Point2d(2, 3));
IAtom clone = (IAtom)atom.clone();
Assert.assertEquals(clone.getPoint2d().x, 2.0, 0.001);
}
/**
* Method to test the clone() method
*/
@Test public void testClone_Point3d() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setPoint3d(new Point3d(2, 3, 4));
IAtom clone = (IAtom)atom.clone();
Assert.assertEquals(clone.getPoint3d().x, 2.0, 0.001);
}
/**
* Method to test the clone() method
*/
@Test public void testClone_FractionalPoint3d() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setFractionalPoint3d(new Point3d(2, 3, 4));
IAtom clone = (IAtom)atom.clone();
Assert.assertEquals(clone.getFractionalPoint3d().x, 2.0, 0.001);
}
/**
* Method to test the clone() method
*/
@Test public void testClone_HydrogenCount() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setImplicitHydrogenCount(Integer.valueOf(3));
IAtom clone = (IAtom)atom.clone();
// test cloning
atom.setImplicitHydrogenCount(Integer.valueOf(4));
Assert.assertEquals(3, clone.getImplicitHydrogenCount().intValue());
}
/**
* Method to test the clone() method
*/
@Test public void testClone_StereoParity() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setStereoParity(3);
IAtom clone = (IAtom)atom.clone();
// test cloning
atom.setStereoParity(4);
Assert.assertEquals(3, clone.getStereoParity().intValue());
}
/**
* Method to test the clone() method
*/
@Test public void testClone_Charge() throws Exception {
IAtom atom = (IAtom)newChemObject();
atom.setCharge(1.0);
IAtom clone = (IAtom)atom.clone();
// test cloning
atom.setCharge(5.0);
Assert.assertEquals(1.0, clone.getCharge(), 0.001);
}
/**
* Method to test whether the class complies with RFC #9.
*/
@Test public void testToString() {
IAtom atom = (IAtom)newChemObject();
String description = atom.toString();
for (int i=0; i< description.length(); i++) {
Assert.assertTrue('\n' != description.charAt(i));
Assert.assertTrue('\r' != description.charAt(i));
}
}
/**
* Checks that the default charge is set to NaN
*/
@Test public void testDefaultChargeValue() {
IAtom atom = (IAtom)newChemObject();
Assert.assertEquals(CDKConstants.UNSET, atom.getCharge());
// Assert.assertEquals(0.0, atom.getCharge(), 0.00000001);
}
}