Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/LinkedCellUnitTest.cpp

    r4f9e47 r920c70  
    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 **************************************/
     
    3338  atom *Walker = NULL;
    3439
    35   // init private all pointers to zero
    36   TestMolecule = NULL;
    37   hydrogen = NULL;
    38   tafel = NULL;
    39 
    4040  // 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");
    5043
    5144  // construct molecule (water molecule)
    52   TestMolecule = new molecule(tafel);
     45  TestMolecule = World::getInstance().createMolecule();
     46  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
    5347  for (double x=0.5;x<3;x+=1.)
    5448    for (double y=0.5;y<3;y+=1.)
    5549      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");
    5752        Walker->type = hydrogen;
    58         Walker->node->Init(x, y, z );
     53        *Walker->node = Vector(x, y, z );
    5954        TestMolecule->AddAtom(Walker);
    6055      }
     
    6257  // construct linked cell
    6358  LC = new LinkedCell (TestMolecule, 1.);
     59  CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell");
    6460
    6561  // check that TestMolecule was correctly constructed
     
    7369{
    7470  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();
    7972};
    8073
     
    201194
    202195  // 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);
    207199  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    208   delete(Walker);
     200  World::getInstance().destroyAtom(Walker);
    209201
    210202  // 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);
    215206  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    216   delete(Walker);
     207  World::getInstance().destroyAtom(Walker);
    217208};
    218209
     
    228219    for (double y=0.5;y<3;y+=1.)
    229220      for (double z=0.5;z<3;z+=1.) {
    230         tester.Init(x,y,z);
     221        tester = Vector(x,y,z);
    231222        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
    232223      }
     
    235226    for (double y=1.;y<4;y+=1.)
    236227      for (double z=1.;z<4;z+=1.) {
    237         tester.Init(x,y,z);
     228        tester= Vector(x,y,z);
    238229        cout << "Tester is at " << tester << "." << endl;
    239230        CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
     
    243234    for (double y=0.5-1e-10;y<5;y+=3.1)
    244235      for (double z=0.5-1e-10;z<5;z+=3.1) {
    245         tester.Init(x,y,z);
     236        tester = Vector(x,y,z);
    246237        cout << "The following test is supposed to fail and produce an ERROR." << endl;
    247238        CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
    248239      }
    249240  // check nonsense vectors
    250   tester.Init(-423598,3245978,29349);
     241  tester= Vector(-423598,3245978,29349);
    251242  cout << "The following test is supposed to fail and produce an ERROR." << endl;
    252243  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
     
    261252  int lower[NDIM], upper[NDIM];
    262253
    263   tester.Init(0.5,0.5,0.5);
     254  tester= Vector(0.5,0.5,0.5);
    264255  LC->SetIndexToVector(&tester);
    265256  LC->GetNeighbourBounds(lower, upper);
     
    281272
    282273  // get all atoms
    283   tester.Init(1.5,1.5,1.5);
     274  tester= Vector(1.5,1.5,1.5);
    284275  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    285276  ListOfPoints = LC->GetallNeighbours();
     
    300291
    301292  // get all atoms in one corner
    302   tester.Init(0.5, 0.5, 0.5);
     293  tester= Vector(0.5, 0.5, 0.5);
    303294  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    304295  ListOfPoints = LC->GetallNeighbours();
     
    308299  while (Walker->next != TestMolecule->end) {
    309300    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)) {
    311302      ListOfPoints->remove(Walker);
    312303      size--;
     
    320311
    321312  // get all atoms from one corner
    322   tester.Init(0.5, 0.5, 0.5);
     313  tester = Vector(0.5, 0.5, 0.5);
    323314  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    324315  ListOfPoints = LC->GetallNeighbours(3);
     
    349340
    350341  // 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);
    352343  CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
    353344  ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
     
    357348  while (Walker->next != TestMolecule->end) {
    358349    Walker = Walker->next;
    359     if ((Walker->x.DistanceSquared(&tester) - 1.) < MYEPSILON ) {
     350    if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
    360351      ListOfPoints->remove(Walker);
    361352      size--;
     
    368359  delete(ListOfPoints);
    369360};
    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.