source: src/unittests/listofbondsunittest.cpp@ 9879f6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 9879f6 was 9879f6, checked in by Frederik Heber <heber@…>, 15 years ago

Huge Refactoring due to class molecule now being an STL container.

  • molecule::start and molecule::end were dropped. Hence, the usual construct Walker = start while (Walker->next != end) {

Walker = walker->next
...

}
was changed to
for (molecule::iterator iter = begin(); iter != end(); ++iter) {

...

}
and (*iter) used instead of Walker.

  • Two build errors remain (beside some more in folder Actions, Patterns and unittest) in molecule_pointcloud.cpp and molecule.cpp
  • lists.cpp was deleted as specialization of atom* was not needed anymore
  • link, unlink, add, remove, removewithoutcheck all are not needed for atoms anymore, just for bonds (where first, last entries remain in molecule)
  • CreateFatherLookupTable() was put back into class molecule.
  • molecule::InternalPointer is now an iterator
  • class PointCloud: GoToPrevious() and GetTerminalPoint() were dropped as not needed.
  • some new STL functions in class molecule: size(), empty(), erase(), find() and insert()
  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * listofbondsunittest.cpp
3 *
4 * Created on: 18 Oct 2009
5 * Author: user
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <cstring>
15
16#include "listofbondsunittest.hpp"
17
18#include "World.hpp"
19#include "atom.hpp"
20#include "bond.hpp"
21#include "element.hpp"
22#include "molecule.hpp"
23#include "periodentafel.hpp"
24#include "World.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
34
35
36void ListOfBondsTest::setUp()
37{
38 atom *Walker = NULL;
39
40 // init private all pointers to zero
41 TestMolecule = NULL;
42 hydrogen = NULL;
43 tafel = NULL;
44
45 // construct element
46 hydrogen = new element;
47 hydrogen->Z = 1;
48 strcpy(hydrogen->name, "hydrogen");
49 strcpy(hydrogen->symbol, "H");
50
51
52 // construct periodentafel
53 tafel = World::get()->getPeriode();
54 tafel->AddElement(hydrogen);
55
56 // construct molecule (tetraeder of hydrogens)
57 TestMolecule = World::get()->createMolecule();
58 Walker = World::get()->createAtom();
59 Walker->type = hydrogen;
60 Walker->node->Init(1., 0., 1. );
61 TestMolecule->AddAtom(Walker);
62 Walker = World::get()->createAtom();
63 Walker->type = hydrogen;
64 Walker->node->Init(0., 1., 1. );
65 TestMolecule->AddAtom(Walker);
66 Walker = World::get()->createAtom();
67 Walker->type = hydrogen;
68 Walker->node->Init(1., 1., 0. );
69 TestMolecule->AddAtom(Walker);
70 Walker = World::get()->createAtom();
71 Walker->type = hydrogen;
72 Walker->node->Init(0., 0., 0. );
73 TestMolecule->AddAtom(Walker);
74
75 // check that TestMolecule was correctly constructed
76 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
77
78};
79
80
81void ListOfBondsTest::tearDown()
82{
83 // remove
84 World::get()->destroyMolecule(TestMolecule);
85 // note that all the atoms, molecules, the tafel and the elements
86 // are all cleaned when the world is destroyed
87 World::destroy();
88 MemoryUsageObserver::purgeInstance();
89 logger::purgeInstance();
90};
91
92/** Tests whether setup worked correctly.
93 *
94 */
95void ListOfBondsTest::SetupTest()
96{
97 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
98 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
99};
100
101/** Unit Test of molecule::AddBond()
102 *
103 */
104void ListOfBondsTest::AddingBondTest()
105{
106 bond *Binder = NULL;
107 molecule::iterator iter = TestMolecule->begin();
108 atom *atom1 = *iter;
109 iter++;
110 atom *atom2 = *iter;
111 CPPUNIT_ASSERT( atom1 != NULL );
112 CPPUNIT_ASSERT( atom2 != NULL );
113
114 // add bond
115 Binder = TestMolecule->AddBond(atom1, atom2, 1);
116 CPPUNIT_ASSERT( Binder != NULL );
117 bond *TestBond = TestMolecule->first->next;
118 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
119
120 // check that bond contains the two atoms
121 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
122 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
123
124 // check that bond is present in both atoms
125 bond *TestBond1 = *(atom1->ListOfBonds.begin());
126 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
127 bond *TestBond2 = *(atom2->ListOfBonds.begin());
128 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
129};
130
131/** Unit Test of molecule::RemoveBond()
132 *
133 */
134void ListOfBondsTest::RemovingBondTest()
135{
136 bond *Binder = NULL;
137 molecule::iterator iter = TestMolecule->begin();
138 atom *atom1 = *iter;
139 iter++;
140 atom *atom2 = *iter;
141 CPPUNIT_ASSERT( atom1 != NULL );
142 CPPUNIT_ASSERT( atom2 != NULL );
143
144 // add bond
145 Binder = TestMolecule->AddBond(atom1, atom2, 1);
146 CPPUNIT_ASSERT( Binder != NULL );
147
148 // remove bond
149 TestMolecule->RemoveBond(Binder);
150
151 // check if removed from atoms
152 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
153 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
154
155 // check if removed from molecule
156 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
157};
158
159/** Unit Test of molecule::RemoveBonds()
160 *
161 */
162void ListOfBondsTest::RemovingBondsTest()
163{
164 bond *Binder = NULL;
165 molecule::iterator iter = TestMolecule->begin();
166 atom *atom1 = *iter;
167 iter++;
168 atom *atom2 = *iter;
169 iter++;
170 atom *atom3 = *iter;
171 CPPUNIT_ASSERT( atom1 != NULL );
172 CPPUNIT_ASSERT( atom2 != NULL );
173 CPPUNIT_ASSERT( atom3 != NULL );
174
175 // add bond
176 Binder = TestMolecule->AddBond(atom1, atom2, 1);
177 CPPUNIT_ASSERT( Binder != NULL );
178 Binder = TestMolecule->AddBond(atom1, atom3, 1);
179 CPPUNIT_ASSERT( Binder != NULL );
180 Binder = TestMolecule->AddBond(atom2, atom3, 1);
181 CPPUNIT_ASSERT( Binder != NULL );
182
183 // check that all are present
184 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
185 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
186 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
187
188 // remove bond
189 TestMolecule->RemoveBonds(atom1);
190
191 // check if removed from atoms
192 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
193 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
194 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
195
196 // check if removed from molecule
197 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
198 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
199};
200
201/** Unit Test of delete(bond *)
202 *
203 */
204void ListOfBondsTest::DeleteBondTest()
205{
206 bond *Binder = NULL;
207 molecule::iterator iter = TestMolecule->begin();
208 atom *atom1 = *iter;
209 iter++;
210 atom *atom2 = *iter;
211 CPPUNIT_ASSERT( atom1 != NULL );
212 CPPUNIT_ASSERT( atom2 != NULL );
213
214 // add bond
215 Binder = TestMolecule->AddBond(atom1, atom2, 1);
216 CPPUNIT_ASSERT( Binder != NULL );
217
218 // remove bond
219 delete(Binder);
220
221 // check if removed from atoms
222 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
223 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
224
225 // check if removed from molecule
226 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
227};
228
229/** Unit Test of molecule::RemoveAtom()
230 *
231 */
232void ListOfBondsTest::RemoveAtomTest()
233{
234 bond *Binder = NULL;
235 molecule::iterator iter = TestMolecule->begin();
236 atom *atom1 = *iter;
237 iter++;
238 atom *atom2 = *iter;
239 CPPUNIT_ASSERT( atom1 != NULL );
240 CPPUNIT_ASSERT( atom2 != NULL );
241
242 // add bond
243 Binder = TestMolecule->AddBond(atom1, atom2, 1);
244 CPPUNIT_ASSERT( Binder != NULL );
245
246 // remove atom2
247 TestMolecule->RemoveAtom(atom2);
248
249 // check bond if removed from other atom
250 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
251
252 // check if removed from molecule
253 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
254};
255
256/** Unit Test of delete(atom *)
257 *
258 */
259void ListOfBondsTest::DeleteAtomTest()
260{
261 bond *Binder = NULL;
262 molecule::iterator iter = TestMolecule->begin();
263 atom *atom1 = *iter;
264 iter++;
265 atom *atom2 = *iter;
266 CPPUNIT_ASSERT( atom1 != NULL );
267 CPPUNIT_ASSERT( atom2 != NULL );
268
269 // add bond
270 Binder = TestMolecule->AddBond(atom1, atom2, 1);
271 CPPUNIT_ASSERT( Binder != NULL );
272
273 // remove atom2
274 World::get()->destroyAtom(atom2);
275
276 // check bond if removed from other atom
277 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
278
279 // check if removed from molecule
280 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
281};
Note: See TracBrowser for help on using the repository browser.