- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r4eb4fe rc6394d 24 24 #include "periodentafel.hpp" 25 25 #include "tesselation.hpp" 26 #include "World.hpp"27 28 #include "Helpers/Assert.hpp"29 30 #ifdef HAVE_TESTRUNNER31 #include "UnitTestMain.hpp"32 #endif /*HAVE_TESTRUNNER*/33 26 34 27 /********************************************** Test classes **************************************/ … … 39 32 void AnalysisCorrelationToSurfaceUnitTest::setUp() 40 33 { 41 //ASSERT_DO(Assert::Throw);42 43 34 atom *Walker = NULL; 44 35 45 36 // init private all pointers to zero 46 37 TestList = NULL; 47 TestSurfaceMolecule = NULL; 38 TestMolecule = NULL; 39 hydrogen = NULL; 40 tafel = NULL; 48 41 surfacemap = NULL; 49 42 binmap = NULL; … … 51 44 LC = NULL; 52 45 46 // construct element 47 hydrogen = new element; 48 hydrogen->Z = 1; 49 strcpy(hydrogen->name, "hydrogen"); 50 strcpy(hydrogen->symbol, "H"); 51 carbon = new element; 52 carbon->Z = 6; 53 strcpy(carbon->name, "carbon"); 54 strcpy(carbon->symbol, "C"); 55 56 // construct periodentafel 57 tafel = new periodentafel; 58 tafel->AddElement(hydrogen); 59 tafel->AddElement(carbon); 60 53 61 // construct molecule (tetraeder of hydrogens) base 54 hydrogen = World::getInstance().getPeriode()->FindElement(1); 55 TestSurfaceMolecule = World::getInstance().createMolecule(); 56 Walker = World::getInstance().createAtom(); 57 Walker->type = hydrogen; 58 *Walker->node = Vector(1., 0., 1. ); 59 60 TestSurfaceMolecule->AddAtom(Walker); 61 Walker = World::getInstance().createAtom(); 62 Walker->type = hydrogen; 63 *Walker->node = Vector(0., 1., 1. ); 64 TestSurfaceMolecule->AddAtom(Walker); 65 Walker = World::getInstance().createAtom(); 66 Walker->type = hydrogen; 67 *Walker->node = Vector(1., 1., 0. ); 68 TestSurfaceMolecule->AddAtom(Walker); 69 Walker = World::getInstance().createAtom(); 70 Walker->type = hydrogen; 71 *Walker->node = Vector(0., 0., 0. ); 72 TestSurfaceMolecule->AddAtom(Walker); 62 TestMolecule = new molecule(tafel); 63 Walker = new atom(); 64 Walker->type = hydrogen; 65 Walker->node->Init(1., 0., 1. ); 66 TestMolecule->AddAtom(Walker); 67 Walker = new atom(); 68 Walker->type = hydrogen; 69 Walker->node->Init(0., 1., 1. ); 70 TestMolecule->AddAtom(Walker); 71 Walker = new atom(); 72 Walker->type = hydrogen; 73 Walker->node->Init(1., 1., 0. ); 74 TestMolecule->AddAtom(Walker); 75 Walker = new atom(); 76 Walker->type = hydrogen; 77 Walker->node->Init(0., 0., 0. ); 78 TestMolecule->AddAtom(Walker); 73 79 74 80 // check that TestMolecule was correctly constructed 75 CPPUNIT_ASSERT_EQUAL( Test SurfaceMolecule->AtomCount, 4 );76 77 TestList = World::getInstance().getMolecules();78 Test SurfaceMolecule->ActiveFlag = true;79 TestList->insert(Test SurfaceMolecule);81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 82 83 TestList = new MoleculeListClass; 84 TestMolecule->ActiveFlag = true; 85 TestList->insert(TestMolecule); 80 86 81 87 // init tesselation and linked cell 82 88 Surface = new Tesselation; 83 LC = new LinkedCell(TestSurfaceMolecule, 5.); 84 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL); 89 FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL); 90 LC = new LinkedCell(TestMolecule, 5.); 91 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); 92 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() ); 93 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() ); 85 94 86 95 // add outer atoms 87 carbon = World::getInstance().getPeriode()->FindElement(6); 88 TestSurfaceMolecule = World::getInstance().createMolecule(); 89 Walker = World::getInstance().createAtom(); 90 Walker->type = carbon; 91 *Walker->node = Vector(4., 0., 4. ); 92 TestSurfaceMolecule->AddAtom(Walker); 93 Walker = World::getInstance().createAtom(); 94 Walker->type = carbon; 95 *Walker->node = Vector(0., 4., 4. ); 96 TestSurfaceMolecule->AddAtom(Walker); 97 Walker = World::getInstance().createAtom(); 98 Walker->type = carbon; 99 *Walker->node = Vector(4., 4., 0. ); 100 TestSurfaceMolecule->AddAtom(Walker); 96 Walker = new atom(); 97 Walker->type = carbon; 98 Walker->node->Init(4., 0., 4. ); 99 TestMolecule->AddAtom(Walker); 100 Walker = new atom(); 101 Walker->type = carbon; 102 Walker->node->Init(0., 4., 4. ); 103 TestMolecule->AddAtom(Walker); 104 Walker = new atom(); 105 Walker->type = carbon; 106 Walker->node->Init(4., 4., 0. ); 107 TestMolecule->AddAtom(Walker); 101 108 // add inner atoms 102 Walker = World::getInstance().createAtom(); 103 Walker->type = carbon; 104 *Walker->node = Vector(0.5, 0.5, 0.5 ); 105 TestSurfaceMolecule->AddAtom(Walker); 106 TestSurfaceMolecule->ActiveFlag = true; 107 TestList->insert(TestSurfaceMolecule); 109 Walker = new atom(); 110 Walker->type = carbon; 111 Walker->node->Init(0.5, 0.5, 0.5 ); 112 TestMolecule->AddAtom(Walker); 108 113 109 114 // init maps … … 121 126 delete(binmap); 122 127 128 // remove 129 delete(TestList); 123 130 delete(Surface); 124 131 // note that all the atoms are cleaned by TestMolecule 125 132 delete(LC); 126 World::purgeInstance(); 127 MemoryUsageObserver::purgeInstance(); 128 logger::purgeInstance(); 129 }; 130 131 132 /** Checks whether setup() does the right thing. 133 */ 134 void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest() 135 { 136 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount ); 137 CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() ); 138 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() ); 139 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() ); 140 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() ); 141 }; 133 delete(tafel); 134 // note that element is cleaned by periodentafel 135 }; 136 142 137 143 138 void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest() … … 145 140 // do the pair correlation 146 141 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 147 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );148 142 CPPUNIT_ASSERT( surfacemap != NULL ); 149 143 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() ); … … 155 149 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 156 150 // put pair correlation into bins and check with no range 157 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );158 151 binmap = BinData( surfacemap, 0.5, 0., 0. ); 159 152 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() ); 160 OutputCorrelation ( (ofstream *)&cout,binmap );153 //OutputCorrelation ( binmap ); 161 154 tester = binmap->begin(); 162 155 CPPUNIT_ASSERT_EQUAL( 0., tester->first ); … … 169 162 BinPairMap::iterator tester; 170 163 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 171 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );172 164 // ... and check with [0., 2.] range 173 165 binmap = BinData( surfacemap, 0.5, 0., 2. ); 174 166 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() ); 175 // OutputCorrelation ( (ofstream *)&cout,binmap );167 //OutputCorrelation ( binmap ); 176 168 tester = binmap->begin(); 177 169 CPPUNIT_ASSERT_EQUAL( 0., tester->first ); … … 187 179 BinPairMap::iterator tester; 188 180 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 189 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );190 181 // put pair correlation into bins and check with no range 191 182 binmap = BinData( surfacemap, 0.5, 0., 0. ); 192 //OutputCorrelation ( (ofstream *)&cout, binmap );183 OutputCorrelation ( (ofstream *)&cout, binmap ); 193 184 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() ); 194 185 // inside point is first and must have negative value 195 tester = binmap->lower_bound( 4.25-0.5); // start depends on the min value and186 tester = binmap->lower_bound(2.95); // start depends on the min value and 196 187 CPPUNIT_ASSERT( tester != binmap->end() ); 197 188 CPPUNIT_ASSERT_EQUAL( 3, tester->second ); 198 189 // inner point 199 tester = binmap->lower_bound( 0.);190 tester = binmap->lower_bound(-0.5); 200 191 CPPUNIT_ASSERT( tester != binmap->end() ); 201 192 CPPUNIT_ASSERT_EQUAL( 1, tester->second ); … … 206 197 BinPairMap::iterator tester; 207 198 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 208 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );209 199 // ... and check with [0., 2.] range 210 200 binmap = BinData( surfacemap, 0.5, -2., 4. ); 211 //OutputCorrelation ( (ofstream *)&cout, binmap );201 OutputCorrelation ( (ofstream *)&cout, binmap ); 212 202 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() ); 213 203 // three outside points 214 tester = binmap->lower_bound( 4.25-0.5);204 tester = binmap->lower_bound(3.); 215 205 CPPUNIT_ASSERT( tester != binmap->end() ); 216 206 CPPUNIT_ASSERT_EQUAL( 3, tester->second ); 217 207 // inner point 218 tester = binmap->lower_bound( 0.);208 tester = binmap->lower_bound(-0.5); 219 209 CPPUNIT_ASSERT( tester != binmap->end() ); 220 210 CPPUNIT_ASSERT_EQUAL( 1, tester->second ); 221 }; 211 212 }; 213 214 /********************************************** Main routine **************************************/ 215 216 int main(int argc, char **argv) 217 { 218 // Get the top level suite from the registry 219 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); 220 221 // Adds the test to the list of test to run 222 CppUnit::TextUi::TestRunner runner; 223 runner.addTest( suite ); 224 225 // Change the default outputter to a compiler error format outputter 226 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), 227 std::cerr ) ); 228 // Run the tests. 229 bool wasSucessful = runner.run(); 230 231 // Return error code 1 if the one of test failed. 232 return wasSucessful ? 0 : 1; 233 };
Note:
See TracChangeset
for help on using the changeset viewer.