Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/bondgraphunittest.cpp

    read4e6 re5ad5c  
    1414#include <iostream>
    1515#include <stdio.h>
    16 #include <cstring>
    1716
    18 #include "World.hpp"
    1917#include "atom.hpp"
    2018#include "bond.hpp"
    2119#include "bondgraph.hpp"
    2220#include "element.hpp"
     21#include "log.hpp"
    2322#include "molecule.hpp"
    2423#include "periodentafel.hpp"
    2524#include "bondgraphunittest.hpp"
    26 #include "World.hpp"
    27 
    28 #ifdef HAVE_TESTRUNNER
    29 #include "UnitTestMain.hpp"
    30 #endif /*HAVE_TESTRUNNER*/
    3125
    3226/********************************************** Test classes **************************************/
     
    4842  hydrogen = new element;
    4943  hydrogen->Z = 1;
     44  hydrogen->CovalentRadius = 0.23;
     45  hydrogen->VanDerWaalsRadius = 1.09;
    5046  strcpy(hydrogen->name, "hydrogen");
    5147  strcpy(hydrogen->symbol, "H");
    5248  carbon = new element;
    5349  carbon->Z = 2;
     50  carbon->CovalentRadius = 0.68;
     51  carbon->VanDerWaalsRadius = 1.7;
    5452  strcpy(carbon->name, "carbon");
    5553  strcpy(carbon->symbol, "C");
     
    5755
    5856  // construct periodentafel
    59   tafel = World::getInstance().getPeriode();
     57  tafel = new periodentafel;
    6058  tafel->AddElement(hydrogen);
    6159  tafel->AddElement(carbon);
    6260
    6361  // construct molecule (tetraeder of hydrogens)
    64   TestMolecule = World::getInstance().createMolecule();
    65   Walker = World::getInstance().createAtom();
    66   Walker->type = hydrogen;
     62  TestMolecule = new molecule(tafel);
     63  Walker = new atom();
     64  Walker->type = carbon;
    6765  Walker->node->Init(1., 0., 1. );
    6866  TestMolecule->AddAtom(Walker);
    69   Walker = World::getInstance().createAtom();
    70   Walker->type = hydrogen;
     67  Walker = new atom();
     68  Walker->type = carbon;
    7169  Walker->node->Init(0., 1., 1. );
    7270  TestMolecule->AddAtom(Walker);
    73   Walker = World::getInstance().createAtom();
    74   Walker->type = hydrogen;
     71  Walker = new atom();
     72  Walker->type = carbon;
    7573  Walker->node->Init(1., 1., 0. );
    7674  TestMolecule->AddAtom(Walker);
    77   Walker = World::getInstance().createAtom();
    78   Walker->type = hydrogen;
     75  Walker = new atom();
     76  Walker->type = carbon;
    7977  Walker->node->Init(0., 0., 0. );
    8078  TestMolecule->AddAtom(Walker);
     
    8482
    8583  // create a small file with table
     84  dummyname = new string("dummy.dat");
    8685  filename = new string("test.dat");
    8786  ofstream test(filename->c_str());
     
    8988  test << "H\t1.\t1.2\n";
    9089  test << "C\t1.2\t1.5\n";
    91   test.close();
    9290  BG = new BondGraph(true);
    9391};
     
    9997  remove(filename->c_str());
    10098  delete(filename);
     99  delete(dummyname);
    101100  delete(BG);
    102101
    103102  // remove molecule
    104   World::getInstance().destroyMolecule(TestMolecule);
    105   // note that all the atoms, molecules, the tafel and the elements
    106   // are all cleaned when the world is destroyed
    107   World::purgeInstance();
    108   MemoryUsageObserver::purgeInstance();
    109   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
    110107};
    111108
     
    122119/** UnitTest for BondGraphTest::ConstructBondGraph().
    123120 */
    124 void BondGraphTest::ConstructGraphTest()
     121void BondGraphTest::ConstructGraphFromTableTest()
    125122{
    126123  atom *Walker = TestMolecule->start->next;
     
    131128  CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
    132129};
     130
     131/** UnitTest for BondGraphTest::ConstructBondGraph().
     132 */
     133void BondGraphTest::ConstructGraphFromCovalentRadiiTest()
     134{
     135  atom *Walker = TestMolecule->start->next;
     136  atom *Runner = TestMolecule->end->previous;
     137  CPPUNIT_ASSERT( TestMolecule->end != Walker );
     138  CPPUNIT_ASSERT_EQUAL( false , BG->LoadBondLengthTable(*dummyname) );
     139  CPPUNIT_ASSERT_EQUAL( true , BG->ConstructBondGraph(TestMolecule) );
     140  CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) );
     141};
     142
     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.