Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/LinkedCellUnitTest.cpp

    r4f9e47 r68f03d  
    2222#include "periodentafel.hpp"
    2323#include "LinkedCellUnitTest.hpp"
     24#include "World.hpp"
     25
     26#ifdef HAVE_TESTRUNNER
     27#include "UnitTestMain.hpp"
     28#endif /*HAVE_TESTRUNNER*/
    2429
    2530/********************************************** Test classes **************************************/
     
    4651
    4752  // construct periodentafel
    48   tafel = new periodentafel;
     53  tafel = World::getInstance().getPeriode();
    4954  tafel->AddElement(hydrogen);
    5055
    5156  // construct molecule (water molecule)
    52   TestMolecule = new molecule(tafel);
     57  TestMolecule = World::getInstance().createMolecule();
    5358  for (double x=0.5;x<3;x+=1.)
    5459    for (double y=0.5;y<3;y+=1.)
    5560      for (double z=0.5;z<3;z+=1.) {
    56         Walker = new atom();
     61        Walker = World::getInstance().createAtom();
    5762        Walker->type = hydrogen;
    58         Walker->node->Init(x, y, z );
     63        *Walker->node = Vector(x, y, z );
    5964        TestMolecule->AddAtom(Walker);
    6065      }
     
    7378{
    7479  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();
    7982};
    8083
     
    201204
    202205  // 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);
    207209  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    208   delete(Walker);
     210  World::getInstance().destroyAtom(Walker);
    209211
    210212  // 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);
    215216  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    216   delete(Walker);
     217  World::getInstance().destroyAtom(Walker);
    217218};
    218219
     
    228229    for (double y=0.5;y<3;y+=1.)
    229230      for (double z=0.5;z<3;z+=1.) {
    230         tester.Init(x,y,z);
     231        tester = Vector(x,y,z);
    231232        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
    232233      }
     
    235236    for (double y=1.;y<4;y+=1.)
    236237      for (double z=1.;z<4;z+=1.) {
    237         tester.Init(x,y,z);
     238        tester= Vector(x,y,z);
    238239        cout << "Tester is at " << tester << "." << endl;
    239240        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
     
    243244    for (double y=0.5-1e-10;y<5;y+=3.1)
    244245      for (double z=0.5-1e-10;z<5;z+=3.1) {
    245         tester.Init(x,y,z);
     246        tester = Vector(x,y,z);
    246247        cout << "The following test is supposed to fail and produce an ERROR." << endl;
    247248        CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
    248249      }
    249250  // check nonsense vectors
    250   tester.Init(-423598,3245978,29349);
     251  tester= Vector(-423598,3245978,29349);
    251252  cout << "The following test is supposed to fail and produce an ERROR." << endl;
    252253  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
     
    261262  int lower[NDIM], upper[NDIM];
    262263
    263   tester.Init(0.5,0.5,0.5);
     264  tester= Vector(0.5,0.5,0.5);
    264265  LC->SetIndexToVector(&tester);
    265266  LC->GetNeighbourBounds(lower, upper);
     
    281282
    282283  // get all atoms
    283   tester.Init(1.5,1.5,1.5);
     284  tester= Vector(1.5,1.5,1.5);
    284285  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    285286  ListOfPoints = LC->GetallNeighbours();
     
    300301
    301302  // get all atoms in one corner
    302   tester.Init(0.5, 0.5, 0.5);
     303  tester= Vector(0.5, 0.5, 0.5);
    303304  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    304305  ListOfPoints = LC->GetallNeighbours();
     
    308309  while (Walker->next != TestMolecule->end) {
    309310    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)) {
    311312      ListOfPoints->remove(Walker);
    312313      size--;
     
    320321
    321322  // get all atoms from one corner
    322   tester.Init(0.5, 0.5, 0.5);
     323  tester = Vector(0.5, 0.5, 0.5);
    323324  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    324325  ListOfPoints = LC->GetallNeighbours(3);
     
    349350
    350351  // 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);
    352353  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    353354  ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
     
    357358  while (Walker->next != TestMolecule->end) {
    358359    Walker = Walker->next;
    359     if ((Walker->x.DistanceSquared(&tester) - 1.) < MYEPSILON ) {
     360    if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
    360361      ListOfPoints->remove(Walker);
    361362      size--;
     
    368369  delete(ListOfPoints);
    369370};
    370 
    371 /********************************************** Main routine **************************************/
    372 
    373 int main(int argc, char **argv)
    374 {
    375   // Get the top level suite from the registry
    376   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    377 
    378   // Adds the test to the list of test to run
    379   CppUnit::TextUi::TestRunner runner;
    380   runner.addTest( suite );
    381 
    382   // Change the default outputter to a compiler error format outputter
    383   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.