- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/bondgraphunittest.cpp
read4e6 re5ad5c 14 14 #include <iostream> 15 15 #include <stdio.h> 16 #include <cstring>17 16 18 #include "World.hpp"19 17 #include "atom.hpp" 20 18 #include "bond.hpp" 21 19 #include "bondgraph.hpp" 22 20 #include "element.hpp" 21 #include "log.hpp" 23 22 #include "molecule.hpp" 24 23 #include "periodentafel.hpp" 25 24 #include "bondgraphunittest.hpp" 26 #include "World.hpp"27 28 #ifdef HAVE_TESTRUNNER29 #include "UnitTestMain.hpp"30 #endif /*HAVE_TESTRUNNER*/31 25 32 26 /********************************************** Test classes **************************************/ … … 48 42 hydrogen = new element; 49 43 hydrogen->Z = 1; 44 hydrogen->CovalentRadius = 0.23; 45 hydrogen->VanDerWaalsRadius = 1.09; 50 46 strcpy(hydrogen->name, "hydrogen"); 51 47 strcpy(hydrogen->symbol, "H"); 52 48 carbon = new element; 53 49 carbon->Z = 2; 50 carbon->CovalentRadius = 0.68; 51 carbon->VanDerWaalsRadius = 1.7; 54 52 strcpy(carbon->name, "carbon"); 55 53 strcpy(carbon->symbol, "C"); … … 57 55 58 56 // construct periodentafel 59 tafel = World::getInstance().getPeriode();57 tafel = new periodentafel; 60 58 tafel->AddElement(hydrogen); 61 59 tafel->AddElement(carbon); 62 60 63 61 // 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; 67 65 Walker->node->Init(1., 0., 1. ); 68 66 TestMolecule->AddAtom(Walker); 69 Walker = World::getInstance().createAtom();70 Walker->type = hydrogen;67 Walker = new atom(); 68 Walker->type = carbon; 71 69 Walker->node->Init(0., 1., 1. ); 72 70 TestMolecule->AddAtom(Walker); 73 Walker = World::getInstance().createAtom();74 Walker->type = hydrogen;71 Walker = new atom(); 72 Walker->type = carbon; 75 73 Walker->node->Init(1., 1., 0. ); 76 74 TestMolecule->AddAtom(Walker); 77 Walker = World::getInstance().createAtom();78 Walker->type = hydrogen;75 Walker = new atom(); 76 Walker->type = carbon; 79 77 Walker->node->Init(0., 0., 0. ); 80 78 TestMolecule->AddAtom(Walker); … … 84 82 85 83 // create a small file with table 84 dummyname = new string("dummy.dat"); 86 85 filename = new string("test.dat"); 87 86 ofstream test(filename->c_str()); … … 89 88 test << "H\t1.\t1.2\n"; 90 89 test << "C\t1.2\t1.5\n"; 91 test.close();92 90 BG = new BondGraph(true); 93 91 }; … … 99 97 remove(filename->c_str()); 100 98 delete(filename); 99 delete(dummyname); 101 100 delete(BG); 102 101 103 102 // 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 110 107 }; 111 108 … … 122 119 /** UnitTest for BondGraphTest::ConstructBondGraph(). 123 120 */ 124 void BondGraphTest::ConstructGraph Test()121 void BondGraphTest::ConstructGraphFromTableTest() 125 122 { 126 123 atom *Walker = TestMolecule->start->next; … … 131 128 CPPUNIT_ASSERT_EQUAL( true , Walker->IsBondedTo(Runner) ); 132 129 }; 130 131 /** UnitTest for BondGraphTest::ConstructBondGraph(). 132 */ 133 void 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 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.