- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
rc6394d r4eb4fe 24 24 #include "periodentafel.hpp" 25 25 #include "tesselation.hpp" 26 #include "World.hpp" 27 28 #include "Helpers/Assert.hpp" 29 30 #ifdef HAVE_TESTRUNNER 31 #include "UnitTestMain.hpp" 32 #endif /*HAVE_TESTRUNNER*/ 26 33 27 34 /********************************************** Test classes **************************************/ … … 32 39 void AnalysisCorrelationToSurfaceUnitTest::setUp() 33 40 { 41 //ASSERT_DO(Assert::Throw); 42 34 43 atom *Walker = NULL; 35 44 36 45 // init private all pointers to zero 37 46 TestList = NULL; 38 TestMolecule = NULL; 39 hydrogen = NULL; 40 tafel = NULL; 47 TestSurfaceMolecule = NULL; 41 48 surfacemap = NULL; 42 49 binmap = NULL; … … 44 51 LC = NULL; 45 52 46 // construct element47 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 periodentafel57 tafel = new periodentafel;58 tafel->AddElement(hydrogen);59 tafel->AddElement(carbon);60 61 53 // construct molecule (tetraeder of hydrogens) base 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); 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); 79 73 80 74 // check that TestMolecule was correctly constructed 81 CPPUNIT_ASSERT_EQUAL( Test Molecule->AtomCount, 4 );82 83 TestList = new MoleculeListClass;84 Test Molecule->ActiveFlag = true;85 TestList->insert(Test Molecule);75 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 ); 76 77 TestList = World::getInstance().getMolecules(); 78 TestSurfaceMolecule->ActiveFlag = true; 79 TestList->insert(TestSurfaceMolecule); 86 80 87 81 // init tesselation and linked cell 88 82 Surface = new Tesselation; 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() ); 83 LC = new LinkedCell(TestSurfaceMolecule, 5.); 84 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL); 94 85 95 86 // add outer atoms 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); 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); 108 101 // add inner atoms 109 Walker = new atom(); 110 Walker->type = carbon; 111 Walker->node->Init(0.5, 0.5, 0.5 ); 112 TestMolecule->AddAtom(Walker); 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); 113 108 114 109 // init maps … … 126 121 delete(binmap); 127 122 128 // remove129 delete(TestList);130 123 delete(Surface); 131 124 // note that all the atoms are cleaned by TestMolecule 132 125 delete(LC); 133 delete(tafel); 134 // note that element is cleaned by periodentafel 135 }; 136 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 }; 137 142 138 143 void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest() … … 140 145 // do the pair correlation 141 146 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 147 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 142 148 CPPUNIT_ASSERT( surfacemap != NULL ); 143 149 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() ); … … 149 155 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 150 156 // put pair correlation into bins and check with no range 157 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 151 158 binmap = BinData( surfacemap, 0.5, 0., 0. ); 152 159 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() ); 153 //OutputCorrelation (binmap );160 OutputCorrelation ( (ofstream *)&cout, binmap ); 154 161 tester = binmap->begin(); 155 162 CPPUNIT_ASSERT_EQUAL( 0., tester->first ); … … 162 169 BinPairMap::iterator tester; 163 170 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC ); 171 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 164 172 // ... and check with [0., 2.] range 165 173 binmap = BinData( surfacemap, 0.5, 0., 2. ); 166 174 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() ); 167 //OutputCorrelation (binmap );175 // OutputCorrelation ( (ofstream *)&cout, binmap ); 168 176 tester = binmap->begin(); 169 177 CPPUNIT_ASSERT_EQUAL( 0., tester->first ); … … 179 187 BinPairMap::iterator tester; 180 188 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 189 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 181 190 // put pair correlation into bins and check with no range 182 191 binmap = BinData( surfacemap, 0.5, 0., 0. ); 183 OutputCorrelation ( (ofstream *)&cout, binmap );192 //OutputCorrelation ( (ofstream *)&cout, binmap ); 184 193 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() ); 185 194 // inside point is first and must have negative value 186 tester = binmap->lower_bound( 2.95); // start depends on the min value and195 tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and 187 196 CPPUNIT_ASSERT( tester != binmap->end() ); 188 197 CPPUNIT_ASSERT_EQUAL( 3, tester->second ); 189 198 // inner point 190 tester = binmap->lower_bound( -0.5);199 tester = binmap->lower_bound(0.); 191 200 CPPUNIT_ASSERT( tester != binmap->end() ); 192 201 CPPUNIT_ASSERT_EQUAL( 1, tester->second ); … … 197 206 BinPairMap::iterator tester; 198 207 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC ); 208 // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap ); 199 209 // ... and check with [0., 2.] range 200 210 binmap = BinData( surfacemap, 0.5, -2., 4. ); 201 OutputCorrelation ( (ofstream *)&cout, binmap );211 //OutputCorrelation ( (ofstream *)&cout, binmap ); 202 212 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() ); 203 213 // three outside points 204 tester = binmap->lower_bound( 3.);214 tester = binmap->lower_bound(4.25-0.5); 205 215 CPPUNIT_ASSERT( tester != binmap->end() ); 206 216 CPPUNIT_ASSERT_EQUAL( 3, tester->second ); 207 217 // inner point 208 tester = binmap->lower_bound( -0.5);218 tester = binmap->lower_bound(0.); 209 219 CPPUNIT_ASSERT( tester != binmap->end() ); 210 220 CPPUNIT_ASSERT_EQUAL( 1, tester->second ); 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 }; 221 };
Note:
See TracChangeset
for help on using the changeset viewer.