[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 |
|
---|
[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 | {
|
---|
[80c63d] | 41 | ASSERT_DO(Assert::Throw);
|
---|
[c4d4df] | 42 | atom *Walker = NULL;
|
---|
| 43 |
|
---|
| 44 | // init private all pointers to zero
|
---|
[a5551b] | 45 | TestList = NULL;
|
---|
[c4d4df] | 46 | TestMolecule = NULL;
|
---|
| 47 | hydrogen = NULL;
|
---|
| 48 | tafel = NULL;
|
---|
| 49 | surfacemap = NULL;
|
---|
| 50 | binmap = NULL;
|
---|
| 51 | Surface = NULL;
|
---|
| 52 | LC = NULL;
|
---|
| 53 |
|
---|
| 54 | // construct element
|
---|
| 55 | hydrogen = new element;
|
---|
| 56 | hydrogen->Z = 1;
|
---|
| 57 | strcpy(hydrogen->name, "hydrogen");
|
---|
[bbc338] | 58 | strcpy(hydrogen->symbol, "H");
|
---|
| 59 | carbon = new element;
|
---|
| 60 | carbon->Z = 6;
|
---|
| 61 | strcpy(carbon->name, "carbon");
|
---|
| 62 | strcpy(carbon->symbol, "C");
|
---|
[c4d4df] | 63 |
|
---|
| 64 | // construct periodentafel
|
---|
[cbc5fb] | 65 | tafel = World::get()->getPeriode();
|
---|
[c4d4df] | 66 | tafel->AddElement(hydrogen);
|
---|
[bbc338] | 67 | tafel->AddElement(carbon);
|
---|
[c4d4df] | 68 |
|
---|
[bbc338] | 69 | // construct molecule (tetraeder of hydrogens) base
|
---|
[cbc5fb] | 70 | TestMolecule = World::get()->createMolecule();
|
---|
[46d958] | 71 | Walker = World::get()->createAtom();
|
---|
[c4d4df] | 72 | Walker->type = hydrogen;
|
---|
| 73 | Walker->node->Init(1., 0., 1. );
|
---|
| 74 | TestMolecule->AddAtom(Walker);
|
---|
[46d958] | 75 | Walker = World::get()->createAtom();
|
---|
[c4d4df] | 76 | Walker->type = hydrogen;
|
---|
| 77 | Walker->node->Init(0., 1., 1. );
|
---|
| 78 | TestMolecule->AddAtom(Walker);
|
---|
[46d958] | 79 | Walker = World::get()->createAtom();
|
---|
[c4d4df] | 80 | Walker->type = hydrogen;
|
---|
| 81 | Walker->node->Init(1., 1., 0. );
|
---|
| 82 | TestMolecule->AddAtom(Walker);
|
---|
[46d958] | 83 | Walker = World::get()->createAtom();
|
---|
[c4d4df] | 84 | Walker->type = hydrogen;
|
---|
| 85 | Walker->node->Init(0., 0., 0. );
|
---|
| 86 | TestMolecule->AddAtom(Walker);
|
---|
| 87 |
|
---|
| 88 | // check that TestMolecule was correctly constructed
|
---|
| 89 | CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
|
---|
| 90 |
|
---|
[cbc5fb] | 91 | TestList = World::get()->getMolecules();
|
---|
[a5551b] | 92 | TestMolecule->ActiveFlag = true;
|
---|
| 93 | TestList->insert(TestMolecule);
|
---|
| 94 |
|
---|
[c4d4df] | 95 | // init tesselation and linked cell
|
---|
| 96 | Surface = new Tesselation;
|
---|
[e138de] | 97 | FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
---|
[c4d4df] | 98 | LC = new LinkedCell(TestMolecule, 5.);
|
---|
| 99 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
| 100 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
| 101 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
| 102 |
|
---|
[bbc338] | 103 | // add outer atoms
|
---|
[46d958] | 104 | Walker = World::get()->createAtom();
|
---|
[bbc338] | 105 | Walker->type = carbon;
|
---|
| 106 | Walker->node->Init(4., 0., 4. );
|
---|
| 107 | TestMolecule->AddAtom(Walker);
|
---|
[46d958] | 108 | Walker = World::get()->createAtom();
|
---|
[bbc338] | 109 | Walker->type = carbon;
|
---|
| 110 | Walker->node->Init(0., 4., 4. );
|
---|
| 111 | TestMolecule->AddAtom(Walker);
|
---|
[46d958] | 112 | Walker = World::get()->createAtom();
|
---|
[bbc338] | 113 | Walker->type = carbon;
|
---|
| 114 | Walker->node->Init(4., 4., 0. );
|
---|
| 115 | TestMolecule->AddAtom(Walker);
|
---|
| 116 | // add inner atoms
|
---|
[46d958] | 117 | Walker = World::get()->createAtom();
|
---|
[bbc338] | 118 | Walker->type = carbon;
|
---|
| 119 | Walker->node->Init(0.5, 0.5, 0.5 );
|
---|
| 120 | TestMolecule->AddAtom(Walker);
|
---|
| 121 |
|
---|
[c4d4df] | 122 | // init maps
|
---|
[bbc338] | 123 | surfacemap = NULL;
|
---|
[c4d4df] | 124 | binmap = NULL;
|
---|
| 125 |
|
---|
| 126 | };
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
| 130 | {
|
---|
| 131 | if (surfacemap != NULL)
|
---|
| 132 | delete(surfacemap);
|
---|
| 133 | if (binmap != NULL)
|
---|
| 134 | delete(binmap);
|
---|
| 135 |
|
---|
[776b64] | 136 | delete(Surface);
|
---|
| 137 | // note that all the atoms are cleaned by TestMolecule
|
---|
[c4d4df] | 138 | delete(LC);
|
---|
[cbc5fb] | 139 | World::destroy();
|
---|
[e6fdbe] | 140 | MemoryUsageObserver::purgeInstance();
|
---|
| 141 | logger::purgeInstance();
|
---|
[c4d4df] | 142 | };
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
| 146 | {
|
---|
| 147 | // do the pair correlation
|
---|
[e138de] | 148 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
[c4d4df] | 149 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
| 150 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
| 151 | };
|
---|
| 152 |
|
---|
[bbc338] | 153 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
[c4d4df] | 154 | {
|
---|
| 155 | BinPairMap::iterator tester;
|
---|
[e138de] | 156 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
[c4d4df] | 157 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 158 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[c4d4df] | 159 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
[e138de] | 160 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 161 | tester = binmap->begin();
|
---|
| 162 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 163 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 164 |
|
---|
| 165 | };
|
---|
| 166 |
|
---|
[bbc338] | 167 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
[c4d4df] | 168 | {
|
---|
| 169 | BinPairMap::iterator tester;
|
---|
[e138de] | 170 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
---|
[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() );
|
---|
[e138de] | 174 | //OutputCorrelation ( 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 );
|
---|
[bbc338] | 188 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 189 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[bbc338] | 190 | CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
|
---|
| 191 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 192 | // inside point is first and must have negative value
|
---|
| 193 | tester = binmap->lower_bound(2.95); // start depends on the min value and
|
---|
| 194 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 195 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 196 | // inner point
|
---|
[7ea9e6] | 197 | tester = binmap->lower_bound(-0.5);
|
---|
[bbc338] | 198 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 199 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 200 | };
|
---|
| 201 |
|
---|
| 202 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
| 203 | {
|
---|
| 204 | BinPairMap::iterator tester;
|
---|
[e138de] | 205 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
---|
[bbc338] | 206 | // ... and check with [0., 2.] range
|
---|
[e138de] | 207 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
[bbc338] | 208 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
| 209 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 210 | // three outside points
|
---|
[7ea9e6] | 211 | tester = binmap->lower_bound(3.);
|
---|
[bbc338] | 212 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 213 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 214 | // inner point
|
---|
[7ea9e6] | 215 | tester = binmap->lower_bound(-0.5);
|
---|
[bbc338] | 216 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 217 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 218 |
|
---|
| 219 | };
|
---|