source: src/unittests/ListOfBondsUnitTest.cpp@ 4cf35ac

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 4cf35ac was 255829, checked in by Frederik Heber <heber@…>, 14 years ago

Removed Helpers.hpp, deleted Helpers.cpp and libMoleCuilderHelpers.la is history.

  • defs.cpp is now compiled into libmolecuilder.la.
  • ShapeUnitTest alone needs defs.cpp.
  • Most changes are removal of Helpers/helpers.hpp.
  • performCriticalExit() now inline function in Helpers/helpers.hpp.
  • also inclusion possible where performCriticalExit() is needed.
  • Helpers/helpers.hpp does not include defs.hpp anymore and this causes lots of missing Helpers/defs.hpp, CodePatterns/Log.hpp and alikes.
  • removed src/Helpers from configure.ac.
  • Property mode set to 100644
File size: 11.5 KB
RevLine 
[bcf653]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
[266237]8/*
[f844ef]9 * ListOfBondsUnitTest.cpp
[266237]10 *
11 * Created on: 18 Oct 2009
12 * Author: user
13 */
14
[bf3817]15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[266237]20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
[49e1ae]26#include <cstring>
27
[255829]28#include "CodePatterns/Log.hpp"
[46d958]29#include "World.hpp"
[266237]30#include "atom.hpp"
[129204]31#include "Bond/bond.hpp"
[266237]32#include "element.hpp"
33#include "molecule.hpp"
34#include "periodentafel.hpp"
[e6fdbe]35#include "World.hpp"
[8aba3c]36#include "WorldTime.hpp"
[266237]37
[f844ef]38#include "ListOfBondsUnitTest.hpp"
39
[9b6b2f]40#ifdef HAVE_TESTRUNNER
41#include "UnitTestMain.hpp"
42#endif /*HAVE_TESTRUNNER*/
[266237]43
44/********************************************** Test classes **************************************/
45
46// Registers the fixture into the 'registry'
47CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
48
49
50void ListOfBondsTest::setUp()
51{
52 atom *Walker = NULL;
53
54 // construct element
[4eb4fe]55 hydrogen = World::getInstance().getPeriode()->FindElement(1);
56 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
[266237]57
58 // construct molecule (tetraeder of hydrogens)
[23b547]59 TestMolecule = World::getInstance().createMolecule();
[4eb4fe]60 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
[23b547]61 Walker = World::getInstance().createAtom();
[4eb4fe]62 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]63 Walker->setType(hydrogen);
64 Walker->setPosition(Vector(1., 0., 1. ));
[266237]65 TestMolecule->AddAtom(Walker);
[23b547]66 Walker = World::getInstance().createAtom();
[4eb4fe]67 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]68 Walker->setType(hydrogen);
69 Walker->setPosition(Vector(0., 1., 1. ));
[266237]70 TestMolecule->AddAtom(Walker);
[23b547]71 Walker = World::getInstance().createAtom();
[4eb4fe]72 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]73 Walker->setType(hydrogen);
74 Walker->setPosition(Vector(1., 1., 0. ));
[266237]75 TestMolecule->AddAtom(Walker);
[23b547]76 Walker = World::getInstance().createAtom();
[4eb4fe]77 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]78 Walker->setType(hydrogen);
79 Walker->setPosition(Vector(0., 0., 0. ));
[266237]80 TestMolecule->AddAtom(Walker);
81
82 // check that TestMolecule was correctly constructed
[ea7176]83 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
[266237]84};
85
86
87void ListOfBondsTest::tearDown()
88{
89 // remove
[23b547]90 World::getInstance().destroyMolecule(TestMolecule);
[a1510d]91 // note that all the atoms, molecules, the tafel and the elements
92 // are all cleaned when the world is destroyed
[23b547]93 World::purgeInstance();
[e6fdbe]94 logger::purgeInstance();
[266237]95};
96
[9879f6]97/** Tests whether setup worked correctly.
98 *
99 */
100void ListOfBondsTest::SetupTest()
101{
102 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
103 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
104};
105
[266237]106/** Unit Test of molecule::AddBond()
107 *
108 */
109void ListOfBondsTest::AddingBondTest()
110{
111 bond *Binder = NULL;
[9879f6]112 molecule::iterator iter = TestMolecule->begin();
113 atom *atom1 = *iter;
114 iter++;
115 atom *atom2 = *iter;
[266237]116 CPPUNIT_ASSERT( atom1 != NULL );
117 CPPUNIT_ASSERT( atom2 != NULL );
118
119 // add bond
120 Binder = TestMolecule->AddBond(atom1, atom2, 1);
121 CPPUNIT_ASSERT( Binder != NULL );
[e08c46]122 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
[266237]123
124 // check that bond contains the two atoms
125 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
126 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
127
128 // check that bond is present in both atoms
[9d83b6]129 BondList::const_iterator bonditer;
130 bonditer = atom1->getListOfBonds().begin();
131 bond *TestBond1 = *bonditer;
[266237]132 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
[9d83b6]133 bonditer = atom2->getListOfBonds().begin();
134 bond *TestBond2 = *bonditer;
[266237]135 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
136};
137
138/** Unit Test of molecule::RemoveBond()
139 *
140 */
141void ListOfBondsTest::RemovingBondTest()
142{
143 bond *Binder = NULL;
[9879f6]144 molecule::iterator iter = TestMolecule->begin();
145 atom *atom1 = *iter;
146 iter++;
147 atom *atom2 = *iter;
[266237]148 CPPUNIT_ASSERT( atom1 != NULL );
149 CPPUNIT_ASSERT( atom2 != NULL );
150
151 // add bond
152 Binder = TestMolecule->AddBond(atom1, atom2, 1);
153 CPPUNIT_ASSERT( Binder != NULL );
154
155 // remove bond
156 TestMolecule->RemoveBond(Binder);
157
158 // check if removed from atoms
[9d83b6]159 {
160 const BondList& ListOfBonds = atom1->getListOfBonds();
161 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
162 }
163 {
164 const BondList& ListOfBonds = atom2->getListOfBonds();
165 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
166 }
[266237]167
168 // check if removed from molecule
[e08c46]169 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]170};
171
172/** Unit Test of molecule::RemoveBonds()
173 *
174 */
175void ListOfBondsTest::RemovingBondsTest()
176{
177 bond *Binder = NULL;
[9879f6]178 molecule::iterator iter = TestMolecule->begin();
179 atom *atom1 = *iter;
180 iter++;
181 atom *atom2 = *iter;
182 iter++;
183 atom *atom3 = *iter;
[266237]184 CPPUNIT_ASSERT( atom1 != NULL );
185 CPPUNIT_ASSERT( atom2 != NULL );
186 CPPUNIT_ASSERT( atom3 != NULL );
187
188 // add bond
189 Binder = TestMolecule->AddBond(atom1, atom2, 1);
190 CPPUNIT_ASSERT( Binder != NULL );
191 Binder = TestMolecule->AddBond(atom1, atom3, 1);
192 CPPUNIT_ASSERT( Binder != NULL );
193 Binder = TestMolecule->AddBond(atom2, atom3, 1);
194 CPPUNIT_ASSERT( Binder != NULL );
195
196 // check that all are present
[9d83b6]197 {
198 const BondList& ListOfBonds = atom1->getListOfBonds();
199 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
200 }
201 {
202 const BondList& ListOfBonds = atom2->getListOfBonds();
203 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
204 }
205 {
206 const BondList& ListOfBonds = atom3->getListOfBonds();
207 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
208 }
[266237]209
210 // remove bond
211 TestMolecule->RemoveBonds(atom1);
212
213 // check if removed from atoms
[9d83b6]214 {
215 const BondList& ListOfBonds = atom1->getListOfBonds();
216 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
217 }
218 {
219 const BondList& ListOfBonds = atom2->getListOfBonds();
220 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
221 }
222 {
223 const BondList& ListOfBonds = atom3->getListOfBonds();
224 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
225 }
[266237]226
227 // check if removed from molecule
[e08c46]228 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
[458c31]229 CPPUNIT_ASSERT_EQUAL( (int)1, TestMolecule->getBondCount() );
[266237]230};
231
232/** Unit Test of delete(bond *)
233 *
234 */
235void ListOfBondsTest::DeleteBondTest()
236{
237 bond *Binder = NULL;
[9879f6]238 molecule::iterator iter = TestMolecule->begin();
239 atom *atom1 = *iter;
240 iter++;
241 atom *atom2 = *iter;
[266237]242 CPPUNIT_ASSERT( atom1 != NULL );
243 CPPUNIT_ASSERT( atom2 != NULL );
244
245 // add bond
246 Binder = TestMolecule->AddBond(atom1, atom2, 1);
247 CPPUNIT_ASSERT( Binder != NULL );
248
249 // remove bond
250 delete(Binder);
251
252 // check if removed from atoms
[9d83b6]253 {
254 const BondList& ListOfBonds = atom1->getListOfBonds();
255 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
256 }
257 {
258 const BondList& ListOfBonds = atom2->getListOfBonds();
259 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
260 }
[266237]261
262 // check if removed from molecule
[e08c46]263 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]264};
265
266/** Unit Test of molecule::RemoveAtom()
267 *
268 */
269void ListOfBondsTest::RemoveAtomTest()
270{
271 bond *Binder = NULL;
[9879f6]272 molecule::iterator iter = TestMolecule->begin();
273 atom *atom1 = *iter;
274 iter++;
275 atom *atom2 = *iter;
[266237]276 CPPUNIT_ASSERT( atom1 != NULL );
277 CPPUNIT_ASSERT( atom2 != NULL );
278
279 // add bond
280 Binder = TestMolecule->AddBond(atom1, atom2, 1);
281 CPPUNIT_ASSERT( Binder != NULL );
282
283 // remove atom2
284 TestMolecule->RemoveAtom(atom2);
285
286 // check bond if removed from other atom
[9d83b6]287 {
288 const BondList& ListOfBonds = atom1->getListOfBonds();
289 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
290 }
[266237]291
292 // check if removed from molecule
[e08c46]293 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]294};
295
296/** Unit Test of delete(atom *)
297 *
298 */
299void ListOfBondsTest::DeleteAtomTest()
300{
[f8e486]301 atom *atom1 = NULL;
302 atom *atom2 = NULL;
[266237]303 bond *Binder = NULL;
[f8e486]304 {
305 molecule::iterator iter = TestMolecule->begin();
306 atom1 = *iter;
307 iter++;
308 atom2 = *iter;
309 }
[266237]310 CPPUNIT_ASSERT( atom1 != NULL );
311 CPPUNIT_ASSERT( atom2 != NULL );
312
313 // add bond
314 Binder = TestMolecule->AddBond(atom1, atom2, 1);
315 CPPUNIT_ASSERT( Binder != NULL );
316
[8aba3c]317 // access test via CurrentTime
[9d83b6]318 {
319 const BondList& ListOfBonds = atom1->getListOfBonds();
320 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
321 }
322 {
323 const BondList& ListOfBonds = atom2->getListOfBonds();
324 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
325 }
[6cfa36]326
[a80241]327 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
328
[266237]329 // remove atom2
[23b547]330 World::getInstance().destroyAtom(atom2);
[266237]331
[8aba3c]332 // check bond if removed from other atom for all time steps
[9d83b6]333 {
334 const BondList& ListOfBonds = atom1->getListOfBonds();
335 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
336 }
[266237]337
338 // check if removed from molecule
[a80241]339 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]340};
[8aba3c]341
342/** Unit test on ListOfBonds at multiple time steps.
343 *
344 */
345void ListOfBondsTest::MultipleTimeStepTest()
346{
347 atom *atom1 = NULL;
348 atom *atom2 = NULL;
349 bond *Binder = NULL;
350 {
351 molecule::iterator iter = TestMolecule->begin();
352 atom1 = *iter;
353 iter++;
354 atom2 = *iter;
355 }
356 CPPUNIT_ASSERT( atom1 != NULL );
357 CPPUNIT_ASSERT( atom2 != NULL );
358
359 // add bond
360 WorldTime::setTime(0);
361 Binder = TestMolecule->AddBond(atom1, atom2, 1);
362 CPPUNIT_ASSERT( Binder != NULL );
363 WorldTime::setTime(1);
364 Binder = TestMolecule->AddBond(atom1, atom2, 1);
365 CPPUNIT_ASSERT( Binder != NULL );
366
367 // access test via CurrentTime
368 { // time step 0
369 WorldTime::setTime(0);
370 {
371 const BondList& ListOfBonds = atom1->getListOfBonds();
372 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
373 }
374 {
375 const BondList& ListOfBonds = atom2->getListOfBonds();
376 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
377 }
378 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
379 }
380 { // time step 1
381 WorldTime::setTime(1);
382 {
383 const BondList& ListOfBonds = atom1->getListOfBonds();
384 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
385 }
386 {
387 const BondList& ListOfBonds = atom2->getListOfBonds();
388 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
389 }
390 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
391 WorldTime::setTime(0);
392 }
393
394 // access time step directly.
395 { // time step 0
396 {
397 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(0);
398 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
399 }
400 {
401 const BondList& ListOfBonds = atom2->getListOfBondsAtStep(0);
402 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
403 }
404 }
405 { // time step 1
406 {
407 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
408 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
409 }
410 {
411 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
412 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
413 }
414 }
415
416 // remove atom2
417 World::getInstance().destroyAtom(atom2);
418
419 // check bond if removed from other atom for all time steps
420 {
421 WorldTime::setTime(0);
422 const BondList& ListOfBonds = atom1->getListOfBonds();
423 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
424 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
425 }
426 {
427 WorldTime::setTime(1);
428 const BondList& ListOfBonds = atom1->getListOfBonds();
429 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
430 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
431 WorldTime::setTime(0);
432 }
433
434}
Note: See TracBrowser for help on using the repository browser.