- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/bondgraphunittest.cpp
re5ad5c r920c70 14 14 #include <iostream> 15 15 #include <stdio.h> 16 #include <cstring> 16 17 18 #include "Helpers/Assert.hpp" 19 20 #include "World.hpp" 17 21 #include "atom.hpp" 18 22 #include "bond.hpp" … … 23 27 #include "periodentafel.hpp" 24 28 #include "bondgraphunittest.hpp" 29 #include "World.hpp" 30 31 #ifdef HAVE_TESTRUNNER 32 #include "UnitTestMain.hpp" 33 #endif /*HAVE_TESTRUNNER*/ 25 34 26 35 /********************************************** Test classes **************************************/ … … 34 43 atom *Walker = NULL; 35 44 36 // init private all pointers to zero37 TestMolecule = NULL;38 hydrogen = NULL;39 tafel = NULL;40 41 45 // 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"); 60 50 61 51 // 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"); 64 56 Walker->type = carbon; 65 Walker->node->Init(1., 0., 1. );57 *Walker->node = Vector(1., 0., 1. ); 66 58 TestMolecule->AddAtom(Walker); 67 Walker = new atom(); 59 60 Walker = World::getInstance().createAtom(); 61 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 68 62 Walker->type = carbon; 69 Walker->node->Init(0., 1., 1. );63 *Walker->node = Vector(0., 1., 1. ); 70 64 TestMolecule->AddAtom(Walker); 71 Walker = new atom(); 65 66 Walker = World::getInstance().createAtom(); 67 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 72 68 Walker->type = carbon; 73 Walker->node->Init(1., 1., 0. );69 *Walker->node = Vector(1., 1., 0. ); 74 70 TestMolecule->AddAtom(Walker); 75 Walker = new atom(); 71 72 Walker = World::getInstance().createAtom(); 73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom"); 76 74 Walker->type = carbon; 77 Walker->node->Init(0., 0., 0. );75 *Walker->node = Vector(0., 0., 0. ); 78 76 TestMolecule->AddAtom(Walker); 79 77 … … 83 81 // create a small file with table 84 82 dummyname = new string("dummy.dat"); 83 CPPUNIT_ASSERT(dummyname != NULL && "could not create string"); 85 84 filename = new string("test.dat"); 85 CPPUNIT_ASSERT(filename != NULL && "could not create string"); 86 86 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(); 90 95 BG = new BondGraph(true); 96 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph"); 91 97 }; 92 98 … … 101 107 102 108 // 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(); 107 114 }; 108 115 … … 113 120 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) ); 114 121 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) ); 117 124 }; 118 125 … … 141 148 }; 142 149 143 144 /********************************************** Main routine **************************************/145 146 int main(int argc, char **argv)147 {148 // Get the top level suite from the registry149 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();150 151 // Adds the test to the list of test to run152 CppUnit::TextUi::TestRunner runner;153 runner.addTest( suite );154 155 // Change the default outputter to a compiler error format outputter156 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.