- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/LinkedCellUnitTest.cpp
r4f9e47 r68f03d 22 22 #include "periodentafel.hpp" 23 23 #include "LinkedCellUnitTest.hpp" 24 #include "World.hpp" 25 26 #ifdef HAVE_TESTRUNNER 27 #include "UnitTestMain.hpp" 28 #endif /*HAVE_TESTRUNNER*/ 24 29 25 30 /********************************************** Test classes **************************************/ … … 46 51 47 52 // construct periodentafel 48 tafel = new periodentafel;53 tafel = World::getInstance().getPeriode(); 49 54 tafel->AddElement(hydrogen); 50 55 51 56 // construct molecule (water molecule) 52 TestMolecule = new molecule(tafel);57 TestMolecule = World::getInstance().createMolecule(); 53 58 for (double x=0.5;x<3;x+=1.) 54 59 for (double y=0.5;y<3;y+=1.) 55 60 for (double z=0.5;z<3;z+=1.) { 56 Walker = new atom();61 Walker = World::getInstance().createAtom(); 57 62 Walker->type = hydrogen; 58 Walker->node->Init(x, y, z );63 *Walker->node = Vector(x, y, z ); 59 64 TestMolecule->AddAtom(Walker); 60 65 } … … 73 78 { 74 79 delete(LC); 75 delete(TestMolecule); 76 // note that all the atoms are cleaned by TestMolecule 77 delete(tafel); 78 // note that element is cleaned by periodentafel 80 World::purgeInstance(); 81 MemoryUsageObserver::purgeInstance(); 79 82 }; 80 83 … … 201 204 202 205 // check internal vectors, returns false, because this atom is not in LC-list! 203 Walker = new atom(); 204 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 205 strcpy(Walker->Name, "test"); 206 Walker->x.Init(1,1,1); 206 Walker = World::getInstance().createAtom(); 207 Walker->setName("test"); 208 Walker->x= Vector(1,1,1); 207 209 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 208 delete(Walker);210 World::getInstance().destroyAtom(Walker); 209 211 210 212 // check out of bounds vectors 211 Walker = new atom(); 212 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker"); 213 strcpy(Walker->Name, "test"); 214 Walker->x.Init(0,-1,0); 213 Walker = World::getInstance().createAtom(); 214 Walker->setName("test"); 215 Walker->x = Vector(0,-1,0); 215 216 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 216 delete(Walker);217 World::getInstance().destroyAtom(Walker); 217 218 }; 218 219 … … 228 229 for (double y=0.5;y<3;y+=1.) 229 230 for (double z=0.5;z<3;z+=1.) { 230 tester .Init(x,y,z);231 tester = Vector(x,y,z); 231 232 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); 232 233 } … … 235 236 for (double y=1.;y<4;y+=1.) 236 237 for (double z=1.;z<4;z+=1.) { 237 tester .Init(x,y,z);238 tester= Vector(x,y,z); 238 239 cout << "Tester is at " << tester << "." << endl; 239 240 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); … … 243 244 for (double y=0.5-1e-10;y<5;y+=3.1) 244 245 for (double z=0.5-1e-10;z<5;z+=3.1) { 245 tester .Init(x,y,z);246 tester = Vector(x,y,z); 246 247 cout << "The following test is supposed to fail and produce an ERROR." << endl; 247 248 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); 248 249 } 249 250 // check nonsense vectors 250 tester .Init(-423598,3245978,29349);251 tester= Vector(-423598,3245978,29349); 251 252 cout << "The following test is supposed to fail and produce an ERROR." << endl; 252 253 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); … … 261 262 int lower[NDIM], upper[NDIM]; 262 263 263 tester .Init(0.5,0.5,0.5);264 tester= Vector(0.5,0.5,0.5); 264 265 LC->SetIndexToVector(&tester); 265 266 LC->GetNeighbourBounds(lower, upper); … … 281 282 282 283 // get all atoms 283 tester .Init(1.5,1.5,1.5);284 tester= Vector(1.5,1.5,1.5); 284 285 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 285 286 ListOfPoints = LC->GetallNeighbours(); … … 300 301 301 302 // get all atoms in one corner 302 tester .Init(0.5, 0.5, 0.5);303 tester= Vector(0.5, 0.5, 0.5); 303 304 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 304 305 ListOfPoints = LC->GetallNeighbours(); … … 308 309 while (Walker->next != TestMolecule->end) { 309 310 Walker = Walker->next; 310 if ((Walker->x .x[0] <2) && (Walker->x.x[1] <2) && (Walker->x.x[2] <2)) {311 if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) { 311 312 ListOfPoints->remove(Walker); 312 313 size--; … … 320 321 321 322 // get all atoms from one corner 322 tester .Init(0.5, 0.5, 0.5);323 tester = Vector(0.5, 0.5, 0.5); 323 324 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 324 325 ListOfPoints = LC->GetallNeighbours(3); … … 349 350 350 351 // get all points around central arom with radius 1. 351 tester .Init(1.5,1.5,1.5);352 tester= Vector(1.5,1.5,1.5); 352 353 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 353 354 ListOfPoints = LC->GetPointsInsideSphere(1., &tester); … … 357 358 while (Walker->next != TestMolecule->end) { 358 359 Walker = Walker->next; 359 if ((Walker->x.DistanceSquared( &tester) - 1.) < MYEPSILON ) {360 if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) { 360 361 ListOfPoints->remove(Walker); 361 362 size--; … … 368 369 delete(ListOfPoints); 369 370 }; 370 371 /********************************************** Main routine **************************************/372 373 int main(int argc, char **argv)374 {375 // Get the top level suite from the registry376 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();377 378 // Adds the test to the list of test to run379 CppUnit::TextUi::TestRunner runner;380 runner.addTest( suite );381 382 // Change the default outputter to a compiler error format outputter383 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),384 std::cerr ) );385 // Run the tests.386 bool wasSucessful = runner.run();387 388 // Return error code 1 if the one of test failed.389 return wasSucessful ? 0 : 1;390 };391
Note:
See TracChangeset
for help on using the changeset viewer.