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 | TestSurfaceMolecule = 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 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
73 | Walker = World::getInstance().createAtom();
|
---|
74 | Walker->type = hydrogen;
|
---|
75 | *Walker->node = Vector(1., 0., 1. );
|
---|
76 |
|
---|
77 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
78 | Walker = World::getInstance().createAtom();
|
---|
79 | Walker->type = hydrogen;
|
---|
80 | *Walker->node = Vector(0., 1., 1. );
|
---|
81 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
82 | Walker = World::getInstance().createAtom();
|
---|
83 | Walker->type = hydrogen;
|
---|
84 | *Walker->node = Vector(1., 1., 0. );
|
---|
85 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
86 | Walker = World::getInstance().createAtom();
|
---|
87 | Walker->type = hydrogen;
|
---|
88 | *Walker->node = Vector(0., 0., 0. );
|
---|
89 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
90 |
|
---|
91 | // check that TestMolecule was correctly constructed
|
---|
92 | CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
|
---|
93 |
|
---|
94 | TestList = World::getInstance().getMolecules();
|
---|
95 | TestSurfaceMolecule->ActiveFlag = true;
|
---|
96 | TestList->insert(TestSurfaceMolecule);
|
---|
97 |
|
---|
98 | // init tesselation and linked cell
|
---|
99 | Surface = new Tesselation;
|
---|
100 | LC = new LinkedCell(TestSurfaceMolecule, 5.);
|
---|
101 | FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
---|
102 |
|
---|
103 | // add outer atoms
|
---|
104 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
105 | Walker = World::getInstance().createAtom();
|
---|
106 | Walker->type = carbon;
|
---|
107 | *Walker->node = Vector(4., 0., 4. );
|
---|
108 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
109 | Walker = World::getInstance().createAtom();
|
---|
110 | Walker->type = carbon;
|
---|
111 | *Walker->node = Vector(0., 4., 4. );
|
---|
112 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
113 | Walker = World::getInstance().createAtom();
|
---|
114 | Walker->type = carbon;
|
---|
115 | *Walker->node = Vector(4., 4., 0. );
|
---|
116 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
117 | // add inner atoms
|
---|
118 | Walker = World::getInstance().createAtom();
|
---|
119 | Walker->type = carbon;
|
---|
120 | *Walker->node = Vector(0.5, 0.5, 0.5 );
|
---|
121 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
122 | TestSurfaceMolecule->ActiveFlag = true;
|
---|
123 | TestList->insert(TestSurfaceMolecule);
|
---|
124 |
|
---|
125 | // init maps
|
---|
126 | surfacemap = NULL;
|
---|
127 | binmap = NULL;
|
---|
128 |
|
---|
129 | };
|
---|
130 |
|
---|
131 |
|
---|
132 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
133 | {
|
---|
134 | if (surfacemap != NULL)
|
---|
135 | delete(surfacemap);
|
---|
136 | if (binmap != NULL)
|
---|
137 | delete(binmap);
|
---|
138 |
|
---|
139 | delete(Surface);
|
---|
140 | // note that all the atoms are cleaned by TestMolecule
|
---|
141 | delete(LC);
|
---|
142 | World::purgeInstance();
|
---|
143 | MemoryUsageObserver::purgeInstance();
|
---|
144 | logger::purgeInstance();
|
---|
145 | };
|
---|
146 |
|
---|
147 |
|
---|
148 | /** Checks whether setup() does the right thing.
|
---|
149 | */
|
---|
150 | void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
|
---|
151 | {
|
---|
152 | CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
|
---|
153 | CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
|
---|
154 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
155 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
156 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
157 | };
|
---|
158 |
|
---|
159 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
160 | {
|
---|
161 | // do the pair correlation
|
---|
162 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
163 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
164 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
165 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
166 | };
|
---|
167 |
|
---|
168 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
169 | {
|
---|
170 | BinPairMap::iterator tester;
|
---|
171 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
172 | // put pair correlation into bins and check with no range
|
---|
173 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
174 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
175 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
176 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
177 | tester = binmap->begin();
|
---|
178 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
179 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
180 |
|
---|
181 | };
|
---|
182 |
|
---|
183 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
184 | {
|
---|
185 | BinPairMap::iterator tester;
|
---|
186 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
187 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
188 | // ... and check with [0., 2.] range
|
---|
189 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
---|
190 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
191 | // OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
192 | tester = binmap->begin();
|
---|
193 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
194 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
195 | tester = binmap->find(1.);
|
---|
196 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
197 | CPPUNIT_ASSERT_EQUAL( 0, tester->second );
|
---|
198 |
|
---|
199 | };
|
---|
200 |
|
---|
201 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
202 | {
|
---|
203 | BinPairMap::iterator tester;
|
---|
204 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
---|
205 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
206 | // put pair correlation into bins and check with no range
|
---|
207 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
208 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
209 | CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
|
---|
210 | // inside point is first and must have negative value
|
---|
211 | tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
|
---|
212 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
213 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
214 | // inner point
|
---|
215 | tester = binmap->lower_bound(0.);
|
---|
216 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
217 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
218 | };
|
---|
219 |
|
---|
220 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
221 | {
|
---|
222 | BinPairMap::iterator tester;
|
---|
223 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
---|
224 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
225 | // ... and check with [0., 2.] range
|
---|
226 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
227 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
228 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
229 | // three outside points
|
---|
230 | tester = binmap->lower_bound(4.25-0.5);
|
---|
231 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
232 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
233 | // inner point
|
---|
234 | tester = binmap->lower_bound(0.);
|
---|
235 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
236 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
237 | };
|
---|