source: src/unittests/listofbondsunittest.cpp@ a1510d

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 a1510d was a1510d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

  • Property mode set to 100644
File size: 6.7 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/** Unit Test of molecule::AddBond()
93 *
94 */
95void ListOfBondsTest::AddingBondTest()
96{
97 bond *Binder = NULL;
98 atom *atom1 = TestMolecule->start->next;
99 atom *atom2 = atom1->next;
100 CPPUNIT_ASSERT( atom1 != NULL );
101 CPPUNIT_ASSERT( atom2 != NULL );
102
103 // add bond
104 Binder = TestMolecule->AddBond(atom1, atom2, 1);
105 CPPUNIT_ASSERT( Binder != NULL );
106 bond *TestBond = TestMolecule->first->next;
107 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
108
109 // check that bond contains the two atoms
110 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
111 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
112
113 // check that bond is present in both atoms
114 bond *TestBond1 = *(atom1->ListOfBonds.begin());
115 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
116 bond *TestBond2 = *(atom2->ListOfBonds.begin());
117 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
118};
119
120/** Unit Test of molecule::RemoveBond()
121 *
122 */
123void ListOfBondsTest::RemovingBondTest()
124{
125 bond *Binder = NULL;
126 atom *atom1 = TestMolecule->start->next;
127 atom *atom2 = atom1->next;
128 CPPUNIT_ASSERT( atom1 != NULL );
129 CPPUNIT_ASSERT( atom2 != NULL );
130
131 // add bond
132 Binder = TestMolecule->AddBond(atom1, atom2, 1);
133 CPPUNIT_ASSERT( Binder != NULL );
134
135 // remove bond
136 TestMolecule->RemoveBond(Binder);
137
138 // check if removed from atoms
139 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
140 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
141
142 // check if removed from molecule
143 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
144};
145
146/** Unit Test of molecule::RemoveBonds()
147 *
148 */
149void ListOfBondsTest::RemovingBondsTest()
150{
151 bond *Binder = NULL;
152 atom *atom1 = TestMolecule->start->next;
153 atom *atom2 = atom1->next;
154 atom *atom3 = atom2->next;
155 CPPUNIT_ASSERT( atom1 != NULL );
156 CPPUNIT_ASSERT( atom2 != NULL );
157 CPPUNIT_ASSERT( atom3 != NULL );
158
159 // add bond
160 Binder = TestMolecule->AddBond(atom1, atom2, 1);
161 CPPUNIT_ASSERT( Binder != NULL );
162 Binder = TestMolecule->AddBond(atom1, atom3, 1);
163 CPPUNIT_ASSERT( Binder != NULL );
164 Binder = TestMolecule->AddBond(atom2, atom3, 1);
165 CPPUNIT_ASSERT( Binder != NULL );
166
167 // check that all are present
168 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
169 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
170 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
171
172 // remove bond
173 TestMolecule->RemoveBonds(atom1);
174
175 // check if removed from atoms
176 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
177 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
178 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
179
180 // check if removed from molecule
181 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
182 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
183};
184
185/** Unit Test of delete(bond *)
186 *
187 */
188void ListOfBondsTest::DeleteBondTest()
189{
190 bond *Binder = NULL;
191 atom *atom1 = TestMolecule->start->next;
192 atom *atom2 = atom1->next;
193 CPPUNIT_ASSERT( atom1 != NULL );
194 CPPUNIT_ASSERT( atom2 != NULL );
195
196 // add bond
197 Binder = TestMolecule->AddBond(atom1, atom2, 1);
198 CPPUNIT_ASSERT( Binder != NULL );
199
200 // remove bond
201 delete(Binder);
202
203 // check if removed from atoms
204 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
205 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
206
207 // check if removed from molecule
208 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
209};
210
211/** Unit Test of molecule::RemoveAtom()
212 *
213 */
214void ListOfBondsTest::RemoveAtomTest()
215{
216 bond *Binder = NULL;
217 atom *atom1 = TestMolecule->start->next;
218 atom *atom2 = atom1->next;
219 CPPUNIT_ASSERT( atom1 != NULL );
220 CPPUNIT_ASSERT( atom2 != NULL );
221
222 // add bond
223 Binder = TestMolecule->AddBond(atom1, atom2, 1);
224 CPPUNIT_ASSERT( Binder != NULL );
225
226 // remove atom2
227 TestMolecule->RemoveAtom(atom2);
228
229 // check bond if removed from other atom
230 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
231
232 // check if removed from molecule
233 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
234};
235
236/** Unit Test of delete(atom *)
237 *
238 */
239void ListOfBondsTest::DeleteAtomTest()
240{
241 bond *Binder = NULL;
242 atom *atom1 = TestMolecule->start->next;
243 atom *atom2 = atom1->next;
244 CPPUNIT_ASSERT( atom1 != NULL );
245 CPPUNIT_ASSERT( atom2 != NULL );
246
247 // add bond
248 Binder = TestMolecule->AddBond(atom1, atom2, 1);
249 CPPUNIT_ASSERT( Binder != NULL );
250
251 // remove atom2
252 World::get()->destroyAtom(atom2);
253
254 // check bond if removed from other atom
255 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
256
257 // check if removed from molecule
258 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
259};
Note: See TracBrowser for help on using the repository browser.