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