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