source: src/unittests/listofbondsunittest.cpp@ 1024cb

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

Merge commit 'jupiter/MoleculeStartEndSwitch' into CommandLineActionMapping

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

Integration of MoleculeStartEndSwitch had the following consequences:

  • no more AtomCount -> getAtomCount()
  • no more start/end -> begin(), end() and iterator
  • no more decent ordering in atomic ids (hence, Simple_configuration/8 and Domain/5, Domain/6 now check by comparing sorted xyz, not confs)

There is still a huge problem with bonds. One test runs into an endless loop.

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

  • Property mode set to 100644
File size: 7.3 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->getAtomCount(), 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 logger::purgeInstance();
81};
82
83/** Tests whether setup worked correctly.
84 *
85 */
86void ListOfBondsTest::SetupTest()
87{
88 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
89 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
90};
91
92/** Unit Test of molecule::AddBond()
93 *
94 */
95void ListOfBondsTest::AddingBondTest()
96{
97 bond *Binder = NULL;
98 molecule::iterator iter = TestMolecule->begin();
99 atom *atom1 = *iter;
100 iter++;
101 atom *atom2 = *iter;
102 CPPUNIT_ASSERT( atom1 != NULL );
103 CPPUNIT_ASSERT( atom2 != NULL );
104
105 // add bond
106 Binder = TestMolecule->AddBond(atom1, atom2, 1);
107 CPPUNIT_ASSERT( Binder != NULL );
108 bond *TestBond = TestMolecule->first->next;
109 CPPUNIT_ASSERT_EQUAL ( TestBond, Binder );
110
111 // check that bond contains the two atoms
112 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
113 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
114
115 // check that bond is present in both atoms
116 bond *TestBond1 = *(atom1->ListOfBonds.begin());
117 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
118 bond *TestBond2 = *(atom2->ListOfBonds.begin());
119 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
120};
121
122/** Unit Test of molecule::RemoveBond()
123 *
124 */
125void ListOfBondsTest::RemovingBondTest()
126{
127 bond *Binder = NULL;
128 molecule::iterator iter = TestMolecule->begin();
129 atom *atom1 = *iter;
130 iter++;
131 atom *atom2 = *iter;
132 CPPUNIT_ASSERT( atom1 != NULL );
133 CPPUNIT_ASSERT( atom2 != NULL );
134
135 // add bond
136 Binder = TestMolecule->AddBond(atom1, atom2, 1);
137 CPPUNIT_ASSERT( Binder != NULL );
138
139 // remove bond
140 TestMolecule->RemoveBond(Binder);
141
142 // check if removed from atoms
143 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
144 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
145
146 // check if removed from molecule
147 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
148};
149
150/** Unit Test of molecule::RemoveBonds()
151 *
152 */
153void ListOfBondsTest::RemovingBondsTest()
154{
155 bond *Binder = NULL;
156 molecule::iterator iter = TestMolecule->begin();
157 atom *atom1 = *iter;
158 iter++;
159 atom *atom2 = *iter;
160 iter++;
161 atom *atom3 = *iter;
162 CPPUNIT_ASSERT( atom1 != NULL );
163 CPPUNIT_ASSERT( atom2 != NULL );
164 CPPUNIT_ASSERT( atom3 != NULL );
165
166 // add bond
167 Binder = TestMolecule->AddBond(atom1, atom2, 1);
168 CPPUNIT_ASSERT( Binder != NULL );
169 Binder = TestMolecule->AddBond(atom1, atom3, 1);
170 CPPUNIT_ASSERT( Binder != NULL );
171 Binder = TestMolecule->AddBond(atom2, atom3, 1);
172 CPPUNIT_ASSERT( Binder != NULL );
173
174 // check that all are present
175 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom1->ListOfBonds.size() );
176 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom2->ListOfBonds.size() );
177 CPPUNIT_ASSERT_EQUAL( (size_t) 2, atom3->ListOfBonds.size() );
178
179 // remove bond
180 TestMolecule->RemoveBonds(atom1);
181
182 // check if removed from atoms
183 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
184 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom2->ListOfBonds.size() );
185 CPPUNIT_ASSERT_EQUAL( (size_t) 1, atom3->ListOfBonds.size() );
186
187 // check if removed from molecule
188 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, Binder );
189 CPPUNIT_ASSERT_EQUAL( Binder->next, TestMolecule->last );
190};
191
192/** Unit Test of delete(bond *)
193 *
194 */
195void ListOfBondsTest::DeleteBondTest()
196{
197 bond *Binder = NULL;
198 molecule::iterator iter = TestMolecule->begin();
199 atom *atom1 = *iter;
200 iter++;
201 atom *atom2 = *iter;
202 CPPUNIT_ASSERT( atom1 != NULL );
203 CPPUNIT_ASSERT( atom2 != NULL );
204
205 // add bond
206 Binder = TestMolecule->AddBond(atom1, atom2, 1);
207 CPPUNIT_ASSERT( Binder != NULL );
208
209 // remove bond
210 delete(Binder);
211
212 // check if removed from atoms
213 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
214 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom2->ListOfBonds.size() );
215
216 // check if removed from molecule
217 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
218};
219
220/** Unit Test of molecule::RemoveAtom()
221 *
222 */
223void ListOfBondsTest::RemoveAtomTest()
224{
225 bond *Binder = NULL;
226 molecule::iterator iter = TestMolecule->begin();
227 atom *atom1 = *iter;
228 iter++;
229 atom *atom2 = *iter;
230 CPPUNIT_ASSERT( atom1 != NULL );
231 CPPUNIT_ASSERT( atom2 != NULL );
232
233 // add bond
234 Binder = TestMolecule->AddBond(atom1, atom2, 1);
235 CPPUNIT_ASSERT( Binder != NULL );
236
237 // remove atom2
238 TestMolecule->RemoveAtom(atom2);
239
240 // check bond if removed from other atom
241 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
242
243 // check if removed from molecule
244 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
245};
246
247/** Unit Test of delete(atom *)
248 *
249 */
250void ListOfBondsTest::DeleteAtomTest()
251{
252 bond *Binder = NULL;
253 molecule::iterator iter = TestMolecule->begin();
254 atom *atom1 = *iter;
255 iter++;
256 atom *atom2 = *iter;
257 CPPUNIT_ASSERT( atom1 != NULL );
258 CPPUNIT_ASSERT( atom2 != NULL );
259
260 // add bond
261 Binder = TestMolecule->AddBond(atom1, atom2, 1);
262 CPPUNIT_ASSERT( Binder != NULL );
263
264 // remove atom2
265 World::getInstance().destroyAtom(atom2);
266
267 // check bond if removed from other atom
268 CPPUNIT_ASSERT_EQUAL( (size_t) 0, atom1->ListOfBonds.size() );
269
270 // check if removed from molecule
271 CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
272};
Note: See TracBrowser for help on using the repository browser.