[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[bcf653] | 21 | */
|
---|
| 22 |
|
---|
[c4d4df] | 23 | /*
|
---|
| 24 | * AnalysisCorrelationToPointUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Oct 13, 2009
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[bf3817] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[c4d4df] | 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
[49e1ae] | 41 | #include <cstring>
|
---|
| 42 |
|
---|
[9b5a2c] | 43 | #include "Analysis/analysis_correlation.hpp"
|
---|
[6f0841] | 44 | #include "Atom/atom.hpp"
|
---|
[53c7fc] | 45 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
[3bdb6d] | 46 | #include "Element/element.hpp"
|
---|
[53c7fc] | 47 | #include "Element/periodentafel.hpp"
|
---|
[c4d4df] | 48 | #include "molecule.hpp"
|
---|
[e6fdbe] | 49 | #include "World.hpp"
|
---|
[c4d4df] | 50 |
|
---|
[f844ef] | 51 | #include "AnalysisCorrelationToPointUnitTest.hpp"
|
---|
| 52 |
|
---|
[9b6b2f] | 53 | #ifdef HAVE_TESTRUNNER
|
---|
| 54 | #include "UnitTestMain.hpp"
|
---|
| 55 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 56 |
|
---|
| 57 | /********************************************** Test classes **************************************/
|
---|
| 58 |
|
---|
| 59 | // Registers the fixture into the 'registry'
|
---|
| 60 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
|
---|
| 61 |
|
---|
| 62 | void AnalysisCorrelationToPointUnitTest::setUp()
|
---|
| 63 | {
|
---|
| 64 | atom *Walker = NULL;
|
---|
| 65 |
|
---|
| 66 | // init private all pointers to zero
|
---|
| 67 | TestMolecule = NULL;
|
---|
| 68 | pointmap = NULL;
|
---|
| 69 | binmap = NULL;
|
---|
| 70 | point = NULL;
|
---|
| 71 |
|
---|
[c78d44] | 72 | // construct element list
|
---|
[e5c0a1] | 73 | std::vector<const element *> elements;
|
---|
[4eb4fe] | 74 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
| 75 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
[c78d44] | 76 | elements.push_back(hydrogen);
|
---|
| 77 | // construct molecule (tetraeder of hydrogens)
|
---|
[23b547] | 78 | TestMolecule = World::getInstance().createMolecule();
|
---|
| 79 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 80 | Walker->setType(hydrogen);
|
---|
| 81 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
[c4d4df] | 82 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 83 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 84 | Walker->setType(hydrogen);
|
---|
| 85 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
[c4d4df] | 86 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 87 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 88 | Walker->setType(hydrogen);
|
---|
| 89 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
[c4d4df] | 90 | TestMolecule->AddAtom(Walker);
|
---|
[23b547] | 91 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 92 | Walker->setType(hydrogen);
|
---|
| 93 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
[c4d4df] | 94 | TestMolecule->AddAtom(Walker);
|
---|
| 95 |
|
---|
| 96 | // check that TestMolecule was correctly constructed
|
---|
[ea7176] | 97 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 98 |
|
---|
[5f612ee] | 99 | TestMolecule->ActiveFlag = true;
|
---|
[a5551b] | 100 |
|
---|
[c4d4df] | 101 | // init point
|
---|
| 102 | point = new Vector(1.,1.,1.);
|
---|
| 103 |
|
---|
| 104 | // init maps
|
---|
[e65de8] | 105 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
[99db9b] | 106 | allMolecules = const_cast<const World &>(World::getInstance()).getSelectedMolecules();
|
---|
[e65de8] | 107 | CPPUNIT_ASSERT_EQUAL( (size_t) 1, allMolecules.size());
|
---|
| 108 | pointmap = CorrelationToPoint( allMolecules, elements, (const Vector *)point );
|
---|
[c4d4df] | 109 | binmap = NULL;
|
---|
| 110 |
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | void AnalysisCorrelationToPointUnitTest::tearDown()
|
---|
| 115 | {
|
---|
| 116 | if (pointmap != NULL)
|
---|
| 117 | delete(pointmap);
|
---|
| 118 | if (binmap != NULL)
|
---|
| 119 | delete(binmap);
|
---|
| 120 |
|
---|
| 121 | delete(point);
|
---|
[23b547] | 122 | World::purgeInstance();
|
---|
[e6fdbe] | 123 | logger::purgeInstance();
|
---|
[c4d4df] | 124 | };
|
---|
| 125 |
|
---|
| 126 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
|
---|
| 127 | {
|
---|
| 128 | // do the pair correlation
|
---|
| 129 | CPPUNIT_ASSERT( pointmap != NULL );
|
---|
| 130 | CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
|
---|
| 131 |
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
|
---|
| 135 | {
|
---|
| 136 | BinPairMap::iterator tester;
|
---|
| 137 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 138 | binmap = BinData( pointmap, 0.5, 0., 0. );
|
---|
[92e5cb] | 139 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
[3d9df5] | 140 | CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
|
---|
[c4d4df] | 141 | tester = binmap->begin();
|
---|
| 142 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 143 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 144 |
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
|
---|
| 148 | {
|
---|
| 149 | BinPairMap::iterator tester;
|
---|
| 150 | // ... and check with [0., 2.] range
|
---|
[e138de] | 151 | binmap = BinData( pointmap, 0.5, 0., 2. );
|
---|
[92e5cb] | 152 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
[c4d4df] | 153 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
| 154 | tester = binmap->begin();
|
---|
| 155 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 156 | tester = binmap->find(1.);
|
---|
| 157 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 158 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 159 |
|
---|
| 160 | };
|
---|