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

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 46ea3b was 266237, checked in by Frederik Heber <heber@…>, 15 years ago

Huge refactoring: molecule::ListOfBondsPerAtom and molecule::NumberOfBondsPerAtom removed, atom::ListOfBonds introduced. Unit Test for ListOfBonds manipulation introduced.

  • changes to builder.cpp: removed CreateListOfBondsPerAtom() calls, as the creation of the global arrays is not necessary anymore
  • changes to LinkedCell: LinkedCell::CheckBounds(int[NDIM]) does not admonish out of bonds as this is not desired for the local offset which may become out of bounds.
  • changes to lists.hpp templates: BUGFIX: unlink() now sets ->next and ->previous to NULL, cleanup() uses removedwithoutcheck()
  • new templates for molecule.hpp: SumPerAtom() allows for summation of the return value of atom:...() member fiunctions. This is needed e.g. for atom::CorrectBondDegree()

Signed-off-by: Frederik Heber <heber@…>

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