source: src/unittests/listofbondsunittest.cpp@ 42af9e

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 Candidate_v1.7.0 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 42af9e was 920c70, checked in by Frederik Heber <heber@…>, 15 years ago

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 6.9 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 // construct element
41 hydrogen = World::getInstance().getPeriode()->FindElement(1);
42 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
43
44 // construct molecule (tetraeder of hydrogens)
45 TestMolecule = World::getInstance().createMolecule();
46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
47 Walker = World::getInstance().createAtom();
48 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
49 Walker->type = hydrogen;
50 *Walker->node = Vector(1., 0., 1. );
51 TestMolecule->AddAtom(Walker);
52 Walker = World::getInstance().createAtom();
53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
54 Walker->type = hydrogen;
55 *Walker->node = Vector(0., 1., 1. );
56 TestMolecule->AddAtom(Walker);
57 Walker = World::getInstance().createAtom();
58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
59 Walker->type = hydrogen;
60 *Walker->node = Vector(1., 1., 0. );
61 TestMolecule->AddAtom(Walker);
62 Walker = World::getInstance().createAtom();
63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
64 Walker->type = hydrogen;
65 *Walker->node = Vector(0., 0., 0. );
66 TestMolecule->AddAtom(Walker);
67
68 // check that TestMolecule was correctly constructed
69 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
70};
71
72
73void ListOfBondsTest::tearDown()
74{
75 // remove
76 World::getInstance().destroyMolecule(TestMolecule);
77 // note that all the atoms, molecules, the tafel and the elements
78 // are all cleaned when the world is destroyed
79 World::purgeInstance();
80 logger::purgeInstance();
81};
82
83/** Unit Test of molecule::AddBond()
84 *
85 */
86void ListOfBondsTest::AddingBondTest()
87{
88 bond *Binder = NULL;
89 atom *atom1 = TestMolecule->start->next;
90 atom *atom2 = atom1->next;
91 CPPUNIT_ASSERT( atom1 != NULL );
92 CPPUNIT_ASSERT( atom2 != NULL );
93
94 // add bond
95 Binder = TestMolecule->AddBond(atom1, atom2, 1);
96 CPPUNIT_ASSERT( Binder != NULL );
97 bond *TestBond = TestMolecule->first->next;
98 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
99
100 // check that bond contains the two atoms
101 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
102 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
103
104 // check that bond is present in both atoms
105 bond *TestBond1 = *(atom1->ListOfBonds.begin());
106 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
107 bond *TestBond2 = *(atom2->ListOfBonds.begin());
108 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
109};
110
111/** Unit Test of molecule::RemoveBond()
112 *
113 */
114void ListOfBondsTest::RemovingBondTest()
115{
116 bond *Binder = NULL;
117 atom *atom1 = TestMolecule->start->next;
118 atom *atom2 = atom1->next;
119 CPPUNIT_ASSERT( atom1 != NULL );
120 CPPUNIT_ASSERT( atom2 != NULL );
121
122 // add bond
123 Binder = TestMolecule->AddBond(atom1, atom2, 1);
124 CPPUNIT_ASSERT( Binder != NULL );
125
126 // remove bond
127 TestMolecule->RemoveBond(Binder);
128
129 // check if removed from atoms
130 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
131 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
132
133 // check if removed from molecule
134 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
135};
136
137/** Unit Test of molecule::RemoveBonds()
138 *
139 */
140void ListOfBondsTest::RemovingBondsTest()
141{
142 bond *Binder = NULL;
143 atom *atom1 = TestMolecule->start->next;
144 atom *atom2 = atom1->next;
145 atom *atom3 = atom2->next;
146 CPPUNIT_ASSERT( atom1 != NULL );
147 CPPUNIT_ASSERT( atom2 != NULL );
148 CPPUNIT_ASSERT( atom3 != NULL );
149
150 // add bond
151 Binder = TestMolecule->AddBond(atom1, atom2, 1);
152 CPPUNIT_ASSERT( Binder != NULL );
153 Binder = TestMolecule->AddBond(atom1, atom3, 1);
154 CPPUNIT_ASSERT( Binder != NULL );
155 Binder = TestMolecule->AddBond(atom2, atom3, 1);
156 CPPUNIT_ASSERT( Binder != NULL );
157
158 // check that all are present
159 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
160 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
161 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
162
163 // remove bond
164 TestMolecule->RemoveBonds(atom1);
165
166 // check if removed from atoms
167 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
168 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
169 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
170
171 // check if removed from molecule
172 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
173 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
174};
175
176/** Unit Test of delete(bond *)
177 *
178 */
179void ListOfBondsTest::DeleteBondTest()
180{
181 bond *Binder = NULL;
182 atom *atom1 = TestMolecule->start->next;
183 atom *atom2 = atom1->next;
184 CPPUNIT_ASSERT( atom1 != NULL );
185 CPPUNIT_ASSERT( atom2 != NULL );
186
187 // add bond
188 Binder = TestMolecule->AddBond(atom1, atom2, 1);
189 CPPUNIT_ASSERT( Binder != NULL );
190
191 // remove bond
192 delete(Binder);
193
194 // check if removed from atoms
195 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
196 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
197
198 // check if removed from molecule
199 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
200};
201
202/** Unit Test of molecule::RemoveAtom()
203 *
204 */
205void ListOfBondsTest::RemoveAtomTest()
206{
207 bond *Binder = NULL;
208 atom *atom1 = TestMolecule->start->next;
209 atom *atom2 = atom1->next;
210 CPPUNIT_ASSERT( atom1 != NULL );
211 CPPUNIT_ASSERT( atom2 != NULL );
212
213 // add bond
214 Binder = TestMolecule->AddBond(atom1, atom2, 1);
215 CPPUNIT_ASSERT( Binder != NULL );
216
217 // remove atom2
218 TestMolecule->RemoveAtom(atom2);
219
220 // check bond if removed from other atom
221 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
222
223 // check if removed from molecule
224 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
225};
226
227/** Unit Test of delete(atom *)
228 *
229 */
230void ListOfBondsTest::DeleteAtomTest()
231{
232 bond *Binder = NULL;
233 atom *atom1 = TestMolecule->start->next;
234 atom *atom2 = atom1->next;
235 CPPUNIT_ASSERT( atom1 != NULL );
236 CPPUNIT_ASSERT( atom2 != NULL );
237
238 // add bond
239 Binder = TestMolecule->AddBond(atom1, atom2, 1);
240 CPPUNIT_ASSERT( Binder != NULL );
241
242 // remove atom2
243 World::getInstance().destroyAtom(atom2);
244
245 // check bond if removed from other atom
246 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
247
248 // check if removed from molecule
249 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
250};
Note: See TracBrowser for help on using the repository browser.