1 | /*
|
---|
2 | * AnalysisCorrelationToSurfaceUnitTest.cpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 13, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 | #include <cppunit/CompilerOutputter.h>
|
---|
11 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
12 | #include <cppunit/ui/text/TestRunner.h>
|
---|
13 |
|
---|
14 | #include <cstring>
|
---|
15 |
|
---|
16 | #include "analysis_correlation.hpp"
|
---|
17 | #include "AnalysisCorrelationToSurfaceUnitTest.hpp"
|
---|
18 |
|
---|
19 | #include "World.hpp"
|
---|
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 | #include "World.hpp"
|
---|
28 |
|
---|
29 | #include "Helpers/Assert.hpp"
|
---|
30 |
|
---|
31 | #ifdef HAVE_TESTRUNNER
|
---|
32 | #include "UnitTestMain.hpp"
|
---|
33 | #endif /*HAVE_TESTRUNNER*/
|
---|
34 |
|
---|
35 | /********************************************** Test classes **************************************/
|
---|
36 |
|
---|
37 | // Registers the fixture into the 'registry'
|
---|
38 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
|
---|
39 |
|
---|
40 | void AnalysisCorrelationToSurfaceUnitTest::setUp()
|
---|
41 | {
|
---|
42 | ASSERT_DO(Assert::Throw);
|
---|
43 |
|
---|
44 | atom *Walker = NULL;
|
---|
45 |
|
---|
46 | // init private all pointers to zero
|
---|
47 | TestList = NULL;
|
---|
48 | TestMolecule = NULL;
|
---|
49 | hydrogen = NULL;
|
---|
50 | tafel = NULL;
|
---|
51 | surfacemap = NULL;
|
---|
52 | binmap = NULL;
|
---|
53 | Surface = NULL;
|
---|
54 | LC = NULL;
|
---|
55 |
|
---|
56 | // construct element
|
---|
57 | hydrogen = new element;
|
---|
58 | hydrogen->Z = 1;
|
---|
59 | strcpy(hydrogen->name, "hydrogen");
|
---|
60 | strcpy(hydrogen->symbol, "H");
|
---|
61 | carbon = new element;
|
---|
62 | carbon->Z = 6;
|
---|
63 | strcpy(carbon->name, "carbon");
|
---|
64 | strcpy(carbon->symbol, "C");
|
---|
65 |
|
---|
66 | // construct periodentafel
|
---|
67 | tafel = World::getInstance().getPeriode();
|
---|
68 | tafel->AddElement(hydrogen);
|
---|
69 | tafel->AddElement(carbon);
|
---|
70 |
|
---|
71 | // construct molecule (tetraeder of hydrogens) base
|
---|
72 | TestMolecule = World::getInstance().createMolecule();
|
---|
73 | Walker = World::getInstance().createAtom();
|
---|
74 | Walker->type = hydrogen;
|
---|
75 | Walker->node->Init(1., 0., 1. );
|
---|
76 | TestMolecule->AddAtom(Walker);
|
---|
77 | Walker = World::getInstance().createAtom();
|
---|
78 | Walker->type = hydrogen;
|
---|
79 | Walker->node->Init(0., 1., 1. );
|
---|
80 | TestMolecule->AddAtom(Walker);
|
---|
81 | Walker = World::getInstance().createAtom();
|
---|
82 | Walker->type = hydrogen;
|
---|
83 | Walker->node->Init(1., 1., 0. );
|
---|
84 | TestMolecule->AddAtom(Walker);
|
---|
85 | Walker = World::getInstance().createAtom();
|
---|
86 | Walker->type = hydrogen;
|
---|
87 | Walker->node->Init(0., 0., 0. );
|
---|
88 | TestMolecule->AddAtom(Walker);
|
---|
89 |
|
---|
90 | // check that TestMolecule was correctly constructed
|
---|
91 | CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
|
---|
92 |
|
---|
93 | TestList = World::getInstance().getMolecules();
|
---|
94 | TestMolecule->ActiveFlag = true;
|
---|
95 | TestList->insert(TestMolecule);
|
---|
96 |
|
---|
97 | // init tesselation and linked cell
|
---|
98 | Surface = new Tesselation;
|
---|
99 | FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
---|
100 | LC = new LinkedCell(TestMolecule, 5.);
|
---|
101 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
102 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
103 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
104 |
|
---|
105 | // add outer atoms
|
---|
106 | Walker = World::getInstance().createAtom();
|
---|
107 | Walker->type = carbon;
|
---|
108 | Walker->node->Init(4., 0., 4. );
|
---|
109 | TestMolecule->AddAtom(Walker);
|
---|
110 | Walker = World::getInstance().createAtom();
|
---|
111 | Walker->type = carbon;
|
---|
112 | Walker->node->Init(0., 4., 4. );
|
---|
113 | TestMolecule->AddAtom(Walker);
|
---|
114 | Walker = World::getInstance().createAtom();
|
---|
115 | Walker->type = carbon;
|
---|
116 | Walker->node->Init(4., 4., 0. );
|
---|
117 | TestMolecule->AddAtom(Walker);
|
---|
118 | // add inner atoms
|
---|
119 | Walker = World::getInstance().createAtom();
|
---|
120 | Walker->type = carbon;
|
---|
121 | Walker->node->Init(0.5, 0.5, 0.5 );
|
---|
122 | TestMolecule->AddAtom(Walker);
|
---|
123 |
|
---|
124 | // init maps
|
---|
125 | surfacemap = NULL;
|
---|
126 | binmap = NULL;
|
---|
127 |
|
---|
128 | };
|
---|
129 |
|
---|
130 |
|
---|
131 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
132 | {
|
---|
133 | if (surfacemap != NULL)
|
---|
134 | delete(surfacemap);
|
---|
135 | if (binmap != NULL)
|
---|
136 | delete(binmap);
|
---|
137 |
|
---|
138 | delete(Surface);
|
---|
139 | // note that all the atoms are cleaned by TestMolecule
|
---|
140 | delete(LC);
|
---|
141 | World::purgeInstance();
|
---|
142 | MemoryUsageObserver::purgeInstance();
|
---|
143 | logger::purgeInstance();
|
---|
144 | };
|
---|
145 |
|
---|
146 |
|
---|
147 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
148 | {
|
---|
149 | // do the pair correlation
|
---|
150 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
151 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
152 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
153 | };
|
---|
154 |
|
---|
155 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
156 | {
|
---|
157 | BinPairMap::iterator tester;
|
---|
158 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
159 | // put pair correlation into bins and check with no range
|
---|
160 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
161 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
162 | //OutputCorrelation ( binmap );
|
---|
163 | tester = binmap->begin();
|
---|
164 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
165 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
166 |
|
---|
167 | };
|
---|
168 |
|
---|
169 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
170 | {
|
---|
171 | BinPairMap::iterator tester;
|
---|
172 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
173 | // ... and check with [0., 2.] range
|
---|
174 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
---|
175 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
176 | //OutputCorrelation ( binmap );
|
---|
177 | tester = binmap->begin();
|
---|
178 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
179 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
180 | tester = binmap->find(1.);
|
---|
181 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
182 | CPPUNIT_ASSERT_EQUAL( 0, tester->second );
|
---|
183 |
|
---|
184 | };
|
---|
185 |
|
---|
186 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
187 | {
|
---|
188 | BinPairMap::iterator tester;
|
---|
189 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
---|
190 | // put pair correlation into bins and check with no range
|
---|
191 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
192 | CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
|
---|
193 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
194 | // inside point is first and must have negative value
|
---|
195 | tester = binmap->lower_bound(2.95); // start depends on the min value and
|
---|
196 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
197 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
198 | // inner point
|
---|
199 | tester = binmap->lower_bound(-0.5);
|
---|
200 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
201 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
202 | };
|
---|
203 |
|
---|
204 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
205 | {
|
---|
206 | BinPairMap::iterator tester;
|
---|
207 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
---|
208 | // ... and check with [0., 2.] range
|
---|
209 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
210 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
211 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
212 | // three outside points
|
---|
213 | tester = binmap->lower_bound(3.);
|
---|
214 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
215 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
216 | // inner point
|
---|
217 | tester = binmap->lower_bound(-0.5);
|
---|
218 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
219 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
220 |
|
---|
221 | };
|
---|