[c4d4df] | 1 | /*
|
---|
| 2 | * AnalysisCorrelationToSurfaceUnitTest.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 "AnalysisCorrelationToSurfaceUnitTest.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( AnalysisCorrelationToSurfaceUnitTest );
|
---|
| 29 |
|
---|
| 30 | void AnalysisCorrelationToSurfaceUnitTest::setUp()
|
---|
| 31 | {
|
---|
| 32 | atom *Walker = NULL;
|
---|
| 33 |
|
---|
| 34 | // init private all pointers to zero
|
---|
| 35 | TestMolecule = NULL;
|
---|
| 36 | hydrogen = NULL;
|
---|
| 37 | tafel = NULL;
|
---|
| 38 | surfacemap = NULL;
|
---|
| 39 | binmap = NULL;
|
---|
| 40 | Surface = NULL;
|
---|
| 41 | LC = NULL;
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | // construct element
|
---|
| 45 | hydrogen = new element;
|
---|
| 46 | hydrogen->Z = 1;
|
---|
| 47 | strcpy(hydrogen->name, "hydrogen");
|
---|
[bbc338] | 48 | strcpy(hydrogen->symbol, "H");
|
---|
| 49 | carbon = new element;
|
---|
| 50 | carbon->Z = 6;
|
---|
| 51 | strcpy(carbon->name, "carbon");
|
---|
| 52 | strcpy(carbon->symbol, "C");
|
---|
[c4d4df] | 53 |
|
---|
| 54 | // construct periodentafel
|
---|
| 55 | tafel = new periodentafel;
|
---|
| 56 | tafel->AddElement(hydrogen);
|
---|
[bbc338] | 57 | tafel->AddElement(carbon);
|
---|
[c4d4df] | 58 |
|
---|
[bbc338] | 59 | // construct molecule (tetraeder of hydrogens) base
|
---|
[c4d4df] | 60 | TestMolecule = new molecule(tafel);
|
---|
| 61 | Walker = new atom();
|
---|
| 62 | Walker->type = hydrogen;
|
---|
| 63 | Walker->node->Init(1., 0., 1. );
|
---|
| 64 | TestMolecule->AddAtom(Walker);
|
---|
| 65 | Walker = new atom();
|
---|
| 66 | Walker->type = hydrogen;
|
---|
| 67 | Walker->node->Init(0., 1., 1. );
|
---|
| 68 | TestMolecule->AddAtom(Walker);
|
---|
| 69 | Walker = new atom();
|
---|
| 70 | Walker->type = hydrogen;
|
---|
| 71 | Walker->node->Init(1., 1., 0. );
|
---|
| 72 | TestMolecule->AddAtom(Walker);
|
---|
| 73 | Walker = new atom();
|
---|
| 74 | Walker->type = hydrogen;
|
---|
| 75 | Walker->node->Init(0., 0., 0. );
|
---|
| 76 | TestMolecule->AddAtom(Walker);
|
---|
| 77 |
|
---|
| 78 | // check that TestMolecule was correctly constructed
|
---|
| 79 | CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
|
---|
| 80 |
|
---|
| 81 | // init tesselation and linked cell
|
---|
| 82 | Surface = new Tesselation;
|
---|
| 83 | TestMolecule->TesselStruct = Surface;
|
---|
[bbc338] | 84 | FindNonConvexBorder((ofstream *)&cerr, TestMolecule, LC, 2.5, NULL);
|
---|
[c4d4df] | 85 | LC = new LinkedCell(TestMolecule, 5.);
|
---|
| 86 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
| 87 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
| 88 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
| 89 |
|
---|
[bbc338] | 90 | // add outer atoms
|
---|
| 91 | Walker = new atom();
|
---|
| 92 | Walker->type = carbon;
|
---|
| 93 | Walker->node->Init(4., 0., 4. );
|
---|
| 94 | TestMolecule->AddAtom(Walker);
|
---|
| 95 | Walker = new atom();
|
---|
| 96 | Walker->type = carbon;
|
---|
| 97 | Walker->node->Init(0., 4., 4. );
|
---|
| 98 | TestMolecule->AddAtom(Walker);
|
---|
| 99 | Walker = new atom();
|
---|
| 100 | Walker->type = carbon;
|
---|
| 101 | Walker->node->Init(4., 4., 0. );
|
---|
| 102 | TestMolecule->AddAtom(Walker);
|
---|
| 103 | // add inner atoms
|
---|
| 104 | Walker = new atom();
|
---|
| 105 | Walker->type = carbon;
|
---|
| 106 | Walker->node->Init(0.5, 0.5, 0.5 );
|
---|
| 107 | TestMolecule->AddAtom(Walker);
|
---|
| 108 |
|
---|
[c4d4df] | 109 | // init maps
|
---|
[bbc338] | 110 | surfacemap = NULL;
|
---|
[c4d4df] | 111 | binmap = NULL;
|
---|
| 112 |
|
---|
| 113 | };
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
| 117 | {
|
---|
| 118 | if (surfacemap != NULL)
|
---|
| 119 | delete(surfacemap);
|
---|
| 120 | if (binmap != NULL)
|
---|
| 121 | delete(binmap);
|
---|
| 122 |
|
---|
| 123 | // remove
|
---|
| 124 | delete(TestMolecule);
|
---|
| 125 | // note that Surface and all the atoms are cleaned by TestMolecule
|
---|
| 126 | delete(LC);
|
---|
| 127 | delete(tafel);
|
---|
| 128 | // note that element is cleaned by periodentafel
|
---|
| 129 | };
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
| 133 | {
|
---|
| 134 | // do the pair correlation
|
---|
[bbc338] | 135 | surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
|
---|
[c4d4df] | 136 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
| 137 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
| 138 | };
|
---|
| 139 |
|
---|
[bbc338] | 140 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
[c4d4df] | 141 | {
|
---|
| 142 | BinPairMap::iterator tester;
|
---|
[bbc338] | 143 | surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
|
---|
[c4d4df] | 144 | // put pair correlation into bins and check with no range
|
---|
| 145 | binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 0. );
|
---|
| 146 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
| 147 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 148 | tester = binmap->begin();
|
---|
| 149 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 150 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 151 |
|
---|
| 152 | };
|
---|
| 153 |
|
---|
[bbc338] | 154 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
[c4d4df] | 155 | {
|
---|
| 156 | BinPairMap::iterator tester;
|
---|
[bbc338] | 157 | surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
|
---|
[c4d4df] | 158 | // ... and check with [0., 2.] range
|
---|
| 159 | binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 2. );
|
---|
| 160 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
| 161 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 162 | tester = binmap->begin();
|
---|
| 163 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 164 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 165 | tester = binmap->find(1.);
|
---|
| 166 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 167 | CPPUNIT_ASSERT_EQUAL( 0, tester->second );
|
---|
| 168 |
|
---|
| 169 | };
|
---|
| 170 |
|
---|
[bbc338] | 171 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
| 172 | {
|
---|
| 173 | BinPairMap::iterator tester;
|
---|
| 174 | surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, carbon, Surface, LC );
|
---|
| 175 | // put pair correlation into bins and check with no range
|
---|
| 176 | binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 0. );
|
---|
| 177 | CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
|
---|
| 178 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 179 | // inside point is first and must have negative value
|
---|
| 180 | tester = binmap->lower_bound(2.95); // start depends on the min value and
|
---|
| 181 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 182 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 183 | // inner point
|
---|
| 184 | tester = binmap->lower_bound(0.);
|
---|
| 185 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 186 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 187 | };
|
---|
| 188 |
|
---|
| 189 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
| 190 | {
|
---|
| 191 | BinPairMap::iterator tester;
|
---|
| 192 | surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, carbon, Surface, LC );
|
---|
| 193 | // ... and check with [0., 2.] range
|
---|
| 194 | binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, -2., 4. );
|
---|
| 195 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
| 196 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
| 197 | // three outside points
|
---|
| 198 | tester = binmap->find(3.);
|
---|
| 199 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 200 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 201 | // inner point
|
---|
| 202 | tester = binmap->find(0.);
|
---|
| 203 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 204 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 205 |
|
---|
| 206 | };
|
---|
| 207 |
|
---|
[c4d4df] | 208 | /********************************************** Main routine **************************************/
|
---|
| 209 |
|
---|
| 210 | int main(int argc, char **argv)
|
---|
| 211 | {
|
---|
| 212 | // Get the top level suite from the registry
|
---|
| 213 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
---|
| 214 |
|
---|
| 215 | // Adds the test to the list of test to run
|
---|
| 216 | CppUnit::TextUi::TestRunner runner;
|
---|
| 217 | runner.addTest( suite );
|
---|
| 218 |
|
---|
| 219 | // Change the default outputter to a compiler error format outputter
|
---|
| 220 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
|
---|
| 221 | std::cerr ) );
|
---|
| 222 | // Run the tests.
|
---|
| 223 | bool wasSucessful = runner.run();
|
---|
| 224 |
|
---|
| 225 | // Return error code 1 if the one of test failed.
|
---|
| 226 | return wasSucessful ? 0 : 1;
|
---|
| 227 | };
|
---|