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