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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
// Copyright 2008 Nanorex, Inc. See LICENSE file for details.
#include "NXEntityManagerTest.h"
CPPUNIT_TEST_SUITE_REGISTRATION(NXEntityManagerTest);
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NXEntityManagerTest,
"NXEntityManagerTestSuite");
/* FUNCTION: setUp */
void NXEntityManagerTest::setUp() {
entityManager = new NXEntityManager();
}
/* FUNCTION: tearDown */
void NXEntityManagerTest::tearDown() {
delete entityManager;
}
/* FUNCTION: moleculeSetTraversalTest
*
* Tests the creation and (depth-first) traversal of the following molecule set
* tree:
*
* root
* |-- child iter1
* |-- child iter1
* |-- child iter2
* |-- child iter2
*/
void NXEntityManagerTest::moleculeSetTraversalTest() {
// Get the root molecule set
int frameSetId = entityManager->addFrameSet();
int frameIndex = entityManager->addFrame(frameSetId);
NXMoleculeSet* rootMoleculeSet =
entityManager->getRootMoleculeSet(frameSetId, frameIndex);
CPPUNIT_ASSERT(rootMoleculeSet != 0);
CPPUNIT_ASSERT(rootMoleculeSet->childCount() == 0);
// Add children to the root molecule set
//
rootMoleculeSet->addChild(new NXMoleculeSet());
CPPUNIT_ASSERT(rootMoleculeSet->childCount() == 1);
NXMoleculeSet* child = new NXMoleculeSet();
rootMoleculeSet->addChild(child);
child->addChild(new NXMoleculeSet());
child->addChild(new NXMoleculeSet());
CPPUNIT_ASSERT(child->childCount() == 2);
// Iterate over the children
NXMoleculeSetIterator iter1 = rootMoleculeSet->childrenBegin();
CPPUNIT_ASSERT(iter1 != rootMoleculeSet->childrenEnd());
iter1++;
CPPUNIT_ASSERT(iter1 != rootMoleculeSet->childrenEnd());
NXMoleculeSetIterator iter2 = (*iter1)->childrenBegin();
CPPUNIT_ASSERT(iter2 != (*iter1)->childrenEnd());
iter2++;
CPPUNIT_ASSERT(iter2 != (*iter1)->childrenEnd());
iter2++;
CPPUNIT_ASSERT(iter2 == (*iter1)->childrenEnd());
iter1++;
CPPUNIT_ASSERT(iter1 == rootMoleculeSet->childrenEnd());
}
/* FUNCTION: moleculeTraversalTest
*
* Tests the creation and (depth-first) traversal of the molecules in the
* following molecule set tree:
*
* root (2 molecules)
* |-- child
* |-- childMoleculeSet1 (2 molecules)
* |-- childMoleculeSet2 (2 molecules)
* |-- child
*/
void NXEntityManagerTest::moleculeTraversalTest() {
// Create a tree of molecules in molecule sets
//
int frameSetId = entityManager->addFrameSet();
int frameIndex = entityManager->addFrame(frameSetId);
NXMoleculeSet* rootMoleculeSet =
entityManager->getRootMoleculeSet(frameSetId, frameIndex);
OBMol* molecule = rootMoleculeSet->newMolecule();
CPPUNIT_ASSERT(((NXMoleculeData*)
(molecule->GetData(NXMoleculeDataType)))->GetIdx() == 0);
rootMoleculeSet->newMolecule();
rootMoleculeSet->addChild(new NXMoleculeSet());
NXMoleculeSet* childMoleculeSet1 = new NXMoleculeSet();
rootMoleculeSet->addChild(childMoleculeSet1);
molecule = childMoleculeSet1->newMolecule();
CPPUNIT_ASSERT(((NXMoleculeData*)
(molecule->GetData(NXMoleculeDataType)))->GetIdx() == 2);
childMoleculeSet1->newMolecule();
NXMoleculeSet* childMoleculeSet2 = new NXMoleculeSet();
childMoleculeSet1->addChild(childMoleculeSet2);
molecule = childMoleculeSet2->newMolecule();
CPPUNIT_ASSERT(((NXMoleculeData*)
(molecule->GetData(NXMoleculeDataType)))->GetIdx() == 4);
childMoleculeSet2->newMolecule();
childMoleculeSet1->addChild(new NXMoleculeSet());
// Traverse all the molecules starting at the root molecule set
//
// root
OBMolIterator iter1 = rootMoleculeSet->moleculesBegin();
CPPUNIT_ASSERT(iter1 != rootMoleculeSet->moleculesEnd());
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 0);
iter1++;
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 1);
iter1++;
CPPUNIT_ASSERT(iter1 == rootMoleculeSet->moleculesEnd());
NXMoleculeSetIterator moleculeSetIter1 = rootMoleculeSet->childrenBegin();
iter1 = (*moleculeSetIter1)->moleculesBegin();
CPPUNIT_ASSERT(iter1 == (*moleculeSetIter1)->moleculesEnd());
// childMoleculeSet1
moleculeSetIter1++;
iter1 = (*moleculeSetIter1)->moleculesBegin();
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 2);
iter1++;
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 3);
iter1++;
CPPUNIT_ASSERT(iter1 == (*moleculeSetIter1)->moleculesEnd());
// childMoleculeSet2
NXMoleculeSetIterator moleculeSetIter2 =
(*moleculeSetIter1)->childrenBegin();
iter1 = (*moleculeSetIter2)->moleculesBegin();
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 4);
iter1++;
CPPUNIT_ASSERT(((NXMoleculeData*)
((*iter1)->GetData(NXMoleculeDataType)))->GetIdx() == 5);
iter1++;
CPPUNIT_ASSERT(iter1 == (*moleculeSetIter2)->moleculesEnd());
moleculeSetIter2++;
iter1 = (*moleculeSetIter2)->moleculesBegin();
CPPUNIT_ASSERT(iter1 == (*moleculeSetIter2)->moleculesEnd());
}
/* FUNCTION: atomTraversalTest1
*
* This tests traversal over all atoms in a molecule set for the
* following molecule set tree:
*
* root (2 molecules, 2 atoms each)
* |-- child
* |-- childMoleculeSet1 (2 molecules, 2 atoms each)
* |-- childMoleculeSet2 (2 molecules, 2 atoms each)
* |-- child
void NXEntityManagerTest::atomTraversalTest1() {
// Create a tree of molecules with atoms in molecule sets
//
int frameSetId = entityManager->addFrameSet();
int frameIndex = entityManager->addFrame(frameSetId);
NXMoleculeSet* rootMoleculeSet =
entityManager->getRootMoleculeSet(frameSetId, frameIndex);
NXMolecule* molecule = rootMoleculeSet->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
molecule = rootMoleculeSet->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
rootMoleculeSet->addChild(new NXMoleculeSet());
NXMoleculeSet* childMoleculeSet1 = new NXMoleculeSet();
rootMoleculeSet->addChild(childMoleculeSet1);
molecule = childMoleculeSet1->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
molecule = childMoleculeSet1->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
NXMoleculeSet* childMoleculeSet2 = new NXMoleculeSet();
childMoleculeSet1->addChild(childMoleculeSet2);
molecule = childMoleculeSet2->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
molecule = childMoleculeSet2->newMolecule();
molecule->NewAtom();
molecule->NewAtom();
childMoleculeSet1->addChild(new NXMoleculeSet());
// Traverse all the atoms starting from the root molecule set
std::string summary = atomTraversalTest1Helper(rootMoleculeSet);
CPPUNIT_ASSERT(summary == "0.1.2.3.4.5.6.7.8.9.10.11.");
}
*/
/* FUNCTION: atomTraversalTest1Helper
std::string NXEntityManagerTest::atomTraversalTest1Helper
(NXMoleculeSet* moleculeSet) {
std::string summary("");
// Traverse atoms
NXAtomIterator atomIter = moleculeSet->BeginAtoms();
while (atomIter != moleculeSet->EndAtoms()) {
char buffer[5];
sprintf(buffer, "%d.", (*atomIter)->GetIdx());
summary.append(buffer);
atomIter++;
}
// Traverse the molecule set's children
NXMoleculeSetIterator moleculeSetIter = moleculeSet->childrenBegin();
while (moleculeSetIter != moleculeSet->childrenEnd()) {
summary.append(atomTraversalTest1Helper(*moleculeSetIter));
moleculeSetIter++;
}
return summary;
}
*/
/* FUNCTION: atomTraversalTest2
*
* This tests traversal over all atoms in a molecule.
*/
void NXEntityManagerTest::atomTraversalTest2() {
// Create a molecule with atoms
//
int frameSetId = entityManager->addFrameSet();
int frameIndex = entityManager->addFrame(frameSetId);
NXMoleculeSet* rootMoleculeSet =
entityManager->getRootMoleculeSet(frameSetId, frameIndex);
OBMol* molecule = rootMoleculeSet->newMolecule();
OBAtom* atom = molecule->NewAtom();
atom = molecule->NewAtom();
// Traverse the molecule's atoms
OBAtomIterator iter = molecule->BeginAtoms();
CPPUNIT_ASSERT((*iter)->GetIdx() == 1);
iter++;
CPPUNIT_ASSERT((*iter)->GetIdx() == 2);
iter++;
/*
while (iter != molecule->EndAtoms()) {
printf("#%d ", (*iter));
iter++;
}
*/
CPPUNIT_ASSERT(*iter == 0);
}
|