- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/LinkedCellUnitTest.cpp
r4f9e47 r920c70 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 **************************************/ … … 33 38 atom *Walker = NULL; 34 39 35 // init private all pointers to zero36 TestMolecule = NULL;37 hydrogen = NULL;38 tafel = NULL;39 40 40 // construct element 41 hydrogen = new element; 42 hydrogen->Z = 1; 43 hydrogen->CovalentRadius = 0.23; 44 strcpy(hydrogen->name, "hydrogen"); 45 strcpy(hydrogen->symbol, "H"); 46 47 // construct periodentafel 48 tafel = new periodentafel; 49 tafel->AddElement(hydrogen); 41 hydrogen = World::getInstance().getPeriode()->FindElement(1); 42 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen"); 50 43 51 44 // construct molecule (water molecule) 52 TestMolecule = new molecule(tafel); 45 TestMolecule = World::getInstance().createMolecule(); 46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 53 47 for (double x=0.5;x<3;x+=1.) 54 48 for (double y=0.5;y<3;y+=1.) 55 49 for (double z=0.5;z<3;z+=1.) { 56 Walker = new atom(); 50 Walker = World::getInstance().createAtom(); 51 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 57 52 Walker->type = hydrogen; 58 Walker->node->Init(x, y, z );53 *Walker->node = Vector(x, y, z ); 59 54 TestMolecule->AddAtom(Walker); 60 55 } … … 62 57 // construct linked cell 63 58 LC = new LinkedCell (TestMolecule, 1.); 59 CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell"); 64 60 65 61 // check that TestMolecule was correctly constructed … … 73 69 { 74 70 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 71 World::purgeInstance(); 79 72 }; 80 73 … … 201 194 202 195 // 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); 196 Walker = World::getInstance().createAtom(); 197 Walker->setName("test"); 198 Walker->x= Vector(1,1,1); 207 199 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 208 delete(Walker);200 World::getInstance().destroyAtom(Walker); 209 201 210 202 // 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); 203 Walker = World::getInstance().createAtom(); 204 Walker->setName("test"); 205 Walker->x = Vector(0,-1,0); 215 206 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) ); 216 delete(Walker);207 World::getInstance().destroyAtom(Walker); 217 208 }; 218 209 … … 228 219 for (double y=0.5;y<3;y+=1.) 229 220 for (double z=0.5;z<3;z+=1.) { 230 tester .Init(x,y,z);221 tester = Vector(x,y,z); 231 222 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); 232 223 } … … 235 226 for (double y=1.;y<4;y+=1.) 236 227 for (double z=1.;z<4;z+=1.) { 237 tester .Init(x,y,z);228 tester= Vector(x,y,z); 238 229 cout << "Tester is at " << tester << "." << endl; 239 230 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) ); … … 243 234 for (double y=0.5-1e-10;y<5;y+=3.1) 244 235 for (double z=0.5-1e-10;z<5;z+=3.1) { 245 tester .Init(x,y,z);236 tester = Vector(x,y,z); 246 237 cout << "The following test is supposed to fail and produce an ERROR." << endl; 247 238 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); 248 239 } 249 240 // check nonsense vectors 250 tester .Init(-423598,3245978,29349);241 tester= Vector(-423598,3245978,29349); 251 242 cout << "The following test is supposed to fail and produce an ERROR." << endl; 252 243 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) ); … … 261 252 int lower[NDIM], upper[NDIM]; 262 253 263 tester .Init(0.5,0.5,0.5);254 tester= Vector(0.5,0.5,0.5); 264 255 LC->SetIndexToVector(&tester); 265 256 LC->GetNeighbourBounds(lower, upper); … … 281 272 282 273 // get all atoms 283 tester .Init(1.5,1.5,1.5);274 tester= Vector(1.5,1.5,1.5); 284 275 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 285 276 ListOfPoints = LC->GetallNeighbours(); … … 300 291 301 292 // get all atoms in one corner 302 tester .Init(0.5, 0.5, 0.5);293 tester= Vector(0.5, 0.5, 0.5); 303 294 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 304 295 ListOfPoints = LC->GetallNeighbours(); … … 308 299 while (Walker->next != TestMolecule->end) { 309 300 Walker = Walker->next; 310 if ((Walker->x .x[0] <2) && (Walker->x.x[1] <2) && (Walker->x.x[2] <2)) {301 if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) { 311 302 ListOfPoints->remove(Walker); 312 303 size--; … … 320 311 321 312 // get all atoms from one corner 322 tester .Init(0.5, 0.5, 0.5);313 tester = Vector(0.5, 0.5, 0.5); 323 314 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 324 315 ListOfPoints = LC->GetallNeighbours(3); … … 349 340 350 341 // get all points around central arom with radius 1. 351 tester .Init(1.5,1.5,1.5);342 tester= Vector(1.5,1.5,1.5); 352 343 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) ); 353 344 ListOfPoints = LC->GetPointsInsideSphere(1., &tester); … … 357 348 while (Walker->next != TestMolecule->end) { 358 349 Walker = Walker->next; 359 if ((Walker->x.DistanceSquared( &tester) - 1.) < MYEPSILON ) {350 if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) { 360 351 ListOfPoints->remove(Walker); 361 352 size--; … … 368 359 delete(ListOfPoints); 369 360 }; 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.