- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/LinkedCellUnitTest.cpp
r68f03d r4ac1aa 38 38 atom *Walker = NULL; 39 39 40 // init private all pointers to zero41 TestMolecule = NULL;42 hydrogen = NULL;43 tafel = NULL;44 45 40 // construct element 46 hydrogen = new element; 47 hydrogen->Z = 1; 48 hydrogen->CovalentRadius = 0.23; 49 strcpy(hydrogen->name, "hydrogen"); 50 strcpy(hydrogen->symbol, "H"); 51 52 // construct periodentafel 53 tafel = World::getInstance().getPeriode(); 54 tafel->AddElement(hydrogen); 41 hydrogen = World::getInstance().getPeriode()->FindElement(1); 42 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen"); 55 43 56 44 // construct molecule (water molecule) 57 45 TestMolecule = World::getInstance().createMolecule(); 46 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule"); 58 47 for (double x=0.5;x<3;x+=1.) 59 48 for (double y=0.5;y<3;y+=1.) 60 49 for (double z=0.5;z<3;z+=1.) { 61 50 Walker = World::getInstance().createAtom(); 51 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 62 52 Walker->type = hydrogen; 63 53 *Walker->node = Vector(x, y, z ); … … 67 57 // construct linked cell 68 58 LC = new LinkedCell (TestMolecule, 1.); 59 CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell"); 69 60 70 61 // check that TestMolecule was correctly constructed 71 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 ); 72 Walker = TestMolecule->start->next; 73 CPPUNIT_ASSERT( TestMolecule->end != Walker ); 62 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 3*3*3 ); 74 63 }; 75 64 … … 79 68 delete(LC); 80 69 World::purgeInstance(); 81 MemoryUsageObserver::purgeInstance();82 70 }; 83 71 … … 197 185 { 198 186 // check all atoms 199 atom *Walker = TestMolecule->start; 200 while (Walker->next != TestMolecule->end) { 201 Walker = Walker->next; 202 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) ); 187 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){ 188 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) ); 203 189 } 204 190 205 191 // check internal vectors, returns false, because this atom is not in LC-list! 206 Walker= World::getInstance().createAtom();207 Walker->setName("test");208 Walker->x= Vector(1,1,1);209 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode( Walker) );210 World::getInstance().destroyAtom( Walker);192 atom *newAtom = World::getInstance().createAtom(); 193 newAtom->setName("test"); 194 newAtom->x= Vector(1,1,1); 195 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) ); 196 World::getInstance().destroyAtom(newAtom); 211 197 212 198 // check out of bounds vectors 213 Walker= World::getInstance().createAtom();214 Walker->setName("test");215 Walker->x = Vector(0,-1,0);216 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode( Walker) );217 World::getInstance().destroyAtom( Walker);199 newAtom = World::getInstance().createAtom(); 200 newAtom->setName("test"); 201 newAtom->x = Vector(0,-1,0); 202 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) ); 203 World::getInstance().destroyAtom(newAtom); 218 204 }; 219 205 … … 278 264 Vector tester; 279 265 LinkedCell::LinkedNodes *ListOfPoints = NULL; 280 atom *Walker = NULL;281 266 size_t size = 0; 282 267 … … 287 272 size = ListOfPoints->size(); 288 273 CPPUNIT_ASSERT_EQUAL( (size_t)27, size ); 289 Walker = TestMolecule->start; 290 Walker = TestMolecule->start; 291 while (Walker->next != TestMolecule->end) { 292 Walker = Walker->next; 293 ListOfPoints->remove(Walker); 274 275 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){ 276 ListOfPoints->remove((*iter)); 294 277 size--; 295 278 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 306 289 size=ListOfPoints->size(); 307 290 CPPUNIT_ASSERT_EQUAL( (size_t)8, size ); 308 Walker = TestMolecule->start; 309 while (Walker->next != TestMolecule->end) { 310 Walker = Walker->next; 311 if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) { 312 ListOfPoints->remove(Walker); 291 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){ 292 if (((*iter)->x[0] <2) && ((*iter)->x[1] <2) && ((*iter)->x[2] <2)) { 293 ListOfPoints->remove(*iter); 313 294 size--; 314 295 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 326 307 size=ListOfPoints->size(); 327 308 CPPUNIT_ASSERT_EQUAL( (size_t)27, size ); 328 Walker = TestMolecule->start; 329 while (Walker->next != TestMolecule->end) { 330 Walker = Walker->next; 331 ListOfPoints->remove(Walker); 309 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){ 310 ListOfPoints->remove(*iter); 332 311 size--; 333 312 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() ); … … 346 325 Vector tester; 347 326 LinkedCell::LinkedNodes *ListOfPoints = NULL; 348 atom *Walker = NULL;349 327 size_t size = 0; 350 328 … … 355 333 size = ListOfPoints->size(); 356 334 CPPUNIT_ASSERT_EQUAL( (size_t)7, size ); 357 Walker = TestMolecule->start; 358 while (Walker->next != TestMolecule->end) { 359 Walker = Walker->next; 360 if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) { 361 ListOfPoints->remove(Walker); 335 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){ 336 if (((*iter)->x.DistanceSquared(tester) - 1.) < MYEPSILON ) { 337 ListOfPoints->remove(*iter); 362 338 size--; 363 339 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
Note:
See TracChangeset
for help on using the changeset viewer.