[c4d4df] | 1 | /*
|
---|
| 2 | * AnalysisPairCorrelationUnitTest.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 "AnalysisPairCorrelationUnitTest.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 |
|
---|
[9b6b2f] | 29 | #ifdef HAVE_TESTRUNNER
|
---|
| 30 | #include "UnitTestMain.hpp"
|
---|
| 31 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 32 |
|
---|
| 33 | /********************************************** Test classes **************************************/
|
---|
| 34 |
|
---|
| 35 | // Registers the fixture into the 'registry'
|
---|
| 36 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisPairCorrelationUnitTest );
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | void AnalysisPairCorrelationUnitTest::setUp()
|
---|
| 40 | {
|
---|
| 41 | atom *Walker = NULL;
|
---|
| 42 |
|
---|
| 43 | // init private all pointers to zero
|
---|
[a5551b] | 44 | TestList = NULL;
|
---|
[c4d4df] | 45 | TestMolecule = NULL;
|
---|
| 46 | correlationmap = NULL;
|
---|
| 47 | binmap = NULL;
|
---|
| 48 |
|
---|
[c78d44] | 49 | // construct element list
|
---|
| 50 | std::vector<element *> elements;
|
---|
[4eb4fe] | 51 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
[c78d44] | 52 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
| 53 | elements.push_back(hydrogen);
|
---|
| 54 | elements.push_back(hydrogen);
|
---|
| 55 |
|
---|
| 56 | // construct molecule (tetraeder of hydrogens)
|
---|
[23b547] | 57 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 58 | Walker = World::getInstance().createAtom();
|
---|
[c4d4df] | 59 | Walker->type = hydrogen;
|
---|
[1bd79e] | 60 | *Walker->node = Vector(1., 0., 1. );
|
---|
[c4d4df] | 61 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 62 | Walker = World::getInstance().createAtom();
|
---|
[c4d4df] | 63 | Walker->type = hydrogen;
|
---|
[1bd79e] | 64 | *Walker->node = Vector(0., 1., 1. );
|
---|
[c4d4df] | 65 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 66 | Walker = World::getInstance().createAtom();
|
---|
[c4d4df] | 67 | Walker->type = hydrogen;
|
---|
[1bd79e] | 68 | *Walker->node = Vector(1., 1., 0. );
|
---|
[c4d4df] | 69 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 70 | Walker = World::getInstance().createAtom();
|
---|
[c4d4df] | 71 | Walker->type = hydrogen;
|
---|
[1bd79e] | 72 | *Walker->node = Vector(0., 0., 0. );
|
---|
[c4d4df] | 73 | TestMolecule->AddAtom(Walker);
|
---|
| 74 |
|
---|
| 75 | // check that TestMolecule was correctly constructed
|
---|
[ea7176] | 76 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 77 |
|
---|
[23b547] | 78 | TestList = World::getInstance().getMolecules();
|
---|
[a5551b] | 79 | TestMolecule->ActiveFlag = true;
|
---|
| 80 | TestList->insert(TestMolecule);
|
---|
| 81 |
|
---|
[c4d4df] | 82 | // init maps
|
---|
[c78d44] | 83 | correlationmap = PairCorrelation( TestList, elements);
|
---|
[c4d4df] | 84 | binmap = NULL;
|
---|
| 85 |
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | void AnalysisPairCorrelationUnitTest::tearDown()
|
---|
| 90 | {
|
---|
| 91 | if (correlationmap != NULL)
|
---|
| 92 | delete(correlationmap);
|
---|
| 93 | if (binmap != NULL)
|
---|
| 94 | delete(binmap);
|
---|
| 95 |
|
---|
| 96 | // note that all the atoms are cleaned by TestMolecule
|
---|
[23b547] | 97 | World::purgeInstance();
|
---|
[e6fdbe] | 98 | logger::purgeInstance();
|
---|
| 99 | errorLogger::purgeInstance();
|
---|
[c4d4df] | 100 | };
|
---|
| 101 |
|
---|
| 102 | void AnalysisPairCorrelationUnitTest::PairCorrelationTest()
|
---|
| 103 | {
|
---|
| 104 | // do the pair correlation
|
---|
| 105 | CPPUNIT_ASSERT( correlationmap != NULL );
|
---|
| 106 | CPPUNIT_ASSERT_EQUAL( (size_t)6, correlationmap->size() );
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinNoRangeTest()
|
---|
| 110 | {
|
---|
| 111 | BinPairMap::iterator tester;
|
---|
| 112 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 113 | binmap = BinData( correlationmap, 0.5, 0., 0. );
|
---|
[c4d4df] | 114 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
[e138de] | 115 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 116 | tester = binmap->begin();
|
---|
| 117 | CPPUNIT_ASSERT_EQUAL( sqrt(2.), tester->first );
|
---|
| 118 | CPPUNIT_ASSERT_EQUAL( 6, tester->second );
|
---|
| 119 | };
|
---|
| 120 |
|
---|
| 121 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinRangeTest()
|
---|
| 122 | {
|
---|
| 123 | BinPairMap::iterator tester;
|
---|
| 124 | // ... and check with [0., 2.] range
|
---|
[e138de] | 125 | binmap = BinData( correlationmap, 0.5, 0., 2. );
|
---|
[c4d4df] | 126 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
[e138de] | 127 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 128 | tester = binmap->begin();
|
---|
| 129 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 130 | tester = binmap->find(1.);
|
---|
| 131 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 132 | CPPUNIT_ASSERT_EQUAL( 6, tester->second );
|
---|
| 133 | };
|
---|