source: molecuilder/src/unittests/bondgraphunittest.cpp@ 90c4460

Last change on this file since 90c4460 was 075729, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'Analysis_PairCorrelation' into StructureRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/World.cpp
molecuilder/src/World.hpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/log.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/periodentafel.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/gslvectorunittest.cpp
molecuilder/src/unittests/logunittest.cpp
molecuilder/src/unittests/tesselation_boundarytriangleunittest.hpp
molecuilder/src/vector.cpp
molecuilder/tests/Tesselations/defs.in

Conflicts have been many and too numerous to listen here, just the few general cases

  • new molecule() replaced by World::getInstance().createMolecule()
  • new atom() replaced by World::getInstance().createAtom() where appropriate.
  • Some DoLog()s added interfered with changes to the message produced by Log() << Verbose(.) << ...
  • DoLog() has been erroneously added to TestRunner.cpp as well, there cout is appropriate
  • ...

Additionally, there was a bug in atom::clone(), sort was set to atom::nr of the atom to clone not of the clone itself. This caused a failure of the fragmentation.

This merge has been fully checked from a clean build directory with subsequent configure,make all install and make check.
It configures, compiles and runs all test cases and the test suite without errors.

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

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * bondgraphunittest.cpp
3 *
4 * Created on: Oct 29, 2009
5 * Author: heber
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 <iostream>
15#include <stdio.h>
16#include <cstring>
17
18#include "World.hpp"
19#include "atom.hpp"
20#include "bond.hpp"
21#include "bondgraph.hpp"
22#include "element.hpp"
23#include "log.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
26#include "bondgraphunittest.hpp"
27#include "World.hpp"
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( BondGraphTest );
37
38
39void BondGraphTest::setUp()
40{
41 atom *Walker = NULL;
42
43 // init private all pointers to zero
44 TestMolecule = NULL;
45 hydrogen = NULL;
46 tafel = NULL;
47
48 // construct element
49 hydrogen = new element;
50 hydrogen->Z = 1;
51 hydrogen->CovalentRadius = 0.23;
52 hydrogen->VanDerWaalsRadius = 1.09;
53 strcpy(hydrogen->name, "hydrogen");
54 strcpy(hydrogen->symbol, "H");
55 carbon = new element;
56 carbon->Z = 2;
57 carbon->CovalentRadius = 0.68;
58 carbon->VanDerWaalsRadius = 1.7;
59 strcpy(carbon->name, "carbon");
60 strcpy(carbon->symbol, "C");
61
62
63 // construct periodentafel
64 tafel = World::getInstance().getPeriode();
65 tafel->AddElement(hydrogen);
66 tafel->AddElement(carbon);
67
68 // construct molecule (tetraeder of hydrogens)
69 TestMolecule = World::getInstance().createMolecule();
70 Walker = World::getInstance().createAtom();
71 Walker->type = carbon;
72 Walker->node->Init(1., 0., 1. );
73 TestMolecule->AddAtom(Walker);
74 Walker = World::getInstance().createAtom();
75 Walker->type = carbon;
76 Walker->node->Init(0., 1., 1. );
77 TestMolecule->AddAtom(Walker);
78 Walker = World::getInstance().createAtom();
79 Walker->type = carbon;
80 Walker->node->Init(1., 1., 0. );
81 TestMolecule->AddAtom(Walker);
82 Walker = World::getInstance().createAtom();
83 Walker->type = carbon;
84 Walker->node->Init(0., 0., 0. );
85 TestMolecule->AddAtom(Walker);
86
87 // check that TestMolecule was correctly constructed
88 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
89
90 // create a small file with table
91 dummyname = new string("dummy.dat");
92 filename = new string("test.dat");
93 ofstream test(filename->c_str());
94 test << ".\tH\tC\n";
95 test << "H\t1.\t1.2\n";
96 test << "C\t1.2\t1.5\n";
97 test.close();
98 BG = new BondGraph(true);
99};
100
101
102void BondGraphTest::tearDown()
103{
104 // remove the file
105 remove(filename->c_str());
106 delete(filename);
107 delete(dummyname);
108 delete(BG);
109
110 // remove molecule
111 World::getInstance().destroyMolecule(TestMolecule);
112 // note that all the atoms, molecules, the tafel and the elements
113 // are all cleaned when the world is destroyed
114 World::purgeInstance();
115 MemoryUsageObserver::purgeInstance();
116 logger::purgeInstance();
117};
118
119/** UnitTest for BondGraphTest::LoadBondLengthTable().
120 */
121void BondGraphTest::LoadTableTest()
122{
123 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
124 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
125 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
126 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
127};
128
129/** UnitTest for BondGraphTest::ConstructBondGraph().
130 */
131void BondGraphTest::ConstructGraphFromTableTest()
132{
133 atom *Walker = TestMolecule->start->next;
134 atom *Runner = TestMolecule->end->previous;
135 CPPUNIT_ASSERT( TestMolecule->end != Walker );
136 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
137 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
138 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
139};
140
141/** UnitTest for BondGraphTest::ConstructBondGraph().
142 */
143void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
144{
145 atom *Walker = TestMolecule->start->next;
146 atom *Runner = TestMolecule->end->previous;
147 CPPUNIT_ASSERT( TestMolecule->end != Walker );
148 CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
149 CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
150 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
151};
152
Note: See TracBrowser for help on using the repository browser.