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