source: src/unittests/listofbondsunittest.cpp@ 4c1230

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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