| 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 |
|
|---|
| 14 | #include <cstring>
|
|---|
| 15 |
|
|---|
| 16 | #include "analysis_correlation.hpp"
|
|---|
| 17 | #include "AnalysisCorrelationToSurfaceUnitTest.hpp"
|
|---|
| 18 |
|
|---|
| 19 | #include "World.hpp"
|
|---|
| 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"
|
|---|
| 27 | #include "World.hpp"
|
|---|
| 28 |
|
|---|
| 29 | #ifdef HAVE_TESTRUNNER
|
|---|
| 30 | #include "UnitTestMain.hpp"
|
|---|
| 31 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 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
|
|---|
| 43 | TestList = NULL;
|
|---|
| 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");
|
|---|
| 56 | strcpy(hydrogen->symbol, "H");
|
|---|
| 57 | carbon = new element;
|
|---|
| 58 | carbon->Z = 6;
|
|---|
| 59 | strcpy(carbon->name, "carbon");
|
|---|
| 60 | strcpy(carbon->symbol, "C");
|
|---|
| 61 |
|
|---|
| 62 | // construct periodentafel
|
|---|
| 63 | tafel = World::getInstance().getPeriode();
|
|---|
| 64 | tafel->AddElement(hydrogen);
|
|---|
| 65 | tafel->AddElement(carbon);
|
|---|
| 66 |
|
|---|
| 67 | // construct molecule (tetraeder of hydrogens) base
|
|---|
| 68 | TestMolecule = World::getInstance().createMolecule();
|
|---|
| 69 | Walker = World::getInstance().createAtom();
|
|---|
| 70 | Walker->type = hydrogen;
|
|---|
| 71 | Walker->node->Init(1., 0., 1. );
|
|---|
| 72 | TestMolecule->AddAtom(Walker);
|
|---|
| 73 | Walker = World::getInstance().createAtom();
|
|---|
| 74 | Walker->type = hydrogen;
|
|---|
| 75 | Walker->node->Init(0., 1., 1. );
|
|---|
| 76 | TestMolecule->AddAtom(Walker);
|
|---|
| 77 | Walker = World::getInstance().createAtom();
|
|---|
| 78 | Walker->type = hydrogen;
|
|---|
| 79 | Walker->node->Init(1., 1., 0. );
|
|---|
| 80 | TestMolecule->AddAtom(Walker);
|
|---|
| 81 | Walker = World::getInstance().createAtom();
|
|---|
| 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 |
|
|---|
| 89 | TestList = World::getInstance().getMolecules();
|
|---|
| 90 | TestMolecule->ActiveFlag = true;
|
|---|
| 91 | TestList->insert(TestMolecule);
|
|---|
| 92 |
|
|---|
| 93 | // init tesselation and linked cell
|
|---|
| 94 | Surface = new Tesselation;
|
|---|
| 95 | FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
|---|
| 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 |
|
|---|
| 101 | // add outer atoms
|
|---|
| 102 | Walker = World::getInstance().createAtom();
|
|---|
| 103 | Walker->type = carbon;
|
|---|
| 104 | Walker->node->Init(4., 0., 4. );
|
|---|
| 105 | TestMolecule->AddAtom(Walker);
|
|---|
| 106 | Walker = World::getInstance().createAtom();
|
|---|
| 107 | Walker->type = carbon;
|
|---|
| 108 | Walker->node->Init(0., 4., 4. );
|
|---|
| 109 | TestMolecule->AddAtom(Walker);
|
|---|
| 110 | Walker = World::getInstance().createAtom();
|
|---|
| 111 | Walker->type = carbon;
|
|---|
| 112 | Walker->node->Init(4., 4., 0. );
|
|---|
| 113 | TestMolecule->AddAtom(Walker);
|
|---|
| 114 | // add inner atoms
|
|---|
| 115 | Walker = World::getInstance().createAtom();
|
|---|
| 116 | Walker->type = carbon;
|
|---|
| 117 | Walker->node->Init(0.5, 0.5, 0.5 );
|
|---|
| 118 | TestMolecule->AddAtom(Walker);
|
|---|
| 119 |
|
|---|
| 120 | // init maps
|
|---|
| 121 | surfacemap = NULL;
|
|---|
| 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 |
|
|---|
| 134 | delete(Surface);
|
|---|
| 135 | // note that all the atoms are cleaned by TestMolecule
|
|---|
| 136 | delete(LC);
|
|---|
| 137 | World::purgeInstance();
|
|---|
| 138 | MemoryUsageObserver::purgeInstance();
|
|---|
| 139 | logger::purgeInstance();
|
|---|
| 140 | };
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
|---|
| 144 | {
|
|---|
| 145 | // do the pair correlation
|
|---|
| 146 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
|---|
| 147 | CPPUNIT_ASSERT( surfacemap != NULL );
|
|---|
| 148 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
|---|
| 149 | };
|
|---|
| 150 |
|
|---|
| 151 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
|---|
| 152 | {
|
|---|
| 153 | BinPairMap::iterator tester;
|
|---|
| 154 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
|---|
| 155 | // put pair correlation into bins and check with no range
|
|---|
| 156 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
|---|
| 157 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
|---|
| 158 | //OutputCorrelation ( binmap );
|
|---|
| 159 | tester = binmap->begin();
|
|---|
| 160 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
|---|
| 161 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
|---|
| 162 |
|
|---|
| 163 | };
|
|---|
| 164 |
|
|---|
| 165 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
|---|
| 166 | {
|
|---|
| 167 | BinPairMap::iterator tester;
|
|---|
| 168 | surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
|
|---|
| 169 | // ... and check with [0., 2.] range
|
|---|
| 170 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
|---|
| 171 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
|---|
| 172 | //OutputCorrelation ( binmap );
|
|---|
| 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 |
|
|---|
| 182 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
|---|
| 183 | {
|
|---|
| 184 | BinPairMap::iterator tester;
|
|---|
| 185 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
|---|
| 186 | // put pair correlation into bins and check with no range
|
|---|
| 187 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
|---|
| 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
|
|---|
| 195 | tester = binmap->lower_bound(-0.5);
|
|---|
| 196 | CPPUNIT_ASSERT( tester != binmap->end() );
|
|---|
| 197 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
|---|
| 198 | };
|
|---|
| 199 |
|
|---|
| 200 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
|---|
| 201 | {
|
|---|
| 202 | BinPairMap::iterator tester;
|
|---|
| 203 | surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
|
|---|
| 204 | // ... and check with [0., 2.] range
|
|---|
| 205 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
|---|
| 206 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
|---|
| 207 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
|---|
| 208 | // three outside points
|
|---|
| 209 | tester = binmap->lower_bound(3.);
|
|---|
| 210 | CPPUNIT_ASSERT( tester != binmap->end() );
|
|---|
| 211 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
|---|
| 212 | // inner point
|
|---|
| 213 | tester = binmap->lower_bound(-0.5);
|
|---|
| 214 | CPPUNIT_ASSERT( tester != binmap->end() );
|
|---|
| 215 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
|---|
| 216 |
|
|---|
| 217 | };
|
|---|