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