Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/bondgraphunittest.cpp

    re5ad5c r920c70  
    1414#include <iostream>
    1515#include <stdio.h>
     16#include <cstring>
    1617
     18#include "Helpers/Assert.hpp"
     19
     20#include "World.hpp"
    1721#include "atom.hpp"
    1822#include "bond.hpp"
     
    2327#include "periodentafel.hpp"
    2428#include "bondgraphunittest.hpp"
     29#include "World.hpp"
     30
     31#ifdef HAVE_TESTRUNNER
     32#include "UnitTestMain.hpp"
     33#endif /*HAVE_TESTRUNNER*/
    2534
    2635/********************************************** Test classes **************************************/
     
    3443  atom *Walker = NULL;
    3544
    36   // init private all pointers to zero
    37   TestMolecule = NULL;
    38   hydrogen = NULL;
    39   tafel = NULL;
    40 
    4145  // construct element
    42   hydrogen = new element;
    43   hydrogen->Z = 1;
    44   hydrogen->CovalentRadius = 0.23;
    45   hydrogen->VanDerWaalsRadius = 1.09;
    46   strcpy(hydrogen->name, "hydrogen");
    47   strcpy(hydrogen->symbol, "H");
    48   carbon = new element;
    49   carbon->Z = 2;
    50   carbon->CovalentRadius = 0.68;
    51   carbon->VanDerWaalsRadius = 1.7;
    52   strcpy(carbon->name, "carbon");
    53   strcpy(carbon->symbol, "C");
    54 
    55 
    56   // construct periodentafel
    57   tafel = new periodentafel;
    58   tafel->AddElement(hydrogen);
    59   tafel->AddElement(carbon);
     46  hydrogen = World::getInstance().getPeriode()->FindElement(1);
     47  carbon = World::getInstance().getPeriode()->FindElement(6);
     48  CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
     49  CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
    6050
    6151  // construct molecule (tetraeder of hydrogens)
    62   TestMolecule = new molecule(tafel);
    63   Walker = new atom();
     52  TestMolecule = World::getInstance().createMolecule();
     53  CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
     54  Walker = World::getInstance().createAtom();
     55  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6456  Walker->type = carbon;
    65   Walker->node->Init(1., 0., 1. );
     57  *Walker->node = Vector(1., 0., 1. );
    6658  TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
     59
     60  Walker = World::getInstance().createAtom();
     61  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    6862  Walker->type = carbon;
    69   Walker->node->Init(0., 1., 1. );
     63  *Walker->node = Vector(0., 1., 1. );
    7064  TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
     65
     66  Walker = World::getInstance().createAtom();
     67  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7268  Walker->type = carbon;
    73   Walker->node->Init(1., 1., 0. );
     69  *Walker->node = Vector(1., 1., 0. );
    7470  TestMolecule->AddAtom(Walker);
    75   Walker = new atom();
     71
     72  Walker = World::getInstance().createAtom();
     73  CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
    7674  Walker->type = carbon;
    77   Walker->node->Init(0., 0., 0. );
     75  *Walker->node = Vector(0., 0., 0. );
    7876  TestMolecule->AddAtom(Walker);
    7977
     
    8381  // create a small file with table
    8482  dummyname = new string("dummy.dat");
     83  CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
    8584  filename = new string("test.dat");
     85  CPPUNIT_ASSERT(filename != NULL && "could not create string");
    8686  ofstream test(filename->c_str());
    87   test << ".\tH\tC\n";
    88   test << "H\t1.\t1.2\n";
    89   test << "C\t1.2\t1.5\n";
     87  test << ".\tH\tHe\tLi\tBe\tB\tC\n";
     88  test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
     89  test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
     90  test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
     91  test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
     92  test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
     93  test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
     94  test.close();
    9095  BG = new BondGraph(true);
     96  CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    9197};
    9298
     
    101107
    102108  // remove molecule
    103   delete(TestMolecule);
    104   // note that all the atoms are cleaned by TestMolecule
    105   delete(tafel);
    106   // note that element is cleaned by periodentafel
     109  World::getInstance().destroyMolecule(TestMolecule);
     110  // note that all the atoms, molecules, the tafel and the elements
     111  // are all cleaned when the world is destroyed
     112  World::purgeInstance();
     113  logger::purgeInstance();
    107114};
    108115
     
    113120  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    114121  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    115   CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
    116   CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
     122  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
     123  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
    117124};
    118125
     
    141148};
    142149
    143 
    144 /********************************************** Main routine **************************************/
    145 
    146 int main(int argc, char **argv)
    147 {
    148   // Get the top level suite from the registry
    149   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    150 
    151   // Adds the test to the list of test to run
    152   CppUnit::TextUi::TestRunner runner;
    153   runner.addTest( suite );
    154 
    155   // Change the default outputter to a compiler error format outputter
    156   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    157                                                        std::cerr ) );
    158   // Run the tests.
    159   bool wasSucessful = runner.run();
    160 
    161   // Return error code 1 if the one of test failed.
    162   return wasSucessful ? 0 : 1;
    163 };
Note: See TracChangeset for help on using the changeset viewer.