source: src/unittests/bondgraphunittest.cpp@ 13e3c3

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 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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