source: src/unittests/listofbondsunittest.cpp@ 46d958

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

Made the world solely responsible for creating and destroying atoms.

  • 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 = new periodentafel;
49 tafel->AddElement(hydrogen);
50
51 // construct molecule (tetraeder of hydrogens)
52 TestMolecule = new molecule(tafel);
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 delete(TestMolecule);
80 // note that all the atoms are cleaned by TestMolecule
81 delete(tafel);
82 // note that element is cleaned by periodentafel
83};
84
85/** Unit Test of molecule::AddBond()
86 *
87 */
88void ListOfBondsTest::AddingBondTest()
89{
90 bond *Binder = NULL;
91 atom *atom1 = TestMolecule->start->next;
92 atom *atom2 = atom1->next;
93 CPPUNIT_ASSERT( atom1 != NULL );
94 CPPUNIT_ASSERT( atom2 != NULL );
95
96 // add bond
97 Binder = TestMolecule->AddBond(atom1, atom2, 1);
98 CPPUNIT_ASSERT( Binder != NULL );
99 bond *TestBond = TestMolecule->first->next;
100 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
101
102 // check that bond contains the two atoms
103 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
104 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
105
106 // check that bond is present in both atoms
107 bond *TestBond1 = *(atom1->ListOfBonds.begin());
108 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
109 bond *TestBond2 = *(atom2->ListOfBonds.begin());
110 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
111};
112
113/** Unit Test of molecule::RemoveBond()
114 *
115 */
116void ListOfBondsTest::RemovingBondTest()
117{
118 bond *Binder = NULL;
119 atom *atom1 = TestMolecule->start->next;
120 atom *atom2 = atom1->next;
121 CPPUNIT_ASSERT( atom1 != NULL );
122 CPPUNIT_ASSERT( atom2 != NULL );
123
124 // add bond
125 Binder = TestMolecule->AddBond(atom1, atom2, 1);
126 CPPUNIT_ASSERT( Binder != NULL );
127
128 // remove bond
129 TestMolecule->RemoveBond(Binder);
130
131 // check if removed from atoms
132 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
133 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
134
135 // check if removed from molecule
136 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
137};
138
139/** Unit Test of molecule::RemoveBonds()
140 *
141 */
142void ListOfBondsTest::RemovingBondsTest()
143{
144 bond *Binder = NULL;
145 atom *atom1 = TestMolecule->start->next;
146 atom *atom2 = atom1->next;
147 atom *atom3 = atom2->next;
148 CPPUNIT_ASSERT( atom1 != NULL );
149 CPPUNIT_ASSERT( atom2 != NULL );
150 CPPUNIT_ASSERT( atom3 != NULL );
151
152 // add bond
153 Binder = TestMolecule->AddBond(atom1, atom2, 1);
154 CPPUNIT_ASSERT( Binder != NULL );
155 Binder = TestMolecule->AddBond(atom1, atom3, 1);
156 CPPUNIT_ASSERT( Binder != NULL );
157 Binder = TestMolecule->AddBond(atom2, atom3, 1);
158 CPPUNIT_ASSERT( Binder != NULL );
159
160 // check that all are present
161 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
162 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
163 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
164
165 // remove bond
166 TestMolecule->RemoveBonds(atom1);
167
168 // check if removed from atoms
169 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
170 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
171 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
172
173 // check if removed from molecule
174 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
175 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
176};
177
178/** Unit Test of delete(bond *)
179 *
180 */
181void ListOfBondsTest::DeleteBondTest()
182{
183 bond *Binder = NULL;
184 atom *atom1 = TestMolecule->start->next;
185 atom *atom2 = atom1->next;
186 CPPUNIT_ASSERT( atom1 != NULL );
187 CPPUNIT_ASSERT( atom2 != NULL );
188
189 // add bond
190 Binder = TestMolecule->AddBond(atom1, atom2, 1);
191 CPPUNIT_ASSERT( Binder != NULL );
192
193 // remove bond
194 delete(Binder);
195
196 // check if removed from atoms
197 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
198 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
199
200 // check if removed from molecule
201 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
202};
203
204/** Unit Test of molecule::RemoveAtom()
205 *
206 */
207void ListOfBondsTest::RemoveAtomTest()
208{
209 bond *Binder = NULL;
210 atom *atom1 = TestMolecule->start->next;
211 atom *atom2 = atom1->next;
212 CPPUNIT_ASSERT( atom1 != NULL );
213 CPPUNIT_ASSERT( atom2 != NULL );
214
215 // add bond
216 Binder = TestMolecule->AddBond(atom1, atom2, 1);
217 CPPUNIT_ASSERT( Binder != NULL );
218
219 // remove atom2
220 TestMolecule->RemoveAtom(atom2);
221
222 // check bond if removed from other atom
223 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
224
225 // check if removed from molecule
226 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
227};
228
229/** Unit Test of delete(atom *)
230 *
231 */
232void ListOfBondsTest::DeleteAtomTest()
233{
234 bond *Binder = NULL;
235 atom *atom1 = TestMolecule->start->next;
236 atom *atom2 = atom1->next;
237 CPPUNIT_ASSERT( atom1 != NULL );
238 CPPUNIT_ASSERT( atom2 != NULL );
239
240 // add bond
241 Binder = TestMolecule->AddBond(atom1, atom2, 1);
242 CPPUNIT_ASSERT( Binder != NULL );
243
244 // remove atom2
245 World::get()->destroyAtom(atom2);
246
247 // check bond if removed from other atom
248 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
249
250 // check if removed from molecule
251 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
252};
253
254/********************************************** Main routine **************************************/
255
256int main(int argc, char **argv)
257{
258 // Get the top level suite from the registry
259 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
260
261 // Adds the test to the list of test to run
262 CppUnit::TextUi::TestRunner runner;
263 runner.addTest( suite );
264
265 // Change the default outputter to a compiler error format outputter
266 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
267 std::cerr ) );
268 // Run the tests.
269 bool wasSucessful = runner.run();
270
271 // Return error code 1 if the one of test failed.
272 return wasSucessful ? 0 : 1;
273};
Note: See TracBrowser for help on using the repository browser.