Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/bondgraphunittest.cpp

    r4eb4fe re5ad5c  
    1414#include <iostream>
    1515#include <stdio.h>
    16 #include <cstring>
    1716
    18 #include "Helpers/Assert.hpp"
    19 
    20 #include "World.hpp"
    2117#include "atom.hpp"
    2218#include "bond.hpp"
     
    2723#include "periodentafel.hpp"
    2824#include "bondgraphunittest.hpp"
    29 #include "World.hpp"
    30 
    31 #ifdef HAVE_TESTRUNNER
    32 #include "UnitTestMain.hpp"
    33 #endif /*HAVE_TESTRUNNER*/
    3425
    3526/********************************************** Test classes **************************************/
     
    4334  atom *Walker = NULL;
    4435
     36  // init private all pointers to zero
     37  TestMolecule = NULL;
     38  hydrogen = NULL;
     39  tafel = NULL;
     40
    4541  // construct element
    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");
     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);
    5060
    5161  // construct molecule (tetraeder of hydrogens)
    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");
     62  TestMolecule = new molecule(tafel);
     63  Walker = new atom();
    5664  Walker->type = carbon;
    57   *Walker->node = Vector(1., 0., 1. );
     65  Walker->node->Init(1., 0., 1. );
    5866  TestMolecule->AddAtom(Walker);
    59 
    60   Walker = World::getInstance().createAtom();
    61   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     67  Walker = new atom();
    6268  Walker->type = carbon;
    63   *Walker->node = Vector(0., 1., 1. );
     69  Walker->node->Init(0., 1., 1. );
    6470  TestMolecule->AddAtom(Walker);
    65 
    66   Walker = World::getInstance().createAtom();
    67   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     71  Walker = new atom();
    6872  Walker->type = carbon;
    69   *Walker->node = Vector(1., 1., 0. );
     73  Walker->node->Init(1., 1., 0. );
    7074  TestMolecule->AddAtom(Walker);
    71 
    72   Walker = World::getInstance().createAtom();
    73   CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
     75  Walker = new atom();
    7476  Walker->type = carbon;
    75   *Walker->node = Vector(0., 0., 0. );
     77  Walker->node->Init(0., 0., 0. );
    7678  TestMolecule->AddAtom(Walker);
    7779
     
    8183  // create a small file with table
    8284  dummyname = new string("dummy.dat");
    83   CPPUNIT_ASSERT(dummyname != NULL && "could not create string");
    8485  filename = new string("test.dat");
    85   CPPUNIT_ASSERT(filename != NULL && "could not create string");
    8686  ofstream test(filename->c_str());
    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();
     87  test << ".\tH\tC\n";
     88  test << "H\t1.\t1.2\n";
     89  test << "C\t1.2\t1.5\n";
    9590  BG = new BondGraph(true);
    96   CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
    9791};
    9892
     
    107101
    108102  // remove molecule
    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   MemoryUsageObserver::purgeInstance();
    114   logger::purgeInstance();
     103  delete(TestMolecule);
     104  // note that all the atoms are cleaned by TestMolecule
     105  delete(tafel);
     106  // note that element is cleaned by periodentafel
    115107};
    116108
     
    121113  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    122114  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    123   CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
    124   CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
     115  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
     116  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
    125117};
    126118
     
    149141};
    150142
     143
     144/********************************************** Main routine **************************************/
     145
     146int 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.