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