source: src/unittests/listofbondsunittest.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 7.6 KB
RevLine 
[266237]1/*
2 * listofbondsunittest.cpp
3 *
4 * Created on: 18 Oct 2009
5 * Author: user
6 */
7
[bf3817]8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
[266237]13using namespace std;
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
[49e1ae]19#include <cstring>
20
[266237]21#include "listofbondsunittest.hpp"
22
[46d958]23#include "World.hpp"
[266237]24#include "atom.hpp"
25#include "bond.hpp"
26#include "element.hpp"
27#include "molecule.hpp"
28#include "periodentafel.hpp"
[e6fdbe]29#include "World.hpp"
[266237]30
[9b6b2f]31#ifdef HAVE_TESTRUNNER
32#include "UnitTestMain.hpp"
33#endif /*HAVE_TESTRUNNER*/
[266237]34
35/********************************************** Test classes **************************************/
36
37// Registers the fixture into the 'registry'
38CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
39
40
41void ListOfBondsTest::setUp()
42{
43 atom *Walker = NULL;
44
45 // construct element
[4eb4fe]46 hydrogen = World::getInstance().getPeriode()->FindElement(1);
47 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
[266237]48
49 // construct molecule (tetraeder of hydrogens)
[23b547]50 TestMolecule = World::getInstance().createMolecule();
[4eb4fe]51 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
[23b547]52 Walker = World::getInstance().createAtom();
[4eb4fe]53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]54 Walker->setType(hydrogen);
55 Walker->setPosition(Vector(1., 0., 1. ));
[266237]56 TestMolecule->AddAtom(Walker);
[23b547]57 Walker = World::getInstance().createAtom();
[4eb4fe]58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]59 Walker->setType(hydrogen);
60 Walker->setPosition(Vector(0., 1., 1. ));
[266237]61 TestMolecule->AddAtom(Walker);
[23b547]62 Walker = World::getInstance().createAtom();
[4eb4fe]63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]64 Walker->setType(hydrogen);
65 Walker->setPosition(Vector(1., 1., 0. ));
[266237]66 TestMolecule->AddAtom(Walker);
[23b547]67 Walker = World::getInstance().createAtom();
[4eb4fe]68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
[d74077]69 Walker->setType(hydrogen);
70 Walker->setPosition(Vector(0., 0., 0. ));
[266237]71 TestMolecule->AddAtom(Walker);
72
73 // check that TestMolecule was correctly constructed
[ea7176]74 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
[266237]75};
76
77
78void ListOfBondsTest::tearDown()
79{
80 // remove
[23b547]81 World::getInstance().destroyMolecule(TestMolecule);
[a1510d]82 // note that all the atoms, molecules, the tafel and the elements
83 // are all cleaned when the world is destroyed
[23b547]84 World::purgeInstance();
[e6fdbe]85 logger::purgeInstance();
[266237]86};
87
[9879f6]88/** Tests whether setup worked correctly.
89 *
90 */
91void ListOfBondsTest::SetupTest()
92{
93 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
94 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
95};
96
[266237]97/** Unit Test of molecule::AddBond()
98 *
99 */
100void ListOfBondsTest::AddingBondTest()
101{
102 bond *Binder = NULL;
[9879f6]103 molecule::iterator iter = TestMolecule->begin();
104 atom *atom1 = *iter;
105 iter++;
106 atom *atom2 = *iter;
[266237]107 CPPUNIT_ASSERT( atom1 != NULL );
108 CPPUNIT_ASSERT( atom2 != NULL );
109
110 // add bond
111 Binder = TestMolecule->AddBond(atom1, atom2, 1);
112 CPPUNIT_ASSERT( Binder != NULL );
[e08c46]113 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
[266237]114
115 // check that bond contains the two atoms
116 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
117 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
118
119 // check that bond is present in both atoms
120 bond *TestBond1 = *(atom1->ListOfBonds.begin());
121 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
122 bond *TestBond2 = *(atom2->ListOfBonds.begin());
123 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
124};
125
126/** Unit Test of molecule::RemoveBond()
127 *
128 */
129void ListOfBondsTest::RemovingBondTest()
130{
131 bond *Binder = NULL;
[9879f6]132 molecule::iterator iter = TestMolecule->begin();
133 atom *atom1 = *iter;
134 iter++;
135 atom *atom2 = *iter;
[266237]136 CPPUNIT_ASSERT( atom1 != NULL );
137 CPPUNIT_ASSERT( atom2 != NULL );
138
139 // add bond
140 Binder = TestMolecule->AddBond(atom1, atom2, 1);
141 CPPUNIT_ASSERT( Binder != NULL );
142
143 // remove bond
144 TestMolecule->RemoveBond(Binder);
145
146 // check if removed from atoms
147 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
148 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
149
150 // check if removed from molecule
[e08c46]151 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]152};
153
154/** Unit Test of molecule::RemoveBonds()
155 *
156 */
157void ListOfBondsTest::RemovingBondsTest()
158{
159 bond *Binder = NULL;
[9879f6]160 molecule::iterator iter = TestMolecule->begin();
161 atom *atom1 = *iter;
162 iter++;
163 atom *atom2 = *iter;
164 iter++;
165 atom *atom3 = *iter;
[266237]166 CPPUNIT_ASSERT( atom1 != NULL );
167 CPPUNIT_ASSERT( atom2 != NULL );
168 CPPUNIT_ASSERT( atom3 != NULL );
169
170 // add bond
171 Binder = TestMolecule->AddBond(atom1, atom2, 1);
172 CPPUNIT_ASSERT( Binder != NULL );
173 Binder = TestMolecule->AddBond(atom1, atom3, 1);
174 CPPUNIT_ASSERT( Binder != NULL );
175 Binder = TestMolecule->AddBond(atom2, atom3, 1);
176 CPPUNIT_ASSERT( Binder != NULL );
177
178 // check that all are present
179 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
180 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
181 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
182
183 // remove bond
184 TestMolecule->RemoveBonds(atom1);
185
186 // check if removed from atoms
187 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
188 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
189 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
190
191 // check if removed from molecule
[e08c46]192 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
193 CPPUNIT_ASSERT_EQUAL( (unsigned int)1, TestMolecule->CountBonds() );
[266237]194};
195
196/** Unit Test of delete(bond *)
197 *
198 */
199void ListOfBondsTest::DeleteBondTest()
200{
201 bond *Binder = NULL;
[9879f6]202 molecule::iterator iter = TestMolecule->begin();
203 atom *atom1 = *iter;
204 iter++;
205 atom *atom2 = *iter;
[266237]206 CPPUNIT_ASSERT( atom1 != NULL );
207 CPPUNIT_ASSERT( atom2 != NULL );
208
209 // add bond
210 Binder = TestMolecule->AddBond(atom1, atom2, 1);
211 CPPUNIT_ASSERT( Binder != NULL );
212
213 // remove bond
214 delete(Binder);
215
216 // check if removed from atoms
217 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
218 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
219
220 // check if removed from molecule
[e08c46]221 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]222};
223
224/** Unit Test of molecule::RemoveAtom()
225 *
226 */
227void ListOfBondsTest::RemoveAtomTest()
228{
229 bond *Binder = NULL;
[9879f6]230 molecule::iterator iter = TestMolecule->begin();
231 atom *atom1 = *iter;
232 iter++;
233 atom *atom2 = *iter;
[266237]234 CPPUNIT_ASSERT( atom1 != NULL );
235 CPPUNIT_ASSERT( atom2 != NULL );
236
237 // add bond
238 Binder = TestMolecule->AddBond(atom1, atom2, 1);
239 CPPUNIT_ASSERT( Binder != NULL );
240
241 // remove atom2
242 TestMolecule->RemoveAtom(atom2);
243
244 // check bond if removed from other atom
245 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
246
247 // check if removed from molecule
[e08c46]248 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]249};
250
251/** Unit Test of delete(atom *)
252 *
253 */
254void ListOfBondsTest::DeleteAtomTest()
255{
[f8e486]256 atom *atom1 = NULL;
257 atom *atom2 = NULL;
[266237]258 bond *Binder = NULL;
[f8e486]259 {
260 molecule::iterator iter = TestMolecule->begin();
261 atom1 = *iter;
262 iter++;
263 atom2 = *iter;
264 }
[266237]265 CPPUNIT_ASSERT( atom1 != NULL );
266 CPPUNIT_ASSERT( atom2 != NULL );
267
268 // add bond
269 Binder = TestMolecule->AddBond(atom1, atom2, 1);
270 CPPUNIT_ASSERT( Binder != NULL );
271
[6cfa36]272 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->ListOfBonds.size() );
273 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
274
[a80241]275 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
276
[266237]277 // remove atom2
[23b547]278 World::getInstance().destroyAtom(atom2);
[266237]279
280 // check bond if removed from other atom
281 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
282
283 // check if removed from molecule
[a80241]284 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
[266237]285};
Note: See TracBrowser for help on using the repository browser.