[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[c4d4df] | 8 | /*
|
---|
| 9 | * AnalysisPairCorrelationUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 13, 2009
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[c4d4df] | 20 | using namespace std;
|
---|
| 21 |
|
---|
| 22 | #include <cppunit/CompilerOutputter.h>
|
---|
| 23 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 24 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 25 |
|
---|
[49e1ae] | 26 | #include <cstring>
|
---|
| 27 |
|
---|
[c4d4df] | 28 | #include "analysis_correlation.hpp"
|
---|
[e65de8] | 29 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 30 |
|
---|
[46d958] | 31 | #include "World.hpp"
|
---|
[c4d4df] | 32 | #include "atom.hpp"
|
---|
| 33 | #include "boundary.hpp"
|
---|
| 34 | #include "element.hpp"
|
---|
| 35 | #include "molecule.hpp"
|
---|
| 36 | #include "linkedcell.hpp"
|
---|
| 37 | #include "periodentafel.hpp"
|
---|
| 38 | #include "tesselation.hpp"
|
---|
[e6fdbe] | 39 | #include "World.hpp"
|
---|
[c4d4df] | 40 |
|
---|
[f844ef] | 41 | #include "AnalysisPairCorrelationUnitTest.hpp"
|
---|
| 42 |
|
---|
[9b6b2f] | 43 | #ifdef HAVE_TESTRUNNER
|
---|
| 44 | #include "UnitTestMain.hpp"
|
---|
| 45 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 46 |
|
---|
| 47 | /********************************************** Test classes **************************************/
|
---|
| 48 |
|
---|
| 49 | // Registers the fixture into the 'registry'
|
---|
| 50 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisPairCorrelationUnitTest );
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | void AnalysisPairCorrelationUnitTest::setUp()
|
---|
| 54 | {
|
---|
| 55 | atom *Walker = NULL;
|
---|
| 56 |
|
---|
| 57 | // init private all pointers to zero
|
---|
| 58 | TestMolecule = NULL;
|
---|
| 59 | correlationmap = NULL;
|
---|
| 60 | binmap = NULL;
|
---|
| 61 |
|
---|
[c78d44] | 62 | // construct element list
|
---|
[e5c0a1] | 63 | std::vector<const element *> elements;
|
---|
[4eb4fe] | 64 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
[c78d44] | 65 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
| 66 | elements.push_back(hydrogen);
|
---|
| 67 | elements.push_back(hydrogen);
|
---|
| 68 |
|
---|
| 69 | // construct molecule (tetraeder of hydrogens)
|
---|
[23b547] | 70 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 71 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 72 | Walker->setType(hydrogen);
|
---|
| 73 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
[c4d4df] | 74 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 75 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 76 | Walker->setType(hydrogen);
|
---|
| 77 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
[c4d4df] | 78 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 79 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 80 | Walker->setType(hydrogen);
|
---|
| 81 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
[c4d4df] | 82 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 83 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 84 | Walker->setType(hydrogen);
|
---|
| 85 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
[c4d4df] | 86 | TestMolecule->AddAtom(Walker);
|
---|
| 87 |
|
---|
| 88 | // check that TestMolecule was correctly constructed
|
---|
[ea7176] | 89 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 90 |
|
---|
| 91 | // init maps
|
---|
[e65de8] | 92 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 93 | allMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 94 | CPPUNIT_ASSERT_EQUAL( (size_t) 1, allMolecules.size());
|
---|
| 95 | correlationmap = PairCorrelation( allMolecules, elements);
|
---|
[c4d4df] | 96 | binmap = NULL;
|
---|
| 97 |
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | void AnalysisPairCorrelationUnitTest::tearDown()
|
---|
| 102 | {
|
---|
| 103 | if (correlationmap != NULL)
|
---|
| 104 | delete(correlationmap);
|
---|
| 105 | if (binmap != NULL)
|
---|
| 106 | delete(binmap);
|
---|
| 107 |
|
---|
| 108 | // note that all the atoms are cleaned by TestMolecule
|
---|
[23b547] | 109 | World::purgeInstance();
|
---|
[e6fdbe] | 110 | logger::purgeInstance();
|
---|
| 111 | errorLogger::purgeInstance();
|
---|
[c4d4df] | 112 | };
|
---|
| 113 |
|
---|
| 114 | void AnalysisPairCorrelationUnitTest::PairCorrelationTest()
|
---|
| 115 | {
|
---|
| 116 | // do the pair correlation
|
---|
| 117 | CPPUNIT_ASSERT( correlationmap != NULL );
|
---|
| 118 | CPPUNIT_ASSERT_EQUAL( (size_t)6, correlationmap->size() );
|
---|
| 119 | };
|
---|
| 120 |
|
---|
| 121 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinNoRangeTest()
|
---|
| 122 | {
|
---|
| 123 | BinPairMap::iterator tester;
|
---|
| 124 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 125 | binmap = BinData( correlationmap, 0.5, 0., 0. );
|
---|
[c4d4df] | 126 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
[e138de] | 127 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 128 | tester = binmap->begin();
|
---|
| 129 | CPPUNIT_ASSERT_EQUAL( sqrt(2.), tester->first );
|
---|
| 130 | CPPUNIT_ASSERT_EQUAL( 6, tester->second );
|
---|
| 131 | };
|
---|
| 132 |
|
---|
| 133 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinRangeTest()
|
---|
| 134 | {
|
---|
| 135 | BinPairMap::iterator tester;
|
---|
| 136 | // ... and check with [0., 2.] range
|
---|
[e138de] | 137 | binmap = BinData( correlationmap, 0.5, 0., 2. );
|
---|
[c4d4df] | 138 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
[e138de] | 139 | //OutputCorrelation ( binmap );
|
---|
[c4d4df] | 140 | tester = binmap->begin();
|
---|
| 141 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 142 | tester = binmap->find(1.);
|
---|
| 143 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 144 | CPPUNIT_ASSERT_EQUAL( 6, tester->second );
|
---|
| 145 | };
|
---|