source: src/unittests/ListOfBondsUnitTest.cpp@ d449a9

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 d449a9 was 7d82a5, checked in by Frederik Heber <heber@…>, 12 years ago

Changed bond::ptr into boost::shared_ptr.

Changes:

  • refactored some BondedParticle functions, cleaning up the interface in terms of private and public functionality, added some helper functions to find bonds.
  • ptr = NULL --> .reset().
  • now initialising to NULL.
  • BondsPerSP is now list of boost::shared_ptr as well.
  • some include of bond.hpp instead of forward references necessary.
  • leftatom and rightatom are now set to NULL on UnregisterBond().
  • bonds are not deleted anymore but simply unregistered.
  • FIX: BondedParticleInfo did unrequiredly inherit AtomObservable.
  • removed UnregisterAllBonds(), code is now in RemoveAllBonds() where UnregisterBond is called for both bond partners. This ensures that the bond is correctly released and shared_ptr free'd.
  • Property mode set to 100644
File size: 9.5 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]21 */
22
[266237]23/*
[f844ef]24 * ListOfBondsUnitTest.cpp
[266237]25 *
26 * Created on: 18 Oct 2009
27 * Author: user
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[266237]35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
[49e1ae]41#include <cstring>
42
[255829]43#include "CodePatterns/Log.hpp"
[46d958]44#include "World.hpp"
[6f0841]45#include "Atom/atom.hpp"
[7d82a5]46#include "Atom/AtomObserver.hpp"
47
[129204]48#include "Bond/bond.hpp"
[3bdb6d]49#include "Element/element.hpp"
[266237]50#include "molecule.hpp"
[3bdb6d]51#include "Element/periodentafel.hpp"
[e6fdbe]52#include "World.hpp"
[8aba3c]53#include "WorldTime.hpp"
[266237]54
[f844ef]55#include "ListOfBondsUnitTest.hpp"
56
[9b6b2f]57#ifdef HAVE_TESTRUNNER
58#include "UnitTestMain.hpp"
59#endif /*HAVE_TESTRUNNER*/
[266237]60
61/********************************************** Test classes **************************************/
62
63// Registers the fixture into the 'registry'
64CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
65
66
67void ListOfBondsTest::setUp()
68{
69 atom *Walker = NULL;
70
[040a5c]71 WorldTime::getInstance().setTime(0);
[5e2f80]72
[266237]73 // construct element
[4eb4fe]74 hydrogen = World::getInstance().getPeriode()->FindElement(1);
75 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
[266237]76
77 // construct molecule (tetraeder of hydrogens)
[23b547]78 TestMolecule = World::getInstance().createMolecule();
[4eb4fe]79 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
[23b547]80 Walker = World::getInstance().createAtom();
[4eb4fe]81 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]82 Walker->setType(hydrogen);
83 Walker->setPosition(Vector(1., 0., 1. ));
[266237]84 TestMolecule->AddAtom(Walker);
[23b547]85 Walker = World::getInstance().createAtom();
[4eb4fe]86 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]87 Walker->setType(hydrogen);
88 Walker->setPosition(Vector(0., 1., 1. ));
[266237]89 TestMolecule->AddAtom(Walker);
[23b547]90 Walker = World::getInstance().createAtom();
[4eb4fe]91 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]92 Walker->setType(hydrogen);
93 Walker->setPosition(Vector(1., 1., 0. ));
[266237]94 TestMolecule->AddAtom(Walker);
[23b547]95 Walker = World::getInstance().createAtom();
[4eb4fe]96 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]97 Walker->setType(hydrogen);
98 Walker->setPosition(Vector(0., 0., 0. ));
[266237]99 TestMolecule->AddAtom(Walker);
100
101 // check that TestMolecule was correctly constructed
[ea7176]102 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
[266237]103};
104
105
106void ListOfBondsTest::tearDown()
107{
108 // remove
[23b547]109 World::getInstance().destroyMolecule(TestMolecule);
[a1510d]110 // note that all the atoms, molecules, the tafel and the elements
111 // are all cleaned when the world is destroyed
[23b547]112 World::purgeInstance();
[7d82a5]113 AtomObserver::purgeInstance();
[e6fdbe]114 logger::purgeInstance();
[7d82a5]115 errorLogger::purgeInstance();
116 WorldTime::purgeInstance();
117
[266237]118};
119
[9879f6]120/** Tests whether setup worked correctly.
121 *
122 */
123void ListOfBondsTest::SetupTest()
124{
125 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
126 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
127};
128
[266237]129/** Unit Test of molecule::AddBond()
130 *
131 */
132void ListOfBondsTest::AddingBondTest()
133{
[7d82a5]134 bond::ptr Binder;
[9879f6]135 molecule::iterator iter = TestMolecule->begin();
136 atom *atom1 = *iter;
137 iter++;
138 atom *atom2 = *iter;
[266237]139 CPPUNIT_ASSERT( atom1 != NULL );
140 CPPUNIT_ASSERT( atom2 != NULL );
141
142 // add bond
143 Binder = TestMolecule->AddBond(atom1, atom2, 1);
144 CPPUNIT_ASSERT( Binder != NULL );
[e08c46]145 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
[266237]146
147 // check that bond contains the two atoms
148 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
149 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
150
151 // check that bond is present in both atoms
[5e2f80]152 const BondList &bondlist1 = atom1->getListOfBonds();
[9d83b6]153 BondList::const_iterator bonditer;
[5e2f80]154 bonditer = bondlist1.begin();
[88c8ec]155 bond::ptr TestBond1 = *bonditer;
[266237]156 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
[5e2f80]157 const BondList &bondlist2 = atom2->getListOfBonds();
158 bonditer = bondlist2.begin();
[88c8ec]159 bond::ptr TestBond2 = *bonditer;
[266237]160 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
161};
162
[88c8ec]163/** Unit Test of delete(bond::ptr )
[266237]164 *
165 */
166void ListOfBondsTest::DeleteBondTest()
167{
[7d82a5]168 bond::ptr Binder;
[9879f6]169 molecule::iterator iter = TestMolecule->begin();
170 atom *atom1 = *iter;
171 iter++;
172 atom *atom2 = *iter;
[266237]173 CPPUNIT_ASSERT( atom1 != NULL );
174 CPPUNIT_ASSERT( atom2 != NULL );
175
176 // add bond
177 Binder = TestMolecule->AddBond(atom1, atom2, 1);
178 CPPUNIT_ASSERT( Binder != NULL );
179
180 // remove bond
[7d82a5]181 atom1->removeBond(Binder);
182 // removed for atom2 automatically but check where nothing breaks
183 atom2->removeBond(Binder);
[266237]184
185 // check if removed from atoms
[9d83b6]186 {
187 const BondList& ListOfBonds = atom1->getListOfBonds();
188 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
189 }
190 {
191 const BondList& ListOfBonds = atom2->getListOfBonds();
192 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
193 }
[266237]194
195 // check if removed from molecule
[e08c46]196 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]197};
198
199/** Unit Test of delete(atom *)
200 *
201 */
202void ListOfBondsTest::DeleteAtomTest()
203{
[f8e486]204 atom *atom1 = NULL;
205 atom *atom2 = NULL;
[7d82a5]206 bond::ptr Binder;
[f8e486]207 {
208 molecule::iterator iter = TestMolecule->begin();
209 atom1 = *iter;
210 iter++;
211 atom2 = *iter;
212 }
[266237]213 CPPUNIT_ASSERT( atom1 != NULL );
214 CPPUNIT_ASSERT( atom2 != NULL );
[7d82a5]215 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->getListOfBonds().size() );
216 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->getListOfBonds().size() );
[266237]217
218 // add bond
219 Binder = TestMolecule->AddBond(atom1, atom2, 1);
220 CPPUNIT_ASSERT( Binder != NULL );
221
[8aba3c]222 // access test via CurrentTime
[7d82a5]223 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->getListOfBonds().size() );
224 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->getListOfBonds().size() );
[6cfa36]225
[a80241]226 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
227
[266237]228 // remove atom2
[23b547]229 World::getInstance().destroyAtom(atom2);
[266237]230
[8aba3c]231 // check bond if removed from other atom for all time steps
[9d83b6]232 {
233 const BondList& ListOfBonds = atom1->getListOfBonds();
234 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
235 }
[266237]236
237 // check if removed from molecule
[a80241]238 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]239};
[8aba3c]240
241/** Unit test on ListOfBonds at multiple time steps.
242 *
243 */
244void ListOfBondsTest::MultipleTimeStepTest()
245{
246 atom *atom1 = NULL;
247 atom *atom2 = NULL;
[7d82a5]248 bond::ptr Binder;
[8aba3c]249 {
250 molecule::iterator iter = TestMolecule->begin();
251 atom1 = *iter;
252 iter++;
253 atom2 = *iter;
254 }
255 CPPUNIT_ASSERT( atom1 != NULL );
256 CPPUNIT_ASSERT( atom2 != NULL );
257
258 // add bond
[040a5c]259 WorldTime::getInstance().setTime(0);
[8aba3c]260 Binder = TestMolecule->AddBond(atom1, atom2, 1);
261 CPPUNIT_ASSERT( Binder != NULL );
[040a5c]262 WorldTime::getInstance().setTime(1);
[8aba3c]263 Binder = TestMolecule->AddBond(atom1, atom2, 1);
264 CPPUNIT_ASSERT( Binder != NULL );
265
266 // access test via CurrentTime
267 { // time step 0
[040a5c]268 WorldTime::getInstance().setTime(0);
[8aba3c]269 {
270 const BondList& ListOfBonds = atom1->getListOfBonds();
271 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
272 }
273 {
274 const BondList& ListOfBonds = atom2->getListOfBonds();
275 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
276 }
277 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
278 }
279 { // time step 1
[040a5c]280 WorldTime::getInstance().setTime(1);
[8aba3c]281 {
282 const BondList& ListOfBonds = atom1->getListOfBonds();
283 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
284 }
285 {
286 const BondList& ListOfBonds = atom2->getListOfBonds();
287 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
288 }
289 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
[040a5c]290 WorldTime::getInstance().setTime(0);
[8aba3c]291 }
292
293 // access time step directly.
294 { // time step 0
295 {
296 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(0);
297 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
298 }
299 {
300 const BondList& ListOfBonds = atom2->getListOfBondsAtStep(0);
301 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
302 }
303 }
304 { // time step 1
305 {
306 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
307 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
308 }
309 {
310 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
311 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
312 }
313 }
314
315 // remove atom2
316 World::getInstance().destroyAtom(atom2);
317
318 // check bond if removed from other atom for all time steps
319 {
[040a5c]320 WorldTime::getInstance().setTime(0);
[8aba3c]321 const BondList& ListOfBonds = atom1->getListOfBonds();
322 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
323 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
324 }
325 {
[040a5c]326 WorldTime::getInstance().setTime(1);
[8aba3c]327 const BondList& ListOfBonds = atom1->getListOfBonds();
328 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
329 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[040a5c]330 WorldTime::getInstance().setTime(0);
[8aba3c]331 }
332
333}
Note: See TracBrowser for help on using the repository browser.