[c4d4df] | 1 | /*
|
---|
| 2 | * AnalysisCorrelationToPointUnitTest.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 "AnalysisCorrelationToPointUnitTest.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"
|
---|
[e6fdbe] | 26 | #include "World.hpp"
|
---|
[c4d4df] | 27 |
|
---|
[9b6b2f] | 28 | #ifdef HAVE_TESTRUNNER
|
---|
| 29 | #include "UnitTestMain.hpp"
|
---|
| 30 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 31 |
|
---|
[c4d4df] | 32 | /********************************************** Test classes **************************************/
|
---|
| 33 |
|
---|
| 34 | // Registers the fixture into the 'registry'
|
---|
| 35 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
|
---|
| 36 |
|
---|
| 37 | void AnalysisCorrelationToPointUnitTest::setUp()
|
---|
| 38 | {
|
---|
| 39 | atom *Walker = NULL;
|
---|
| 40 |
|
---|
| 41 | // init private all pointers to zero
|
---|
[a5551b] | 42 | TestList = NULL;
|
---|
[c4d4df] | 43 | TestMolecule = NULL;
|
---|
| 44 | hydrogen = NULL;
|
---|
| 45 | tafel = NULL;
|
---|
| 46 | pointmap = NULL;
|
---|
| 47 | binmap = NULL;
|
---|
| 48 | point = NULL;
|
---|
| 49 |
|
---|
| 50 | // construct element
|
---|
| 51 | hydrogen = new element;
|
---|
| 52 | hydrogen->Z = 1;
|
---|
| 53 | strcpy(hydrogen->name, "hydrogen");
|
---|
[bbc338] | 54 | strcpy(hydrogen->symbol, "H");
|
---|
| 55 |
|
---|
[c4d4df] | 56 |
|
---|
| 57 | // construct periodentafel
|
---|
| 58 | tafel = new periodentafel;
|
---|
| 59 | tafel->AddElement(hydrogen);
|
---|
| 60 |
|
---|
| 61 | // construct molecule (tetraeder of hydrogens)
|
---|
| 62 | TestMolecule = new molecule(tafel);
|
---|
| 63 | Walker = new atom();
|
---|
| 64 | Walker->type = hydrogen;
|
---|
| 65 | Walker->node->Init(1., 0., 1. );
|
---|
| 66 | TestMolecule->AddAtom(Walker);
|
---|
| 67 | Walker = new atom();
|
---|
| 68 | Walker->type = hydrogen;
|
---|
| 69 | Walker->node->Init(0., 1., 1. );
|
---|
| 70 | TestMolecule->AddAtom(Walker);
|
---|
| 71 | Walker = new atom();
|
---|
| 72 | Walker->type = hydrogen;
|
---|
| 73 | Walker->node->Init(1., 1., 0. );
|
---|
| 74 | TestMolecule->AddAtom(Walker);
|
---|
| 75 | Walker = new atom();
|
---|
| 76 | Walker->type = hydrogen;
|
---|
| 77 | Walker->node->Init(0., 0., 0. );
|
---|
| 78 | TestMolecule->AddAtom(Walker);
|
---|
| 79 |
|
---|
| 80 | // check that TestMolecule was correctly constructed
|
---|
| 81 | CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
|
---|
| 82 |
|
---|
[a5551b] | 83 | TestList = new MoleculeListClass;
|
---|
| 84 | TestMolecule->ActiveFlag = true;
|
---|
| 85 | TestList->insert(TestMolecule);
|
---|
| 86 |
|
---|
[c4d4df] | 87 | // init point
|
---|
| 88 | point = new Vector(1.,1.,1.);
|
---|
| 89 |
|
---|
| 90 | // init maps
|
---|
[e138de] | 91 | pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, (const element * const)hydrogen, (const Vector *)point );
|
---|
[c4d4df] | 92 | binmap = NULL;
|
---|
| 93 |
|
---|
| 94 | };
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | void AnalysisCorrelationToPointUnitTest::tearDown()
|
---|
| 98 | {
|
---|
| 99 | if (pointmap != NULL)
|
---|
| 100 | delete(pointmap);
|
---|
| 101 | if (binmap != NULL)
|
---|
| 102 | delete(binmap);
|
---|
| 103 |
|
---|
| 104 | // remove
|
---|
[a5551b] | 105 | delete(TestList);
|
---|
[c4d4df] | 106 | // note that all the atoms are cleaned by TestMolecule
|
---|
| 107 | delete(point);
|
---|
| 108 | delete(tafel);
|
---|
| 109 | // note that element is cleaned by periodentafel
|
---|
[e6fdbe] | 110 | World::destroy();
|
---|
| 111 | MemoryUsageObserver::purgeInstance();
|
---|
| 112 | logger::purgeInstance();
|
---|
[c4d4df] | 113 | };
|
---|
| 114 |
|
---|
| 115 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
|
---|
| 116 | {
|
---|
| 117 | // do the pair correlation
|
---|
| 118 | CPPUNIT_ASSERT( pointmap != NULL );
|
---|
| 119 | CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
|
---|
| 120 |
|
---|
| 121 | };
|
---|
| 122 |
|
---|
| 123 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
|
---|
| 124 | {
|
---|
| 125 | BinPairMap::iterator tester;
|
---|
| 126 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 127 | binmap = BinData( pointmap, 0.5, 0., 0. );
|
---|
[c4d4df] | 128 | CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
|
---|
[e138de] | 129 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 130 | tester = binmap->begin();
|
---|
| 131 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 132 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 133 |
|
---|
| 134 | };
|
---|
| 135 |
|
---|
| 136 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
|
---|
| 137 | {
|
---|
| 138 | BinPairMap::iterator tester;
|
---|
| 139 | // ... and check with [0., 2.] range
|
---|
[e138de] | 140 | binmap = BinData( pointmap, 0.5, 0., 2. );
|
---|
[c4d4df] | 141 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
[e138de] | 142 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 143 | tester = binmap->begin();
|
---|
| 144 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 145 | tester = binmap->find(1.);
|
---|
| 146 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 147 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 148 |
|
---|
| 149 | };
|
---|