[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 |
|
---|
[e65de8] | 19 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 20 |
|
---|
[c4d4df] | 21 | #include "atom.hpp"
|
---|
| 22 | #include "element.hpp"
|
---|
| 23 | #include "molecule.hpp"
|
---|
| 24 | #include "linkedcell.hpp"
|
---|
| 25 | #include "periodentafel.hpp"
|
---|
[e6fdbe] | 26 | #include "World.hpp"
|
---|
[c4d4df] | 27 |
|
---|
[9b6b2f] | 28 | #ifdef HAVE_TESTRUNNER
|
---|
| 29 | #include "UnitTestMain.hpp"
|
---|
| 30 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 31 |
|
---|
| 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
|
---|
| 42 | TestMolecule = NULL;
|
---|
| 43 | pointmap = NULL;
|
---|
| 44 | binmap = NULL;
|
---|
| 45 | point = NULL;
|
---|
| 46 |
|
---|
[c78d44] | 47 | // construct element list
|
---|
| 48 | std::vector<element *> elements;
|
---|
[4eb4fe] | 49 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
| 50 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
[c78d44] | 51 | elements.push_back(hydrogen);
|
---|
| 52 | // construct molecule (tetraeder of hydrogens)
|
---|
[23b547] | 53 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 54 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 55 | Walker->setType(hydrogen);
|
---|
| 56 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
[c4d4df] | 57 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 58 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 59 | Walker->setType(hydrogen);
|
---|
| 60 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
[c4d4df] | 61 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 62 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 63 | Walker->setType(hydrogen);
|
---|
| 64 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
[c4d4df] | 65 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 66 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 67 | Walker->setType(hydrogen);
|
---|
| 68 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
[c4d4df] | 69 | TestMolecule->AddAtom(Walker);
|
---|
| 70 |
|
---|
| 71 | // check that TestMolecule was correctly constructed
|
---|
[ea7176] | 72 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 73 |
|
---|
[5f612ee] | 74 | TestMolecule->ActiveFlag = true;
|
---|
[a5551b] | 75 |
|
---|
[c4d4df] | 76 | // init point
|
---|
| 77 | point = new Vector(1.,1.,1.);
|
---|
| 78 |
|
---|
| 79 | // init maps
|
---|
[e65de8] | 80 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 81 | allMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 82 | CPPUNIT_ASSERT_EQUAL( (size_t) 1, allMolecules.size());
|
---|
| 83 | pointmap = CorrelationToPoint( allMolecules, elements, (const Vector *)point );
|
---|
[c4d4df] | 84 | binmap = NULL;
|
---|
| 85 |
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | void AnalysisCorrelationToPointUnitTest::tearDown()
|
---|
| 90 | {
|
---|
| 91 | if (pointmap != NULL)
|
---|
| 92 | delete(pointmap);
|
---|
| 93 | if (binmap != NULL)
|
---|
| 94 | delete(binmap);
|
---|
| 95 |
|
---|
| 96 | delete(point);
|
---|
[23b547] | 97 | World::purgeInstance();
|
---|
[e6fdbe] | 98 | logger::purgeInstance();
|
---|
[c4d4df] | 99 | };
|
---|
| 100 |
|
---|
| 101 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
|
---|
| 102 | {
|
---|
| 103 | // do the pair correlation
|
---|
| 104 | CPPUNIT_ASSERT( pointmap != NULL );
|
---|
| 105 | CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
|
---|
| 106 |
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
|
---|
| 110 | {
|
---|
| 111 | BinPairMap::iterator tester;
|
---|
| 112 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 113 | binmap = BinData( pointmap, 0.5, 0., 0. );
|
---|
[3d9df5] | 114 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 115 | CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
|
---|
[c4d4df] | 116 | tester = binmap->begin();
|
---|
| 117 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 118 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 119 |
|
---|
| 120 | };
|
---|
| 121 |
|
---|
| 122 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
|
---|
| 123 | {
|
---|
| 124 | BinPairMap::iterator tester;
|
---|
| 125 | // ... and check with [0., 2.] range
|
---|
[e138de] | 126 | binmap = BinData( pointmap, 0.5, 0., 2. );
|
---|
[3d9df5] | 127 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c4d4df] | 128 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
| 129 | tester = binmap->begin();
|
---|
| 130 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 131 | tester = binmap->find(1.);
|
---|
| 132 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 133 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 134 |
|
---|
| 135 | };
|
---|