- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/bondgraphunittest.cpp
r4eb4fe re5ad5c 14 14 #include <iostream> 15 15 #include <stdio.h> 16 #include <cstring>17 16 18 #include "Helpers/Assert.hpp"19 20 #include "World.hpp"21 17 #include "atom.hpp" 22 18 #include "bond.hpp" … … 27 23 #include "periodentafel.hpp" 28 24 #include "bondgraphunittest.hpp" 29 #include "World.hpp"30 31 #ifdef HAVE_TESTRUNNER32 #include "UnitTestMain.hpp"33 #endif /*HAVE_TESTRUNNER*/34 25 35 26 /********************************************** Test classes **************************************/ … … 43 34 atom *Walker = NULL; 44 35 36 // init private all pointers to zero 37 TestMolecule = NULL; 38 hydrogen = NULL; 39 tafel = NULL; 40 45 41 // 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); 50 60 51 61 // 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(); 56 64 Walker->type = carbon; 57 *Walker->node = Vector(1., 0., 1. );65 Walker->node->Init(1., 0., 1. ); 58 66 TestMolecule->AddAtom(Walker); 59 60 Walker = World::getInstance().createAtom(); 61 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 67 Walker = new atom(); 62 68 Walker->type = carbon; 63 *Walker->node = Vector(0., 1., 1. );69 Walker->node->Init(0., 1., 1. ); 64 70 TestMolecule->AddAtom(Walker); 65 66 Walker = World::getInstance().createAtom(); 67 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 71 Walker = new atom(); 68 72 Walker->type = carbon; 69 *Walker->node = Vector(1., 1., 0. );73 Walker->node->Init(1., 1., 0. ); 70 74 TestMolecule->AddAtom(Walker); 71 72 Walker = World::getInstance().createAtom(); 73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 75 Walker = new atom(); 74 76 Walker->type = carbon; 75 *Walker->node = Vector(0., 0., 0. );77 Walker->node->Init(0., 0., 0. ); 76 78 TestMolecule->AddAtom(Walker); 77 79 … … 81 83 // create a small file with table 82 84 dummyname = new string("dummy.dat"); 83 CPPUNIT_ASSERT(dummyname != NULL && "could not create string");84 85 filename = new string("test.dat"); 85 CPPUNIT_ASSERT(filename != NULL && "could not create string");86 86 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"; 95 90 BG = new BondGraph(true); 96 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");97 91 }; 98 92 … … 107 101 108 102 // 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 115 107 }; 116 108 … … 121 113 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 122 114 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) ); 125 117 }; 126 118 … … 149 141 }; 150 142 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.