source: src/unittests/ListOfBondsUnitTest.cpp@ 8b58ac

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 8b58ac was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 12.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * ListOfBondsUnitTest.cpp
25 *
26 * Created on: 18 Oct 2009
27 * Author: user
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include <cstring>
42
43#include "CodePatterns/Log.hpp"
44#include "World.hpp"
45#include "Atom/atom.hpp"
46#include "Bond/bond.hpp"
47#include "Element/element.hpp"
48#include "molecule.hpp"
49#include "Element/periodentafel.hpp"
50#include "World.hpp"
51#include "WorldTime.hpp"
52
53#include "ListOfBondsUnitTest.hpp"
54
55#ifdef HAVE_TESTRUNNER
56#include "UnitTestMain.hpp"
57#endif /*HAVE_TESTRUNNER*/
58
59/********************************************** Test classes **************************************/
60
61// Registers the fixture into the 'registry'
62CPPUNIT_TEST_SUITE_REGISTRATION( ListOfBondsTest );
63
64
65void ListOfBondsTest::setUp()
66{
67 atom *Walker = NULL;
68
69 WorldTime::getInstance().setTime(0);
70
71 // construct element
72 hydrogen = World::getInstance().getPeriode()->FindElement(1);
73 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
74
75 // construct molecule (tetraeder of hydrogens)
76 TestMolecule = World::getInstance().createMolecule();
77 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
78 Walker = World::getInstance().createAtom();
79 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
80 Walker->setType(hydrogen);
81 Walker->setPosition(Vector(1., 0., 1. ));
82 TestMolecule->AddAtom(Walker);
83 Walker = World::getInstance().createAtom();
84 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
85 Walker->setType(hydrogen);
86 Walker->setPosition(Vector(0., 1., 1. ));
87 TestMolecule->AddAtom(Walker);
88 Walker = World::getInstance().createAtom();
89 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
90 Walker->setType(hydrogen);
91 Walker->setPosition(Vector(1., 1., 0. ));
92 TestMolecule->AddAtom(Walker);
93 Walker = World::getInstance().createAtom();
94 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
95 Walker->setType(hydrogen);
96 Walker->setPosition(Vector(0., 0., 0. ));
97 TestMolecule->AddAtom(Walker);
98
99 // check that TestMolecule was correctly constructed
100 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
101};
102
103
104void ListOfBondsTest::tearDown()
105{
106 // remove
107 World::getInstance().destroyMolecule(TestMolecule);
108 // note that all the atoms, molecules, the tafel and the elements
109 // are all cleaned when the world is destroyed
110 World::purgeInstance();
111 logger::purgeInstance();
112};
113
114/** Tests whether setup worked correctly.
115 *
116 */
117void ListOfBondsTest::SetupTest()
118{
119 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->empty() );
120 CPPUNIT_ASSERT_EQUAL( (size_t)4, TestMolecule->size() );
121};
122
123/** Unit Test of molecule::AddBond()
124 *
125 */
126void ListOfBondsTest::AddingBondTest()
127{
128 bond *Binder = NULL;
129 molecule::iterator iter = TestMolecule->begin();
130 atom *atom1 = *iter;
131 iter++;
132 atom *atom2 = *iter;
133 CPPUNIT_ASSERT( atom1 != NULL );
134 CPPUNIT_ASSERT( atom2 != NULL );
135
136 // add bond
137 Binder = TestMolecule->AddBond(atom1, atom2, 1);
138 CPPUNIT_ASSERT( Binder != NULL );
139 CPPUNIT_ASSERT_EQUAL ( true, TestMolecule->hasBondStructure() );
140
141 // check that bond contains the two atoms
142 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom1) );
143 CPPUNIT_ASSERT_EQUAL( true, Binder->Contains(atom2) );
144
145 // check that bond is present in both atoms
146 const BondList &bondlist1 = atom1->getListOfBonds();
147 BondList::const_iterator bonditer;
148 bonditer = bondlist1.begin();
149 bond *TestBond1 = *bonditer;
150 CPPUNIT_ASSERT_EQUAL( TestBond1, Binder );
151 const BondList &bondlist2 = atom2->getListOfBonds();
152 bonditer = bondlist2.begin();
153 bond *TestBond2 = *bonditer;
154 CPPUNIT_ASSERT_EQUAL( TestBond2, Binder );
155};
156
157/** Unit Test of molecule::RemoveBond()
158 *
159 */
160void ListOfBondsTest::RemovingBondTest()
161{
162 bond *Binder = NULL;
163 molecule::iterator iter = TestMolecule->begin();
164 atom *atom1 = *iter;
165 iter++;
166 atom *atom2 = *iter;
167 CPPUNIT_ASSERT( atom1 != NULL );
168 CPPUNIT_ASSERT( atom2 != NULL );
169
170 // add bond
171 Binder = TestMolecule->AddBond(atom1, atom2, 1);
172 CPPUNIT_ASSERT( Binder != NULL );
173
174 // remove bond
175 TestMolecule->RemoveBond(Binder);
176
177 // check if removed from atoms
178 {
179 const BondList& ListOfBonds = atom1->getListOfBonds();
180 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
181 }
182 {
183 const BondList& ListOfBonds = atom2->getListOfBonds();
184 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
185 }
186
187 // check if removed from molecule
188 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
189};
190
191/** Unit Test of molecule::RemoveBonds()
192 *
193 */
194void ListOfBondsTest::RemovingBondsTest()
195{
196 bond *Binder = NULL;
197 molecule::iterator iter = TestMolecule->begin();
198 atom *atom1 = *iter;
199 iter++;
200 atom *atom2 = *iter;
201 iter++;
202 atom *atom3 = *iter;
203 CPPUNIT_ASSERT( atom1 != NULL );
204 CPPUNIT_ASSERT( atom2 != NULL );
205 CPPUNIT_ASSERT( atom3 != NULL );
206
207 // add bond
208 Binder = TestMolecule->AddBond(atom1, atom2, 1);
209 CPPUNIT_ASSERT( Binder != NULL );
210 Binder = TestMolecule->AddBond(atom1, atom3, 1);
211 CPPUNIT_ASSERT( Binder != NULL );
212 Binder = TestMolecule->AddBond(atom2, atom3, 1);
213 CPPUNIT_ASSERT( Binder != NULL );
214
215 // check that all are present
216 {
217 const BondList& ListOfBonds = atom1->getListOfBonds();
218 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
219 }
220 {
221 const BondList& ListOfBonds = atom2->getListOfBonds();
222 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
223 }
224 {
225 const BondList& ListOfBonds = atom3->getListOfBonds();
226 CPPUNIT_ASSERT_EQUAL( (size_t) 2, ListOfBonds.size() );
227 }
228
229 // remove bond
230 TestMolecule->RemoveBonds(atom1);
231
232 // check if removed from atoms
233 {
234 const BondList& ListOfBonds = atom1->getListOfBonds();
235 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
236 }
237 {
238 const BondList& ListOfBonds = atom2->getListOfBonds();
239 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
240 }
241 {
242 const BondList& ListOfBonds = atom3->getListOfBonds();
243 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
244 }
245
246 // check if removed from molecule
247 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
248 CPPUNIT_ASSERT_EQUAL( (int)1, TestMolecule->getBondCount() );
249};
250
251/** Unit Test of delete(bond *)
252 *
253 */
254void ListOfBondsTest::DeleteBondTest()
255{
256 bond *Binder = NULL;
257 molecule::iterator iter = TestMolecule->begin();
258 atom *atom1 = *iter;
259 iter++;
260 atom *atom2 = *iter;
261 CPPUNIT_ASSERT( atom1 != NULL );
262 CPPUNIT_ASSERT( atom2 != NULL );
263
264 // add bond
265 Binder = TestMolecule->AddBond(atom1, atom2, 1);
266 CPPUNIT_ASSERT( Binder != NULL );
267
268 // remove bond
269 delete(Binder);
270
271 // check if removed from atoms
272 {
273 const BondList& ListOfBonds = atom1->getListOfBonds();
274 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
275 }
276 {
277 const BondList& ListOfBonds = atom2->getListOfBonds();
278 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
279 }
280
281 // check if removed from molecule
282 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
283};
284
285/** Unit Test of molecule::RemoveAtom()
286 *
287 */
288void ListOfBondsTest::RemoveAtomTest()
289{
290 bond *Binder = NULL;
291 molecule::iterator iter = TestMolecule->begin();
292 atom *atom1 = *iter;
293 iter++;
294 atom *atom2 = *iter;
295 CPPUNIT_ASSERT( atom1 != NULL );
296 CPPUNIT_ASSERT( atom2 != NULL );
297
298 // add bond
299 Binder = TestMolecule->AddBond(atom1, atom2, 1);
300 CPPUNIT_ASSERT( Binder != NULL );
301
302 // remove atom2
303 TestMolecule->RemoveAtom(atom2);
304
305 // check bond if removed from other atom
306 {
307 const BondList& ListOfBonds = atom1->getListOfBonds();
308 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
309 }
310
311 // check if removed from molecule
312 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
313};
314
315/** Unit Test of delete(atom *)
316 *
317 */
318void ListOfBondsTest::DeleteAtomTest()
319{
320 atom *atom1 = NULL;
321 atom *atom2 = NULL;
322 bond *Binder = NULL;
323 {
324 molecule::iterator iter = TestMolecule->begin();
325 atom1 = *iter;
326 iter++;
327 atom2 = *iter;
328 }
329 CPPUNIT_ASSERT( atom1 != NULL );
330 CPPUNIT_ASSERT( atom2 != NULL );
331
332 // add bond
333 Binder = TestMolecule->AddBond(atom1, atom2, 1);
334 CPPUNIT_ASSERT( Binder != NULL );
335
336 // access test via CurrentTime
337 {
338 const BondList& ListOfBonds = atom1->getListOfBonds();
339 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
340 }
341 {
342 const BondList& ListOfBonds = atom2->getListOfBonds();
343 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
344 }
345
346 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
347
348 // remove atom2
349 World::getInstance().destroyAtom(atom2);
350
351 // check bond if removed from other atom for all time steps
352 {
353 const BondList& ListOfBonds = atom1->getListOfBonds();
354 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
355 }
356
357 // check if removed from molecule
358 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
359};
360
361/** Unit test on ListOfBonds at multiple time steps.
362 *
363 */
364void ListOfBondsTest::MultipleTimeStepTest()
365{
366 atom *atom1 = NULL;
367 atom *atom2 = NULL;
368 bond *Binder = NULL;
369 {
370 molecule::iterator iter = TestMolecule->begin();
371 atom1 = *iter;
372 iter++;
373 atom2 = *iter;
374 }
375 CPPUNIT_ASSERT( atom1 != NULL );
376 CPPUNIT_ASSERT( atom2 != NULL );
377
378 // add bond
379 WorldTime::getInstance().setTime(0);
380 Binder = TestMolecule->AddBond(atom1, atom2, 1);
381 CPPUNIT_ASSERT( Binder != NULL );
382 WorldTime::getInstance().setTime(1);
383 Binder = TestMolecule->AddBond(atom1, atom2, 1);
384 CPPUNIT_ASSERT( Binder != NULL );
385
386 // access test via CurrentTime
387 { // time step 0
388 WorldTime::getInstance().setTime(0);
389 {
390 const BondList& ListOfBonds = atom1->getListOfBonds();
391 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
392 }
393 {
394 const BondList& ListOfBonds = atom2->getListOfBonds();
395 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
396 }
397 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
398 }
399 { // time step 1
400 WorldTime::getInstance().setTime(1);
401 {
402 const BondList& ListOfBonds = atom1->getListOfBonds();
403 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
404 }
405 {
406 const BondList& ListOfBonds = atom2->getListOfBonds();
407 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
408 }
409 CPPUNIT_ASSERT_EQUAL( true, TestMolecule->hasBondStructure() );
410 WorldTime::getInstance().setTime(0);
411 }
412
413 // access time step directly.
414 { // time step 0
415 {
416 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(0);
417 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
418 }
419 {
420 const BondList& ListOfBonds = atom2->getListOfBondsAtStep(0);
421 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
422 }
423 }
424 { // time step 1
425 {
426 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
427 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
428 }
429 {
430 const BondList& ListOfBonds = atom1->getListOfBondsAtStep(1);
431 CPPUNIT_ASSERT_EQUAL( (size_t) 1, ListOfBonds.size() );
432 }
433 }
434
435 // remove atom2
436 World::getInstance().destroyAtom(atom2);
437
438 // check bond if removed from other atom for all time steps
439 {
440 WorldTime::getInstance().setTime(0);
441 const BondList& ListOfBonds = atom1->getListOfBonds();
442 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
443 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
444 }
445 {
446 WorldTime::getInstance().setTime(1);
447 const BondList& ListOfBonds = atom1->getListOfBonds();
448 CPPUNIT_ASSERT_EQUAL( (size_t) 0, ListOfBonds.size() );
449 CPPUNIT_ASSERT_EQUAL( false, TestMolecule->hasBondStructure() );
450 WorldTime::getInstance().setTime(0);
451 }
452
453}
Note: See TracBrowser for help on using the repository browser.