[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[d103d3] | 4 | * Copyright (C) 2010-2011 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[c4d4df] | 8 | /*
|
---|
| 9 | * AnalysisCorrelationToPointUnitTest.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 |
|
---|
[9b5a2c] | 28 | #include "Analysis/analysis_correlation.hpp"
|
---|
[6f0841] | 29 | #include "Atom/atom.hpp"
|
---|
[53c7fc] | 30 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
[3bdb6d] | 31 | #include "Element/element.hpp"
|
---|
[53c7fc] | 32 | #include "Element/periodentafel.hpp"
|
---|
[c4d4df] | 33 | #include "molecule.hpp"
|
---|
[42127c] | 34 | #include "MoleculeListClass.hpp"
|
---|
[e6fdbe] | 35 | #include "World.hpp"
|
---|
[c4d4df] | 36 |
|
---|
[f844ef] | 37 | #include "AnalysisCorrelationToPointUnitTest.hpp"
|
---|
| 38 |
|
---|
[9b6b2f] | 39 | #ifdef HAVE_TESTRUNNER
|
---|
| 40 | #include "UnitTestMain.hpp"
|
---|
| 41 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 42 |
|
---|
| 43 | /********************************************** Test classes **************************************/
|
---|
| 44 |
|
---|
| 45 | // Registers the fixture into the 'registry'
|
---|
| 46 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
|
---|
| 47 |
|
---|
| 48 | void AnalysisCorrelationToPointUnitTest::setUp()
|
---|
| 49 | {
|
---|
| 50 | atom *Walker = NULL;
|
---|
| 51 |
|
---|
| 52 | // init private all pointers to zero
|
---|
| 53 | TestMolecule = NULL;
|
---|
| 54 | pointmap = NULL;
|
---|
| 55 | binmap = NULL;
|
---|
| 56 | point = NULL;
|
---|
| 57 |
|
---|
[c78d44] | 58 | // construct element list
|
---|
[e5c0a1] | 59 | std::vector<const element *> elements;
|
---|
[4eb4fe] | 60 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
| 61 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
[c78d44] | 62 | elements.push_back(hydrogen);
|
---|
| 63 | // construct molecule (tetraeder of hydrogens)
|
---|
[23b547] | 64 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 65 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 66 | Walker->setType(hydrogen);
|
---|
| 67 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
[c4d4df] | 68 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 69 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 70 | Walker->setType(hydrogen);
|
---|
| 71 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
[c4d4df] | 72 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 73 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 74 | Walker->setType(hydrogen);
|
---|
| 75 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
[c4d4df] | 76 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 77 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 78 | Walker->setType(hydrogen);
|
---|
| 79 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
[c4d4df] | 80 | TestMolecule->AddAtom(Walker);
|
---|
| 81 |
|
---|
| 82 | // check that TestMolecule was correctly constructed
|
---|
[ea7176] | 83 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 84 |
|
---|
[5f612ee] | 85 | TestMolecule->ActiveFlag = true;
|
---|
[a5551b] | 86 |
|
---|
[c4d4df] | 87 | // init point
|
---|
| 88 | point = new Vector(1.,1.,1.);
|
---|
| 89 |
|
---|
| 90 | // init maps
|
---|
[e65de8] | 91 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 92 | allMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 93 | CPPUNIT_ASSERT_EQUAL( (size_t) 1, allMolecules.size());
|
---|
| 94 | pointmap = CorrelationToPoint( allMolecules, elements, (const Vector *)point );
|
---|
[c4d4df] | 95 | binmap = NULL;
|
---|
| 96 |
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | void AnalysisCorrelationToPointUnitTest::tearDown()
|
---|
| 101 | {
|
---|
| 102 | if (pointmap != NULL)
|
---|
| 103 | delete(pointmap);
|
---|
| 104 | if (binmap != NULL)
|
---|
| 105 | delete(binmap);
|
---|
| 106 |
|
---|
| 107 | delete(point);
|
---|
[23b547] | 108 | World::purgeInstance();
|
---|
[e6fdbe] | 109 | logger::purgeInstance();
|
---|
[c4d4df] | 110 | };
|
---|
| 111 |
|
---|
| 112 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
|
---|
| 113 | {
|
---|
| 114 | // do the pair correlation
|
---|
| 115 | CPPUNIT_ASSERT( pointmap != NULL );
|
---|
| 116 | CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
|
---|
| 117 |
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
|
---|
| 121 | {
|
---|
| 122 | BinPairMap::iterator tester;
|
---|
| 123 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 124 | binmap = BinData( pointmap, 0.5, 0., 0. );
|
---|
[92e5cb] | 125 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
[3d9df5] | 126 | CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
|
---|
[c4d4df] | 127 | tester = binmap->begin();
|
---|
| 128 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 129 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 130 |
|
---|
| 131 | };
|
---|
| 132 |
|
---|
| 133 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
|
---|
| 134 | {
|
---|
| 135 | BinPairMap::iterator tester;
|
---|
| 136 | // ... and check with [0., 2.] range
|
---|
[e138de] | 137 | binmap = BinData( pointmap, 0.5, 0., 2. );
|
---|
[92e5cb] | 138 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
[c4d4df] | 139 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
| 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( 3, tester->second );
|
---|
| 145 |
|
---|
| 146 | };
|
---|