source: src/unittests/BondGraphUnitTest.cpp@ 1f91f4

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 1f91f4 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * BondGraphUnitTest.cpp
10 *
11 * Created on: Oct 29, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <iostream>
27#include <stdio.h>
28#include <cstring>
29
30#include "CodePatterns/Assert.hpp"
31
32#include "World.hpp"
33#include "atom.hpp"
34#include "bond.hpp"
35#include "bondgraph.hpp"
36#include "element.hpp"
37#include "CodePatterns/Log.hpp"
38#include "molecule.hpp"
39#include "periodentafel.hpp"
40#include "World.hpp"
41
42#include "BondGraphUnitTest.hpp"
43
44#ifdef HAVE_TESTRUNNER
45#include "UnitTestMain.hpp"
46#endif /*HAVE_TESTRUNNER*/
47
48/********************************************** Test classes **************************************/
49
50// Registers the fixture into the 'registry'
51CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
52
53
54void BondGraphTest::setUp()
55{
56 atom *Walker = NULL;
57
58 // construct element
59 hydrogen = World::getInstance().getPeriode()->FindElement(1);
60 carbon = World::getInstance().getPeriode()->FindElement(6);
61 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
62 CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
63
64 // construct molecule (tetraeder of hydrogens)
65 TestMolecule = World::getInstance().createMolecule();
66 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
67 Walker = World::getInstance().createAtom();
68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
69 Walker->setType(carbon);
70 Walker->setPosition(Vector(1., 0., 1. ));
71 TestMolecule->AddAtom(Walker);
72
73 Walker = World::getInstance().createAtom();
74 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
75 Walker->setType(carbon);
76 Walker->setPosition(Vector(0., 1., 1. ));
77 TestMolecule->AddAtom(Walker);
78
79 Walker = World::getInstance().createAtom();
80 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
81 Walker->setType(carbon);
82 Walker->setPosition(Vector(1., 1., 0. ));
83 TestMolecule->AddAtom(Walker);
84
85 Walker = World::getInstance().createAtom();
86 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
87 Walker->setType(carbon);
88 Walker->setPosition(Vector(0., 0., 0. ));
89 TestMolecule->AddAtom(Walker);
90
91 // check that TestMolecule was correctly constructed
92 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
93
94 // create a small file with table
95 dummyname = new string("dummy.dat");
96 CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
97 filename = new string("test.dat");
98 CPPUNIT_ASSERT(filename != NULL && "could not create string");
99 ofstream test(filename->c_str());
100 test << ".\tH\tHe\tLi\tBe\tB\tC\n";
101 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
102 test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
103 test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
104 test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
105 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
106 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
107 test.close();
108 BG = new BondGraph(true);
109 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
110};
111
112
113void BondGraphTest::tearDown()
114{
115 // remove the file
116 remove(filename->c_str());
117 delete(filename);
118 delete(dummyname);
119 delete(BG);
120
121 // remove molecule
122 World::getInstance().destroyMolecule(TestMolecule);
123 // note that all the atoms, molecules, the tafel and the elements
124 // are all cleaned when the world is destroyed
125 World::purgeInstance();
126 logger::purgeInstance();
127};
128
129/** Tests whether setup worked.
130 */
131void BondGraphTest::SetupTest()
132{
133 CPPUNIT_ASSERT_EQUAL (false, TestMolecule->empty());
134 CPPUNIT_ASSERT_EQUAL ((size_t)4, TestMolecule->size());
135};
136
137/** UnitTest for BondGraphTest::LoadBondLengthTable().
138 */
139void BondGraphTest::LoadTableTest()
140{
141 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
142 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
143 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
144 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
145};
146
147/** UnitTest for BondGraphTest::ConstructBondGraph().
148 */
149void BondGraphTest::ConstructGraphFromTableTest()
150{
151 molecule::iterator Walker = TestMolecule->begin();
152 molecule::iterator Runner = TestMolecule->begin();
153 Runner++;
154 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
155 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
156 CPPUNIT_ASSERT_EQUAL( true , (*Walker)->IsBondedTo((*Runner)) );
157};
158
159/** UnitTest for BondGraphTest::ConstructBondGraph().
160 */
161void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
162{
163
164 //atom *Walker = TestMolecule->start->next;
165 //atom *Runner = TestMolecule->end->previous;
166 //CPPUNIT_ASSERT( TestMolecule->end != Walker );
167 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
168 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
169
170 // this cannot be assured using dynamic IDs
171 //CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
172};
173
Note: See TracBrowser for help on using the repository browser.