source: src/unittests/ListOfBondsUnitTest.cpp@ 72d108

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 72d108 was f844ef, checked in by Frederik Heber <heber@…>, 14 years ago

Renamed all remaining unit tests in src/unittests to Capitalized naming scheme.

  • some includes had to be changed.
  • some other files too due to befriended member functions of unit tests.
  • 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
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 bond *TestBond1 = *(atom1->ListOfBonds.begin());
129 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
130 bond *TestBond2 = *(atom2->ListOfBonds.begin());
131 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
132};
133
134/** Unit Test of molecule::RemoveBond()
135 *
136 */
137void ListOfBondsTest::RemovingBondTest()
138{
139 bond *Binder = NULL;
140 molecule::iterator iter = TestMolecule->begin();
141 atom *atom1 = *iter;
142 iter++;
143 atom *atom2 = *iter;
144 CPPUNIT_ASSERT( atom1 != NULL );
145 CPPUNIT_ASSERT( atom2 != NULL );
146
147 // add bond
148 Binder = TestMolecule->AddBond(atom1, atom2, 1);
149 CPPUNIT_ASSERT( Binder != NULL );
150
151 // remove bond
152 TestMolecule->RemoveBond(Binder);
153
154 // check if removed from atoms
155 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
156 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
157
158 // check if removed from molecule
159 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
160};
161
162/** Unit Test of molecule::RemoveBonds()
163 *
164 */
165void ListOfBondsTest::RemovingBondsTest()
166{
167 bond *Binder = NULL;
168 molecule::iterator iter = TestMolecule->begin();
169 atom *atom1 = *iter;
170 iter++;
171 atom *atom2 = *iter;
172 iter++;
173 atom *atom3 = *iter;
174 CPPUNIT_ASSERT( atom1 != NULL );
175 CPPUNIT_ASSERT( atom2 != NULL );
176 CPPUNIT_ASSERT( atom3 != NULL );
177
178 // add bond
179 Binder = TestMolecule->AddBond(atom1, atom2, 1);
180 CPPUNIT_ASSERT( Binder != NULL );
181 Binder = TestMolecule->AddBond(atom1, atom3, 1);
182 CPPUNIT_ASSERT( Binder != NULL );
183 Binder = TestMolecule->AddBond(atom2, atom3, 1);
184 CPPUNIT_ASSERT( Binder != NULL );
185
186 // check that all are present
187 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
188 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
189 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
190
191 // remove bond
192 TestMolecule->RemoveBonds(atom1);
193
194 // check if removed from atoms
195 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
196 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
197 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
198
199 // check if removed from molecule
200 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
201 CPPUNIT_ASSERT_EQUAL( (unsigned int)1, TestMolecule->CountBonds() );
202};
203
204/** Unit Test of delete(bond *)
205 *
206 */
207void ListOfBondsTest::DeleteBondTest()
208{
209 bond *Binder = NULL;
210 molecule::iterator iter = TestMolecule->begin();
211 atom *atom1 = *iter;
212 iter++;
213 atom *atom2 = *iter;
214 CPPUNIT_ASSERT( atom1 != NULL );
215 CPPUNIT_ASSERT( atom2 != NULL );
216
217 // add bond
218 Binder = TestMolecule->AddBond(atom1, atom2, 1);
219 CPPUNIT_ASSERT( Binder != NULL );
220
221 // remove bond
222 delete(Binder);
223
224 // check if removed from atoms
225 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
226 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
227
228 // check if removed from molecule
229 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
230};
231
232/** Unit Test of molecule::RemoveAtom()
233 *
234 */
235void ListOfBondsTest::RemoveAtomTest()
236{
237 bond *Binder = NULL;
238 molecule::iterator iter = TestMolecule->begin();
239 atom *atom1 = *iter;
240 iter++;
241 atom *atom2 = *iter;
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 atom2
250 TestMolecule->RemoveAtom(atom2);
251
252 // check bond if removed from other atom
253 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
254
255 // check if removed from molecule
256 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
257};
258
259/** Unit Test of delete(atom *)
260 *
261 */
262void ListOfBondsTest::DeleteAtomTest()
263{
264 atom *atom1 = NULL;
265 atom *atom2 = NULL;
266 bond *Binder = NULL;
267 {
268 molecule::iterator iter = TestMolecule->begin();
269 atom1 = *iter;
270 iter++;
271 atom2 = *iter;
272 }
273 CPPUNIT_ASSERT( atom1 != NULL );
274 CPPUNIT_ASSERT( atom2 != NULL );
275
276 // add bond
277 Binder = TestMolecule->AddBond(atom1, atom2, 1);
278 CPPUNIT_ASSERT( Binder != NULL );
279
280 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom1->ListOfBonds.size() );
281 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
282
283 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
284
285 // remove atom2
286 World::getInstance().destroyAtom(atom2);
287
288 // check bond if removed from other atom
289 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
290
291 // check if removed from molecule
292 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
293};
Note: See TracBrowser for help on using the repository browser.