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