| 1 | /* | 
|---|
| 2 | * periodentafelTest.cpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: May 18, 2010 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | using namespace std; | 
|---|
| 9 |  | 
|---|
| 10 | #include <cppunit/CompilerOutputter.h> | 
|---|
| 11 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
| 12 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
| 13 |  | 
|---|
| 14 | #include <sstream> | 
|---|
| 15 | #include <iostream> | 
|---|
| 16 |  | 
|---|
| 17 | #include "Helpers/Assert.hpp" | 
|---|
| 18 |  | 
|---|
| 19 | #include "World.hpp" | 
|---|
| 20 | #include "periodentafelTest.hpp" | 
|---|
| 21 | #include "element.hpp" | 
|---|
| 22 | #include "elements_db.hpp" | 
|---|
| 23 | #include "periodentafel.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | #ifdef HAVE_TESTRUNNER | 
|---|
| 26 | #include "UnitTestMain.hpp" | 
|---|
| 27 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| 28 |  | 
|---|
| 29 | /********************************************** Test classes **************************************/ | 
|---|
| 30 |  | 
|---|
| 31 | // Registers the fixture into the 'registry' | 
|---|
| 32 | CPPUNIT_TEST_SUITE_REGISTRATION( periodentafelTest ); | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | void periodentafelTest::setUp() | 
|---|
| 36 | { | 
|---|
| 37 | // make sure world is present | 
|---|
| 38 | tafel = World::getInstance().getPeriode(); | 
|---|
| 39 | CPPUNIT_ASSERT(tafel != NULL && "could not obtain periodentafel"); | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 | void periodentafelTest::tearDown() | 
|---|
| 44 | { | 
|---|
| 45 | World::purgeInstance(); | 
|---|
| 46 | }; | 
|---|
| 47 |  | 
|---|
| 48 | /** UnitTest for AddRemoveTest(). | 
|---|
| 49 | */ | 
|---|
| 50 | void periodentafelTest::AddRemoveTest() | 
|---|
| 51 | { | 
|---|
| 52 | // copy the element | 
|---|
| 53 | const element * ElementPtr = tafel->FindElement(3); | 
|---|
| 54 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find element lithium"); | 
|---|
| 55 | element *Elemental = new element(*ElementPtr); | 
|---|
| 56 | // remove element | 
|---|
| 57 | tafel->RemoveElement((element * const)ElementPtr); | 
|---|
| 58 | ElementPtr = tafel->FindElement(3); | 
|---|
| 59 | CPPUNIT_ASSERT_EQUAL( (const element *)NULL, ElementPtr ); | 
|---|
| 60 | // add element again | 
|---|
| 61 | tafel->AddElement((element * const)Elemental); | 
|---|
| 62 | ElementPtr = tafel->FindElement(3); | 
|---|
| 63 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find re-added element lithium"); | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 | /** UnitTest for LoadStoreTest(). | 
|---|
| 67 | * TODO: periodentafelTest::LoadStoreTest() not implemented yet | 
|---|
| 68 | */ | 
|---|
| 69 | void periodentafelTest::LoadStoreTest() | 
|---|
| 70 | { | 
|---|
| 71 | // reload all databases | 
|---|
| 72 | stringstream elementsDBstream(elementsDB,ios_base::in); | 
|---|
| 73 | CPPUNIT_ASSERT(tafel->LoadElementsDatabase(elementsDBstream) && "General element initialization failed"); | 
|---|
| 74 | CPPUNIT_ASSERT(tafel->LoadValenceDatabase(new stringstream(valenceDB,ios_base::in)) && "Valence entry of element initialization failed"); | 
|---|
| 75 | CPPUNIT_ASSERT(tafel->LoadOrbitalsDatabase(new stringstream(orbitalsDB,ios_base::in)) && "Orbitals entry of element initialization failed"); | 
|---|
| 76 | CPPUNIT_ASSERT(tafel->LoadHBondAngleDatabase(new stringstream(HbondangleDB,ios_base::in)) && "HBond angle entry of element initialization failed"); | 
|---|
| 77 | CPPUNIT_ASSERT(tafel->LoadHBondLengthsDatabase(new stringstream(HbonddistanceDB,ios_base::in)) && "HBond distance entry of element initialization failed"); | 
|---|
| 78 | // check presence of elements | 
|---|
| 79 | atomicNumber_t Z = 1; | 
|---|
| 80 | for(periodentafel::const_iterator ElementRunner = tafel->begin(); ElementRunner != tafel->end(); ++ElementRunner) | 
|---|
| 81 | CPPUNIT_ASSERT( (ElementRunner->second->getNumber() == Z++) && "element is missing in sequence"); | 
|---|
| 82 | }; | 
|---|