source: src/unittests/ListOfBondsUnitTest.cpp@ d557374

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 d557374 was 9d83b6, checked in by Frederik Heber <heber@…>, 14 years ago

BondedParticleInfo now has vector<BondList>

  • vector<BondList> ListOfBonds is private, getter for (non-)const access.
  • Access everywhere to ListOfBonds replaced by respective getter.
  • Access is as of now always to time step zero.
  • greatest impact is on molecule... files, and ListOfBondsUnitTest.
  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ListOfBondsUnitTest.cpp
10 *
11 * Created on: 18 Oct 2009
12 * Author: user
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <cstring>
27
28
29#include "World.hpp"
30#include "atom.hpp"
31#include "bond.hpp"
32#include "element.hpp"
33#include "molecule.hpp"
34#include "periodentafel.hpp"
35#include "World.hpp"
36
37#include "ListOfBondsUnitTest.hpp"
38
39#ifdef HAVE_TESTRUNNER
40#include "UnitTestMain.hpp"
41#endif /*HAVE_TESTRUNNER*/
42
43/********************************************** Test classes **************************************/
44
45// Registers the fixture into the 'registry'
46CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
47
48
49void ListOfBondsTest::setUp()
50{
51 atom *Walker = NULL;
52
53 // construct element
54 hydrogen = World::getInstance().getPeriode()->FindElement(1);
55 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
56
57 // construct molecule (tetraeder of hydrogens)
58 TestMolecule = World::getInstance().createMolecule();
59 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
60 Walker = World::getInstance().createAtom();
61 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
62 Walker->setType(hydrogen);
63 Walker->setPosition(Vector(1., 0., 1. ));
64 TestMolecule->AddAtom(Walker);
65 Walker = World::getInstance().createAtom();
66 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
67 Walker->setType(hydrogen);
68 Walker->setPosition(Vector(0., 1., 1. ));
69 TestMolecule->AddAtom(Walker);
70 Walker = World::getInstance().createAtom();
71 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
72 Walker->setType(hydrogen);
73 Walker->setPosition(Vector(1., 1., 0. ));
74 TestMolecule->AddAtom(Walker);
75 Walker = World::getInstance().createAtom();
76 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
77 Walker->setType(hydrogen);
78 Walker->setPosition(Vector(0., 0., 0. ));
79 TestMolecule->AddAtom(Walker);
80
81 // check that TestMolecule was correctly constructed
82 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
83};
84
85
86void ListOfBondsTest::tearDown()
87{
88 // remove
89 World::getInstance().destroyMolecule(TestMolecule);
90 // note that all the atoms, molecules, the tafel and the elements
91 // are all cleaned when the world is destroyed
92 World::purgeInstance();
93 logger::purgeInstance();
94};
95
96/** Tests whether setup worked correctly.
97 *
98 */
99void ListOfBondsTest::SetupTest()
100{
101 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
102 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
103};
104
105/** Unit Test of molecule::AddBond()
106 *
107 */
108void ListOfBondsTest::AddingBondTest()
109{
110 bond *Binder = NULL;
111 molecule::iterator iter = TestMolecule->begin();
112 atom *atom1 = *iter;
113 iter++;
114 atom *atom2 = *iter;
115 CPPUNIT_ASSERT( atom1 != NULL );
116 CPPUNIT_ASSERT( atom2 != NULL );
117
118 // add bond
119 Binder = TestMolecule->AddBond(atom1, atom2, 1);
120 CPPUNIT_ASSERT( Binder != NULL );
121 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
122
123 // check that bond contains the two atoms
124 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
125 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
126
127 // check that bond is present in both atoms
128 BondList::const_iterator bonditer;
129 bonditer = atom1->getListOfBonds().begin();
130 bond *TestBond1 = *bonditer;
131 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
132 bonditer = atom2->getListOfBonds().begin();
133 bond *TestBond2 = *bonditer;
134 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
135};
136
137/** Unit Test of molecule::RemoveBond()
138 *
139 */
140void ListOfBondsTest::RemovingBondTest()
141{
142 bond *Binder = NULL;
143 molecule::iterator iter = TestMolecule->begin();
144 atom *atom1 = *iter;
145 iter++;
146 atom *atom2 = *iter;
147 CPPUNIT_ASSERT( atom1 != NULL );
148 CPPUNIT_ASSERT( atom2 != NULL );
149
150 // add bond
151 Binder = TestMolecule->AddBond(atom1, atom2, 1);
152 CPPUNIT_ASSERT( Binder != NULL );
153
154 // remove bond
155 TestMolecule->RemoveBond(Binder);
156
157 // check if removed from atoms
158 {
159 const BondList& ListOfBonds = atom1->getListOfBonds();
160 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
161 }
162 {
163 const BondList& ListOfBonds = atom2->getListOfBonds();
164 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
165 }
166
167 // check if removed from molecule
168 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
169};
170
171/** Unit Test of molecule::RemoveBonds()
172 *
173 */
174void ListOfBondsTest::RemovingBondsTest()
175{
176 bond *Binder = NULL;
177 molecule::iterator iter = TestMolecule->begin();
178 atom *atom1 = *iter;
179 iter++;
180 atom *atom2 = *iter;
181 iter++;
182 atom *atom3 = *iter;
183 CPPUNIT_ASSERT( atom1 != NULL );
184 CPPUNIT_ASSERT( atom2 != NULL );
185 CPPUNIT_ASSERT( atom3 != NULL );
186
187 // add bond
188 Binder = TestMolecule->AddBond(atom1, atom2, 1);
189 CPPUNIT_ASSERT( Binder != NULL );
190 Binder = TestMolecule->AddBond(atom1, atom3, 1);
191 CPPUNIT_ASSERT( Binder != NULL );
192 Binder = TestMolecule->AddBond(atom2, atom3, 1);
193 CPPUNIT_ASSERT( Binder != NULL );
194
195 // check that all are present
196 {
197 const BondList& ListOfBonds = atom1->getListOfBonds();
198 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
199 }
200 {
201 const BondList& ListOfBonds = atom2->getListOfBonds();
202 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
203 }
204 {
205 const BondList& ListOfBonds = atom3->getListOfBonds();
206 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
207 }
208
209 // remove bond
210 TestMolecule->RemoveBonds(atom1);
211
212 // check if removed from atoms
213 {
214 const BondList& ListOfBonds = atom1->getListOfBonds();
215 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
216 }
217 {
218 const BondList& ListOfBonds = atom2->getListOfBonds();
219 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
220 }
221 {
222 const BondList& ListOfBonds = atom3->getListOfBonds();
223 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
224 }
225
226 // check if removed from molecule
227 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
228 CPPUNIT_ASSERT_EQUAL( (unsigned int)1, TestMolecule->CountBonds() );
229};
230
231/** Unit Test of delete(bond *)
232 *
233 */
234void ListOfBondsTest::DeleteBondTest()
235{
236 bond *Binder = NULL;
237 molecule::iterator iter = TestMolecule->begin();
238 atom *atom1 = *iter;
239 iter++;
240 atom *atom2 = *iter;
241 CPPUNIT_ASSERT( atom1 != NULL );
242 CPPUNIT_ASSERT( atom2 != NULL );
243
244 // add bond
245 Binder = TestMolecule->AddBond(atom1, atom2, 1);
246 CPPUNIT_ASSERT( Binder != NULL );
247
248 // remove bond
249 delete(Binder);
250
251 // check if removed from atoms
252 {
253 const BondList& ListOfBonds = atom1->getListOfBonds();
254 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
255 }
256 {
257 const BondList& ListOfBonds = atom2->getListOfBonds();
258 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
259 }
260
261 // check if removed from molecule
262 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
263};
264
265/** Unit Test of molecule::RemoveAtom()
266 *
267 */
268void ListOfBondsTest::RemoveAtomTest()
269{
270 bond *Binder = NULL;
271 molecule::iterator iter = TestMolecule->begin();
272 atom *atom1 = *iter;
273 iter++;
274 atom *atom2 = *iter;
275 CPPUNIT_ASSERT( atom1 != NULL );
276 CPPUNIT_ASSERT( atom2 != NULL );
277
278 // add bond
279 Binder = TestMolecule->AddBond(atom1, atom2, 1);
280 CPPUNIT_ASSERT( Binder != NULL );
281
282 // remove atom2
283 TestMolecule->RemoveAtom(atom2);
284
285 // check bond if removed from other atom
286 {
287 const BondList& ListOfBonds = atom1->getListOfBonds();
288 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
289 }
290
291 // check if removed from molecule
292 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
293};
294
295/** Unit Test of delete(atom *)
296 *
297 */
298void ListOfBondsTest::DeleteAtomTest()
299{
300 atom *atom1 = NULL;
301 atom *atom2 = NULL;
302 bond *Binder = NULL;
303 {
304 molecule::iterator iter = TestMolecule->begin();
305 atom1 = *iter;
306 iter++;
307 atom2 = *iter;
308 }
309 CPPUNIT_ASSERT( atom1 != NULL );
310 CPPUNIT_ASSERT( atom2 != NULL );
311
312 // add bond
313 Binder = TestMolecule->AddBond(atom1, atom2, 1);
314 CPPUNIT_ASSERT( Binder != NULL );
315
316 {
317 const BondList& ListOfBonds = atom1->getListOfBonds();
318 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
319 }
320 {
321 const BondList& ListOfBonds = atom2->getListOfBonds();
322 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
323 }
324
325 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
326
327 // remove atom2
328 World::getInstance().destroyAtom(atom2);
329
330 // check bond if removed from other atom
331 {
332 const BondList& ListOfBonds = atom1->getListOfBonds();
333 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
334 }
335
336 // check if removed from molecule
337 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
338};
Note: See TracBrowser for help on using the repository browser.