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 |
|
---|
14 | #include "analysis_correlation.hpp"
|
---|
15 | #include "AnalysisCorrelationToPointUnitTest.hpp"
|
---|
16 |
|
---|
17 | #include "atom.hpp"
|
---|
18 | #include "boundary.hpp"
|
---|
19 | #include "element.hpp"
|
---|
20 | #include "molecule.hpp"
|
---|
21 | #include "linkedcell.hpp"
|
---|
22 | #include "periodentafel.hpp"
|
---|
23 | #include "tesselation.hpp"
|
---|
24 |
|
---|
25 | /********************************************** Test classes **************************************/
|
---|
26 |
|
---|
27 | // Registers the fixture into the 'registry'
|
---|
28 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToPointUnitTest );
|
---|
29 |
|
---|
30 | void AnalysisCorrelationToPointUnitTest::setUp()
|
---|
31 | {
|
---|
32 | atom *Walker = NULL;
|
---|
33 |
|
---|
34 | // init private all pointers to zero
|
---|
35 | TestList = NULL;
|
---|
36 | TestMolecule = NULL;
|
---|
37 | hydrogen = NULL;
|
---|
38 | tafel = NULL;
|
---|
39 | pointmap = NULL;
|
---|
40 | binmap = NULL;
|
---|
41 | point = NULL;
|
---|
42 |
|
---|
43 | // construct element
|
---|
44 | hydrogen = new element;
|
---|
45 | hydrogen->Z = 1;
|
---|
46 | strcpy(hydrogen->name, "hydrogen");
|
---|
47 | strcpy(hydrogen->symbol, "H");
|
---|
48 |
|
---|
49 |
|
---|
50 | // construct periodentafel
|
---|
51 | tafel = new periodentafel;
|
---|
52 | tafel->AddElement(hydrogen);
|
---|
53 |
|
---|
54 | // construct molecule (tetraeder of hydrogens)
|
---|
55 | TestMolecule = new molecule(tafel);
|
---|
56 | Walker = new atom();
|
---|
57 | Walker->type = hydrogen;
|
---|
58 | Walker->node->Init(1., 0., 1. );
|
---|
59 | TestMolecule->AddAtom(Walker);
|
---|
60 | Walker = new atom();
|
---|
61 | Walker->type = hydrogen;
|
---|
62 | Walker->node->Init(0., 1., 1. );
|
---|
63 | TestMolecule->AddAtom(Walker);
|
---|
64 | Walker = new atom();
|
---|
65 | Walker->type = hydrogen;
|
---|
66 | Walker->node->Init(1., 1., 0. );
|
---|
67 | TestMolecule->AddAtom(Walker);
|
---|
68 | Walker = new atom();
|
---|
69 | Walker->type = hydrogen;
|
---|
70 | Walker->node->Init(0., 0., 0. );
|
---|
71 | TestMolecule->AddAtom(Walker);
|
---|
72 |
|
---|
73 | // check that TestMolecule was correctly constructed
|
---|
74 | CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
|
---|
75 |
|
---|
76 | TestList = new MoleculeListClass;
|
---|
77 | TestMolecule->ActiveFlag = true;
|
---|
78 | TestList->insert(TestMolecule);
|
---|
79 |
|
---|
80 | // init point
|
---|
81 | point = new Vector(1.,1.,1.);
|
---|
82 |
|
---|
83 | // init maps
|
---|
84 | pointmap = CorrelationToPoint( (MoleculeListClass * const)TestList, (const element * const)hydrogen, (const Vector *)point );
|
---|
85 | binmap = NULL;
|
---|
86 |
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 | void AnalysisCorrelationToPointUnitTest::tearDown()
|
---|
91 | {
|
---|
92 | if (pointmap != NULL)
|
---|
93 | delete(pointmap);
|
---|
94 | if (binmap != NULL)
|
---|
95 | delete(binmap);
|
---|
96 |
|
---|
97 | // remove
|
---|
98 | delete(TestList);
|
---|
99 | // note that all the atoms are cleaned by TestMolecule
|
---|
100 | delete(point);
|
---|
101 | delete(tafel);
|
---|
102 | // note that element is cleaned by periodentafel
|
---|
103 | };
|
---|
104 |
|
---|
105 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointTest()
|
---|
106 | {
|
---|
107 | // do the pair correlation
|
---|
108 | CPPUNIT_ASSERT( pointmap != NULL );
|
---|
109 | CPPUNIT_ASSERT_EQUAL( (size_t)4, pointmap->size() );
|
---|
110 |
|
---|
111 | };
|
---|
112 |
|
---|
113 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinNoRangeTest()
|
---|
114 | {
|
---|
115 | BinPairMap::iterator tester;
|
---|
116 | // put pair correlation into bins and check with no range
|
---|
117 | binmap = BinData( pointmap, 0.5, 0., 0. );
|
---|
118 | CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
|
---|
119 | //OutputCorrelation ( binmap );
|
---|
120 | tester = binmap->begin();
|
---|
121 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
122 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
123 |
|
---|
124 | };
|
---|
125 |
|
---|
126 | void AnalysisCorrelationToPointUnitTest::CorrelationToPointBinRangeTest()
|
---|
127 | {
|
---|
128 | BinPairMap::iterator tester;
|
---|
129 | // ... and check with [0., 2.] range
|
---|
130 | binmap = BinData( pointmap, 0.5, 0., 2. );
|
---|
131 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
132 | //OutputCorrelation ( binmap );
|
---|
133 | tester = binmap->begin();
|
---|
134 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
135 | tester = binmap->find(1.);
|
---|
136 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
137 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
138 |
|
---|
139 | };
|
---|
140 |
|
---|
141 | /********************************************** Main routine **************************************/
|
---|
142 |
|
---|
143 | int main(int argc, char **argv)
|
---|
144 | {
|
---|
145 | // Get the top level suite from the registry
|
---|
146 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
---|
147 |
|
---|
148 | // Adds the test to the list of test to run
|
---|
149 | CppUnit::TextUi::TestRunner runner;
|
---|
150 | runner.addTest( suite );
|
---|
151 |
|
---|
152 | // Change the default outputter to a compiler error format outputter
|
---|
153 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
|
---|
154 | std::cerr ) );
|
---|
155 | // Run the tests.
|
---|
156 | bool wasSucessful = runner.run();
|
---|
157 |
|
---|
158 | // Return error code 1 if the one of test failed.
|
---|
159 | return wasSucessful ? 0 : 1;
|
---|
160 | };
|
---|