source: src/unittests/listofbondsunittest.cpp@ cf1a07

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 cf1a07 was cbc5fb, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the world solely responsible for creating and erasing molecules.

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * listofbondsunittest.cpp
3 *
4 * Created on: 18 Oct 2009
5 * Author: user
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <cstring>
15
16#include "listofbondsunittest.hpp"
17
18#include "World.hpp"
19#include "atom.hpp"
20#include "bond.hpp"
21#include "element.hpp"
22#include "molecule.hpp"
23#include "periodentafel.hpp"
24
25/********************************************** Test classes **************************************/
26
27// Registers the fixture into the 'registry'
28CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
29
30
31void ListOfBondsTest::setUp()
32{
33 atom *Walker = NULL;
34
35 // init private all pointers to zero
36 TestMolecule = NULL;
37 hydrogen = NULL;
38 tafel = NULL;
39
40 // construct element
41 hydrogen = new element;
42 hydrogen->Z = 1;
43 strcpy(hydrogen->name, "hydrogen");
44 strcpy(hydrogen->symbol, "H");
45
46
47 // construct periodentafel
48 tafel = World::get()->getPeriode();
49 tafel->AddElement(hydrogen);
50
51 // construct molecule (tetraeder of hydrogens)
52 TestMolecule = World::get()->createMolecule();
53 Walker = World::get()->createAtom();
54 Walker->type = hydrogen;
55 Walker->node->Init(1., 0., 1. );
56 TestMolecule->AddAtom(Walker);
57 Walker = World::get()->createAtom();
58 Walker->type = hydrogen;
59 Walker->node->Init(0., 1., 1. );
60 TestMolecule->AddAtom(Walker);
61 Walker = World::get()->createAtom();
62 Walker->type = hydrogen;
63 Walker->node->Init(1., 1., 0. );
64 TestMolecule->AddAtom(Walker);
65 Walker = World::get()->createAtom();
66 Walker->type = hydrogen;
67 Walker->node->Init(0., 0., 0. );
68 TestMolecule->AddAtom(Walker);
69
70 // check that TestMolecule was correctly constructed
71 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
72
73};
74
75
76void ListOfBondsTest::tearDown()
77{
78 // remove
79 World::get()->destroyMolecule(TestMolecule);
80 // note that all the atoms are cleaned by TestMolecule
81 World::destroy();
82};
83
84/** Unit Test of molecule::AddBond()
85 *
86 */
87void ListOfBondsTest::AddingBondTest()
88{
89 bond *Binder = NULL;
90 atom *atom1 = TestMolecule->start->next;
91 atom *atom2 = atom1->next;
92 CPPUNIT_ASSERT( atom1 != NULL );
93 CPPUNIT_ASSERT( atom2 != NULL );
94
95 // add bond
96 Binder = TestMolecule->AddBond(atom1, atom2, 1);
97 CPPUNIT_ASSERT( Binder != NULL );
98 bond *TestBond = TestMolecule->first->next;
99 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
100
101 // check that bond contains the two atoms
102 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
103 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
104
105 // check that bond is present in both atoms
106 bond *TestBond1 = *(atom1->ListOfBonds.begin());
107 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
108 bond *TestBond2 = *(atom2->ListOfBonds.begin());
109 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
110};
111
112/** Unit Test of molecule::RemoveBond()
113 *
114 */
115void ListOfBondsTest::RemovingBondTest()
116{
117 bond *Binder = NULL;
118 atom *atom1 = TestMolecule->start->next;
119 atom *atom2 = atom1->next;
120 CPPUNIT_ASSERT( atom1 != NULL );
121 CPPUNIT_ASSERT( atom2 != NULL );
122
123 // add bond
124 Binder = TestMolecule->AddBond(atom1, atom2, 1);
125 CPPUNIT_ASSERT( Binder != NULL );
126
127 // remove bond
128 TestMolecule->RemoveBond(Binder);
129
130 // check if removed from atoms
131 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
132 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
133
134 // check if removed from molecule
135 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
136};
137
138/** Unit Test of molecule::RemoveBonds()
139 *
140 */
141void ListOfBondsTest::RemovingBondsTest()
142{
143 bond *Binder = NULL;
144 atom *atom1 = TestMolecule->start->next;
145 atom *atom2 = atom1->next;
146 atom *atom3 = atom2->next;
147 CPPUNIT_ASSERT( atom1 != NULL );
148 CPPUNIT_ASSERT( atom2 != NULL );
149 CPPUNIT_ASSERT( atom3 != NULL );
150
151 // add bond
152 Binder = TestMolecule->AddBond(atom1, atom2, 1);
153 CPPUNIT_ASSERT( Binder != NULL );
154 Binder = TestMolecule->AddBond(atom1, atom3, 1);
155 CPPUNIT_ASSERT( Binder != NULL );
156 Binder = TestMolecule->AddBond(atom2, atom3, 1);
157 CPPUNIT_ASSERT( Binder != NULL );
158
159 // check that all are present
160 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
161 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
162 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
163
164 // remove bond
165 TestMolecule->RemoveBonds(atom1);
166
167 // check if removed from atoms
168 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
169 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
170 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
171
172 // check if removed from molecule
173 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
174 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
175};
176
177/** Unit Test of delete(bond *)
178 *
179 */
180void ListOfBondsTest::DeleteBondTest()
181{
182 bond *Binder = NULL;
183 atom *atom1 = TestMolecule->start->next;
184 atom *atom2 = atom1->next;
185 CPPUNIT_ASSERT( atom1 != NULL );
186 CPPUNIT_ASSERT( atom2 != NULL );
187
188 // add bond
189 Binder = TestMolecule->AddBond(atom1, atom2, 1);
190 CPPUNIT_ASSERT( Binder != NULL );
191
192 // remove bond
193 delete(Binder);
194
195 // check if removed from atoms
196 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
197 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
198
199 // check if removed from molecule
200 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
201};
202
203/** Unit Test of molecule::RemoveAtom()
204 *
205 */
206void ListOfBondsTest::RemoveAtomTest()
207{
208 bond *Binder = NULL;
209 atom *atom1 = TestMolecule->start->next;
210 atom *atom2 = atom1->next;
211 CPPUNIT_ASSERT( atom1 != NULL );
212 CPPUNIT_ASSERT( atom2 != NULL );
213
214 // add bond
215 Binder = TestMolecule->AddBond(atom1, atom2, 1);
216 CPPUNIT_ASSERT( Binder != NULL );
217
218 // remove atom2
219 TestMolecule->RemoveAtom(atom2);
220
221 // check bond if removed from other atom
222 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
223
224 // check if removed from molecule
225 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
226};
227
228/** Unit Test of delete(atom *)
229 *
230 */
231void ListOfBondsTest::DeleteAtomTest()
232{
233 bond *Binder = NULL;
234 atom *atom1 = TestMolecule->start->next;
235 atom *atom2 = atom1->next;
236 CPPUNIT_ASSERT( atom1 != NULL );
237 CPPUNIT_ASSERT( atom2 != NULL );
238
239 // add bond
240 Binder = TestMolecule->AddBond(atom1, atom2, 1);
241 CPPUNIT_ASSERT( Binder != NULL );
242
243 // remove atom2
244 World::get()->destroyAtom(atom2);
245
246 // check bond if removed from other atom
247 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
248
249 // check if removed from molecule
250 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
251};
252
253/********************************************** Main routine **************************************/
254
255int main(int argc, char **argv)
256{
257 // Get the top level suite from the registry
258 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
259
260 // Adds the test to the list of test to run
261 CppUnit::TextUi::TestRunner runner;
262 runner.addTest( suite );
263
264 // Change the default outputter to a compiler error format outputter
265 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
266 std::cerr ) );
267 // Run the tests.
268 bool wasSucessful = runner.run();
269
270 // Return error code 1 if the one of test failed.
271 return wasSucessful ? 0 : 1;
272};
Note: See TracBrowser for help on using the repository browser.