source: src/unittests/listofbondsunittest.cpp@ 5e5283

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

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 6.5 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 "atom.hpp"
19#include "bond.hpp"
20#include "element.hpp"
21#include "molecule.hpp"
22#include "periodentafel.hpp"
23
24#ifdef HAVE_TESTRUNNER
25#include "UnitTestMain.hpp"
26#endif /*HAVE_TESTRUNNER*/
27
28/********************************************** Test classes **************************************/
29
30// Registers the fixture into the 'registry'
31CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
32
33
34void ListOfBondsTest::setUp()
35{
36 atom *Walker = NULL;
37
38 // init private all pointers to zero
39 TestMolecule = NULL;
40 hydrogen = NULL;
41 tafel = NULL;
42
43 // construct element
44 hydrogen = new element;
45 hydrogen->Z = 1;
46 strcpy(hydrogen->name, "hydrogen");
47 strcpy(hydrogen->symbol, "H");
48
49
50 // construct periodentafel
51 tafel = new periodentafel;
52 tafel->AddElement(hydrogen);
53
54 // construct molecule (tetraeder of hydrogens)
55 TestMolecule = new molecule(tafel);
56 Walker = new atom();
57 Walker->type = hydrogen;
58 Walker->node->Init(1., 0., 1. );
59 TestMolecule->AddAtom(Walker);
60 Walker = new atom();
61 Walker->type = hydrogen;
62 Walker->node->Init(0., 1., 1. );
63 TestMolecule->AddAtom(Walker);
64 Walker = new atom();
65 Walker->type = hydrogen;
66 Walker->node->Init(1., 1., 0. );
67 TestMolecule->AddAtom(Walker);
68 Walker = new atom();
69 Walker->type = hydrogen;
70 Walker->node->Init(0., 0., 0. );
71 TestMolecule->AddAtom(Walker);
72
73 // check that TestMolecule was correctly constructed
74 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
75
76};
77
78
79void ListOfBondsTest::tearDown()
80{
81 // remove
82 delete(TestMolecule);
83 // note that all the atoms are cleaned by TestMolecule
84 delete(tafel);
85 // note that element is cleaned by periodentafel
86};
87
88/** Unit Test of molecule::AddBond()
89 *
90 */
91void ListOfBondsTest::AddingBondTest()
92{
93 bond *Binder = NULL;
94 atom *atom1 = TestMolecule->start->next;
95 atom *atom2 = atom1->next;
96 CPPUNIT_ASSERT( atom1 != NULL );
97 CPPUNIT_ASSERT( atom2 != NULL );
98
99 // add bond
100 Binder = TestMolecule->AddBond(atom1, atom2, 1);
101 CPPUNIT_ASSERT( Binder != NULL );
102 bond *TestBond = TestMolecule->first->next;
103 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
104
105 // check that bond contains the two atoms
106 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
107 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
108
109 // check that bond is present in both atoms
110 bond *TestBond1 = *(atom1->ListOfBonds.begin());
111 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
112 bond *TestBond2 = *(atom2->ListOfBonds.begin());
113 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
114};
115
116/** Unit Test of molecule::RemoveBond()
117 *
118 */
119void ListOfBondsTest::RemovingBondTest()
120{
121 bond *Binder = NULL;
122 atom *atom1 = TestMolecule->start->next;
123 atom *atom2 = atom1->next;
124 CPPUNIT_ASSERT( atom1 != NULL );
125 CPPUNIT_ASSERT( atom2 != NULL );
126
127 // add bond
128 Binder = TestMolecule->AddBond(atom1, atom2, 1);
129 CPPUNIT_ASSERT( Binder != NULL );
130
131 // remove bond
132 TestMolecule->RemoveBond(Binder);
133
134 // check if removed from atoms
135 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
136 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
137
138 // check if removed from molecule
139 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
140};
141
142/** Unit Test of molecule::RemoveBonds()
143 *
144 */
145void ListOfBondsTest::RemovingBondsTest()
146{
147 bond *Binder = NULL;
148 atom *atom1 = TestMolecule->start->next;
149 atom *atom2 = atom1->next;
150 atom *atom3 = atom2->next;
151 CPPUNIT_ASSERT( atom1 != NULL );
152 CPPUNIT_ASSERT( atom2 != NULL );
153 CPPUNIT_ASSERT( atom3 != NULL );
154
155 // add bond
156 Binder = TestMolecule->AddBond(atom1, atom2, 1);
157 CPPUNIT_ASSERT( Binder != NULL );
158 Binder = TestMolecule->AddBond(atom1, atom3, 1);
159 CPPUNIT_ASSERT( Binder != NULL );
160 Binder = TestMolecule->AddBond(atom2, atom3, 1);
161 CPPUNIT_ASSERT( Binder != NULL );
162
163 // check that all are present
164 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
165 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
166 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
167
168 // remove bond
169 TestMolecule->RemoveBonds(atom1);
170
171 // check if removed from atoms
172 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
173 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
174 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
175
176 // check if removed from molecule
177 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
178 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
179};
180
181/** Unit Test of delete(bond *)
182 *
183 */
184void ListOfBondsTest::DeleteBondTest()
185{
186 bond *Binder = NULL;
187 atom *atom1 = TestMolecule->start->next;
188 atom *atom2 = atom1->next;
189 CPPUNIT_ASSERT( atom1 != NULL );
190 CPPUNIT_ASSERT( atom2 != NULL );
191
192 // add bond
193 Binder = TestMolecule->AddBond(atom1, atom2, 1);
194 CPPUNIT_ASSERT( Binder != NULL );
195
196 // remove bond
197 delete(Binder);
198
199 // check if removed from atoms
200 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
201 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
202
203 // check if removed from molecule
204 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
205};
206
207/** Unit Test of molecule::RemoveAtom()
208 *
209 */
210void ListOfBondsTest::RemoveAtomTest()
211{
212 bond *Binder = NULL;
213 atom *atom1 = TestMolecule->start->next;
214 atom *atom2 = atom1->next;
215 CPPUNIT_ASSERT( atom1 != NULL );
216 CPPUNIT_ASSERT( atom2 != NULL );
217
218 // add bond
219 Binder = TestMolecule->AddBond(atom1, atom2, 1);
220 CPPUNIT_ASSERT( Binder != NULL );
221
222 // remove atom2
223 TestMolecule->RemoveAtom(atom2);
224
225 // check bond if removed from other atom
226 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
227
228 // check if removed from molecule
229 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
230};
231
232/** Unit Test of delete(atom *)
233 *
234 */
235void ListOfBondsTest::DeleteAtomTest()
236{
237 bond *Binder = NULL;
238 atom *atom1 = TestMolecule->start->next;
239 atom *atom2 = atom1->next;
240 CPPUNIT_ASSERT( atom1 != NULL );
241 CPPUNIT_ASSERT( atom2 != NULL );
242
243 // add bond
244 Binder = TestMolecule->AddBond(atom1, atom2, 1);
245 CPPUNIT_ASSERT( Binder != NULL );
246
247 // remove atom2
248 delete(atom2);
249
250 // check bond if removed from other atom
251 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
252
253 // check if removed from molecule
254 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
255};
Note: See TracBrowser for help on using the repository browser.