source: molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp@ dc5413

Last change on this file since dc5413 was dc5413, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[57cfb7]1/*
2 * AnalysisCorrelationToPointUnitTest.cpp
3 *
4 * Created on: Oct 13, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
[e6fe8a]14#include <cstring>
15
[57cfb7]16#include "analysis_correlation.hpp"
17#include "AnalysisCorrelationToPointUnitTest.hpp"
18
[7bfc19]19#include "World.hpp"
[57cfb7]20#include "atom.hpp"
21#include "boundary.hpp"
22#include "element.hpp"
23#include "molecule.hpp"
24#include "linkedcell.hpp"
25#include "periodentafel.hpp"
26#include "tesselation.hpp"
[45cc89]27#include "World.hpp"
[57cfb7]28
[44becc]29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
[57cfb7]32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
37
38void AnalysisCorrelationToPointUnitTest::setUp()
39{
40 atom *Walker = NULL;
41
42 // init private all pointers to zero
[e1900f]43 TestList = NULL;
[57cfb7]44 TestMolecule = NULL;
45 hydrogen = NULL;
46 tafel = NULL;
47 pointmap = NULL;
48 binmap = NULL;
49 point = NULL;
50
51 // construct element
52 hydrogen = new element;
53 hydrogen->Z = 1;
54 strcpy(hydrogen->name, "hydrogen");
[13ecff]55 strcpy(hydrogen->symbol, "H");
56
[57cfb7]57
58 // construct periodentafel
[8d9d38]59 tafel = World::get()->getPeriode();
[57cfb7]60 tafel->AddElement(hydrogen);
61
62 // construct molecule (tetraeder of hydrogens)
[8d9d38]63 TestMolecule = World::get()->createMolecule();
[7bfc19]64 Walker = World::get()->createAtom();
[57cfb7]65 Walker->type = hydrogen;
66 Walker->node->Init(1., 0., 1. );
67 TestMolecule->AddAtom(Walker);
[7bfc19]68 Walker = World::get()->createAtom();
[57cfb7]69 Walker->type = hydrogen;
70 Walker->node->Init(0., 1., 1. );
71 TestMolecule->AddAtom(Walker);
[7bfc19]72 Walker = World::get()->createAtom();
[57cfb7]73 Walker->type = hydrogen;
74 Walker->node->Init(1., 1., 0. );
75 TestMolecule->AddAtom(Walker);
[7bfc19]76 Walker = World::get()->createAtom();
[57cfb7]77 Walker->type = hydrogen;
78 Walker->node->Init(0., 0., 0. );
79 TestMolecule->AddAtom(Walker);
80
81 // check that TestMolecule was correctly constructed
82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
83
[8d9d38]84 TestList = World::get()->getMolecules();
[e1900f]85 TestMolecule->ActiveFlag = true;
86 TestList->insert(TestMolecule);
87
[57cfb7]88 // init point
89 point = new Vector(1.,1.,1.);
90
91 // init maps
[543ce4]92 pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, (const element * const)hydrogen, (const Vector *)point );
[57cfb7]93 binmap = NULL;
94
95};
96
97
98void AnalysisCorrelationToPointUnitTest::tearDown()
99{
100 if (pointmap != NULL)
101 delete(pointmap);
102 if (binmap != NULL)
103 delete(binmap);
104
105 delete(point);
[8d9d38]106 World::destroy();
[45cc89]107 MemoryUsageObserver::purgeInstance();
108 logger::purgeInstance();
[57cfb7]109};
110
111void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
112{
113 // do the pair correlation
114 CPPUNIT_ASSERT( pointmap != NULL );
115 CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
116
117};
118
119void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
120{
121 BinPairMap::iterator tester;
122 // put pair correlation into bins and check with no range
[543ce4]123 binmap = BinData( pointmap, 0.5, 0., 0. );
[57cfb7]124 CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
[543ce4]125 //OutputCorrelation ( binmap );
[57cfb7]126 tester = binmap->begin();
127 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
128 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
129
130};
131
132void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
133{
134 BinPairMap::iterator tester;
135 // ... and check with [0., 2.] range
[543ce4]136 binmap = BinData( pointmap, 0.5, 0., 2. );
[57cfb7]137 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
[543ce4]138 //OutputCorrelation ( binmap );
[57cfb7]139 tester = binmap->begin();
140 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
141 tester = binmap->find(1.);
142 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
143 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
144
145};
Note: See TracBrowser for help on using the repository browser.