source: src/unittests/listofbondsunittest.cpp@ 673c7f

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 673c7f was 4eb4fe, checked in by Frederik Heber <heber@…>, 15 years ago

"-e <db path>" not necessary anymore.

Removed necessity of specifying path to databases (this was one check of molecuilder/test/testsuite.at which cannot be fulfilled anymore with boost::program_options)
For this to work a great number of small changes have been necessary:

class periodentafel:

  • all .db files merged into const char * arrays in elements_db.cpp
  • periodentafel rewritten:
  • FindElement(), AskElement() and EnterElement return element * const instead of const element * (i.e. the contents of the pointer is const (the element) not the pointer itself which is very vexatious (i.e. FindElement() yields const element * which can subsequently not be used for RemoveElement(), ...)
  • parsedElems is not needed anymore. Instead we operate on map elements directly
  • new unittest periodentafelTest which is made friend of periodentafel to be able to access private loading functions directly

A number of unit tests had to be changed (all that create elements during setUp() which is now unnecessary)

Some of the analysis_bonds function's signatures were changed in the process:

Finally, the respective tests are removed from molecuilder/tests/testsuite.at.

  • Property mode set to 100644
File size: 6.9 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#include "World.hpp"
25
26#ifdef HAVE_TESTRUNNER
27#include "UnitTestMain.hpp"
28#endif /*HAVE_TESTRUNNER*/
29
30/********************************************** Test classes **************************************/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
34
35
36void ListOfBondsTest::setUp()
37{
38 atom *Walker = NULL;
39
40 // construct element
41 hydrogen = World::getInstance().getPeriode()->FindElement(1);
42 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
43
44 // construct molecule (tetraeder of hydrogens)
45 TestMolecule = World::getInstance().createMolecule();
46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
47 Walker = World::getInstance().createAtom();
48 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
49 Walker->type = hydrogen;
50 *Walker->node = Vector(1., 0., 1. );
51 TestMolecule->AddAtom(Walker);
52 Walker = World::getInstance().createAtom();
53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
54 Walker->type = hydrogen;
55 *Walker->node = Vector(0., 1., 1. );
56 TestMolecule->AddAtom(Walker);
57 Walker = World::getInstance().createAtom();
58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
59 Walker->type = hydrogen;
60 *Walker->node = Vector(1., 1., 0. );
61 TestMolecule->AddAtom(Walker);
62 Walker = World::getInstance().createAtom();
63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
64 Walker->type = hydrogen;
65 *Walker->node = Vector(0., 0., 0. );
66 TestMolecule->AddAtom(Walker);
67
68 // check that TestMolecule was correctly constructed
69 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
70};
71
72
73void ListOfBondsTest::tearDown()
74{
75 // remove
76 World::getInstance().destroyMolecule(TestMolecule);
77 // note that all the atoms, molecules, the tafel and the elements
78 // are all cleaned when the world is destroyed
79 World::purgeInstance();
80 MemoryUsageObserver::purgeInstance();
81 logger::purgeInstance();
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::getInstance().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};
Note: See TracBrowser for help on using the repository browser.