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