source: molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ e7e088

Last change on this file since e7e088 was 7bfc19, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Made the world solely responsible for creating and destroying atoms.

  • Property mode set to 100644
File size: 7.0 KB
RevLine 
[57cfb7]1/*
2 * AnalysisCorrelationToSurfaceUnitTest.cpp
3 *
4 * Created on: Oct 13, 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
[e6fe8a]14#include <cstring>
15
[57cfb7]16#include "analysis_correlation.hpp"
17#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
18
[7bfc19]19#include "World.hpp"
[57cfb7]20#include "atom.hpp"
21#include "boundary.hpp"
22#include "element.hpp"
23#include "molecule.hpp"
24#include "linkedcell.hpp"
25#include "periodentafel.hpp"
26#include "tesselation.hpp"
27
28/********************************************** Test classes **************************************/
29
30// Registers the fixture into the 'registry'
31CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
32
33void AnalysisCorrelationToSurfaceUnitTest::setUp()
34{
35 atom *Walker = NULL;
36
37 // init private all pointers to zero
[e1900f]38 TestList = NULL;
[57cfb7]39 TestMolecule = NULL;
40 hydrogen = NULL;
41 tafel = NULL;
42 surfacemap = NULL;
43 binmap = NULL;
44 Surface = NULL;
45 LC = NULL;
46
47 // construct element
48 hydrogen = new element;
49 hydrogen->Z = 1;
50 strcpy(hydrogen->name, "hydrogen");
[13ecff]51 strcpy(hydrogen->symbol, "H");
52 carbon = new element;
53 carbon->Z = 6;
54 strcpy(carbon->name, "carbon");
55 strcpy(carbon->symbol, "C");
[57cfb7]56
57 // construct periodentafel
58 tafel = new periodentafel;
59 tafel->AddElement(hydrogen);
[13ecff]60 tafel->AddElement(carbon);
[57cfb7]61
[13ecff]62 // construct molecule (tetraeder of hydrogens) base
[57cfb7]63 TestMolecule = new molecule(tafel);
[7bfc19]64 Walker = World::get()->createAtom();
[57cfb7]65 Walker->type = hydrogen;
66 Walker->node->Init(1., 0., 1. );
67 TestMolecule->AddAtom(Walker);
[7bfc19]68 Walker = World::get()->createAtom();
[57cfb7]69 Walker->type = hydrogen;
70 Walker->node->Init(0., 1., 1. );
71 TestMolecule->AddAtom(Walker);
[7bfc19]72 Walker = World::get()->createAtom();
[57cfb7]73 Walker->type = hydrogen;
74 Walker->node->Init(1., 1., 0. );
75 TestMolecule->AddAtom(Walker);
[7bfc19]76 Walker = World::get()->createAtom();
[57cfb7]77 Walker->type = hydrogen;
78 Walker->node->Init(0., 0., 0. );
79 TestMolecule->AddAtom(Walker);
80
81 // check that TestMolecule was correctly constructed
82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
83
[e1900f]84 TestList = new MoleculeListClass;
85 TestMolecule->ActiveFlag = true;
86 TestList->insert(TestMolecule);
87
[57cfb7]88 // init tesselation and linked cell
89 Surface = new Tesselation;
[543ce4]90 FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
[57cfb7]91 LC = new LinkedCell(TestMolecule, 5.);
92 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
93 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
94 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
95
[13ecff]96 // add outer atoms
[7bfc19]97 Walker = World::get()->createAtom();
[13ecff]98 Walker->type = carbon;
99 Walker->node->Init(4., 0., 4. );
100 TestMolecule->AddAtom(Walker);
[7bfc19]101 Walker = World::get()->createAtom();
[13ecff]102 Walker->type = carbon;
103 Walker->node->Init(0., 4., 4. );
104 TestMolecule->AddAtom(Walker);
[7bfc19]105 Walker = World::get()->createAtom();
[13ecff]106 Walker->type = carbon;
107 Walker->node->Init(4., 4., 0. );
108 TestMolecule->AddAtom(Walker);
109 // add inner atoms
[7bfc19]110 Walker = World::get()->createAtom();
[13ecff]111 Walker->type = carbon;
112 Walker->node->Init(0.5, 0.5, 0.5 );
113 TestMolecule->AddAtom(Walker);
114
[57cfb7]115 // init maps
[13ecff]116 surfacemap = NULL;
[57cfb7]117 binmap = NULL;
118
119};
120
121
122void AnalysisCorrelationToSurfaceUnitTest::tearDown()
123{
124 if (surfacemap != NULL)
125 delete(surfacemap);
126 if (binmap != NULL)
127 delete(binmap);
128
129 // remove
[e1900f]130 delete(TestList);
[a9b2a0a]131 delete(Surface);
132 // note that all the atoms are cleaned by TestMolecule
[57cfb7]133 delete(LC);
134 delete(tafel);
135 // note that element is cleaned by periodentafel
136};
137
138
139void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
140{
141 // do the pair correlation
[543ce4]142 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[57cfb7]143 CPPUNIT_ASSERT( surfacemap != NULL );
144 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
145};
146
[13ecff]147void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
[57cfb7]148{
149 BinPairMap::iterator tester;
[543ce4]150 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[57cfb7]151 // put pair correlation into bins and check with no range
[543ce4]152 binmap = BinData( surfacemap, 0.5, 0., 0. );
[57cfb7]153 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
[543ce4]154 //OutputCorrelation ( binmap );
[57cfb7]155 tester = binmap->begin();
156 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
157 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
158
159};
160
[13ecff]161void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
[57cfb7]162{
163 BinPairMap::iterator tester;
[543ce4]164 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[57cfb7]165 // ... and check with [0., 2.] range
[543ce4]166 binmap = BinData( surfacemap, 0.5, 0., 2. );
[57cfb7]167 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
[543ce4]168 //OutputCorrelation ( binmap );
[57cfb7]169 tester = binmap->begin();
170 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
171 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
172 tester = binmap->find(1.);
173 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
174 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
175
176};
177
[13ecff]178void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
179{
180 BinPairMap::iterator tester;
[543ce4]181 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
[13ecff]182 // put pair correlation into bins and check with no range
[543ce4]183 binmap = BinData( surfacemap, 0.5, 0., 0. );
[13ecff]184 CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
185 OutputCorrelation ( (ofstream *)&cout, binmap );
186 // inside point is first and must have negative value
187 tester = binmap->lower_bound(2.95); // start depends on the min value and
188 CPPUNIT_ASSERT( tester != binmap->end() );
189 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
190 // inner point
[5f1d021]191 tester = binmap->lower_bound(-0.5);
[13ecff]192 CPPUNIT_ASSERT( tester != binmap->end() );
193 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
194};
195
196void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
197{
198 BinPairMap::iterator tester;
[543ce4]199 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
[13ecff]200 // ... and check with [0., 2.] range
[543ce4]201 binmap = BinData( surfacemap, 0.5, -2., 4. );
[13ecff]202 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
203 OutputCorrelation ( (ofstream *)&cout, binmap );
204 // three outside points
[5f1d021]205 tester = binmap->lower_bound(3.);
[13ecff]206 CPPUNIT_ASSERT( tester != binmap->end() );
207 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
208 // inner point
[5f1d021]209 tester = binmap->lower_bound(-0.5);
[13ecff]210 CPPUNIT_ASSERT( tester != binmap->end() );
211 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
212
213};
214
[57cfb7]215/********************************************** Main routine **************************************/
216
217int main(int argc, char **argv)
218{
219 // Get the top level suite from the registry
220 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
221
222 // Adds the test to the list of test to run
223 CppUnit::TextUi::TestRunner runner;
224 runner.addTest( suite );
225
226 // Change the default outputter to a compiler error format outputter
227 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
228 std::cerr ) );
229 // Run the tests.
230 bool wasSucessful = runner.run();
231
232 // Return error code 1 if the one of test failed.
233 return wasSucessful ? 0 : 1;
234};
Note: See TracBrowser for help on using the repository browser.