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