| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [4eb4fe] | 8 | /* | 
|---|
| [f844ef] | 9 | * PeriodentafelUnitTest.cpp | 
|---|
| [4eb4fe] | 10 | * | 
|---|
|  | 11 | *  Created on: May 18, 2010 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [4eb4fe] | 20 | using namespace std; | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [e5c0a1] | 26 | #include <sstream> | 
|---|
|  | 27 | #include <iostream> | 
|---|
|  | 28 |  | 
|---|
| [ad011c] | 29 | #include "CodePatterns/Assert.hpp" | 
|---|
| [4eb4fe] | 30 |  | 
|---|
|  | 31 | #include "World.hpp" | 
|---|
|  | 32 | #include "element.hpp" | 
|---|
|  | 33 | #include "elements_db.hpp" | 
|---|
|  | 34 | #include "periodentafel.hpp" | 
|---|
|  | 35 |  | 
|---|
| [f844ef] | 36 | #include "PeriodentafelUnitTest.hpp" | 
|---|
|  | 37 |  | 
|---|
| [4eb4fe] | 38 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 39 | #include "UnitTestMain.hpp" | 
|---|
|  | 40 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 41 |  | 
|---|
|  | 42 | /********************************************** Test classes **************************************/ | 
|---|
|  | 43 |  | 
|---|
|  | 44 | // Registers the fixture into the 'registry' | 
|---|
|  | 45 | CPPUNIT_TEST_SUITE_REGISTRATION( periodentafelTest ); | 
|---|
|  | 46 |  | 
|---|
|  | 47 |  | 
|---|
|  | 48 | void periodentafelTest::setUp() | 
|---|
|  | 49 | { | 
|---|
|  | 50 | // make sure world is present | 
|---|
|  | 51 | tafel = World::getInstance().getPeriode(); | 
|---|
|  | 52 | CPPUNIT_ASSERT(tafel != NULL && "could not obtain periodentafel"); | 
|---|
|  | 53 | }; | 
|---|
|  | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 | void periodentafelTest::tearDown() | 
|---|
|  | 57 | { | 
|---|
|  | 58 | World::purgeInstance(); | 
|---|
|  | 59 | }; | 
|---|
|  | 60 |  | 
|---|
|  | 61 | /** UnitTest for AddRemoveTest(). | 
|---|
|  | 62 | */ | 
|---|
|  | 63 | void periodentafelTest::AddRemoveTest() | 
|---|
|  | 64 | { | 
|---|
|  | 65 | // copy the element | 
|---|
|  | 66 | const element * ElementPtr = tafel->FindElement(3); | 
|---|
|  | 67 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find element lithium"); | 
|---|
|  | 68 | element *Elemental = new element(*ElementPtr); | 
|---|
|  | 69 | // remove element | 
|---|
|  | 70 | tafel->RemoveElement((element * const)ElementPtr); | 
|---|
|  | 71 | ElementPtr = tafel->FindElement(3); | 
|---|
|  | 72 | CPPUNIT_ASSERT_EQUAL( (const element *)NULL, ElementPtr ); | 
|---|
|  | 73 | // add element again | 
|---|
|  | 74 | tafel->AddElement((element * const)Elemental); | 
|---|
|  | 75 | ElementPtr = tafel->FindElement(3); | 
|---|
|  | 76 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find re-added element lithium"); | 
|---|
|  | 77 | }; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | /** UnitTest for LoadStoreTest(). | 
|---|
|  | 80 | * TODO: periodentafelTest::LoadStoreTest() not implemented yet | 
|---|
|  | 81 | */ | 
|---|
|  | 82 | void periodentafelTest::LoadStoreTest() | 
|---|
|  | 83 | { | 
|---|
|  | 84 | // reload all databases | 
|---|
| [e5c0a1] | 85 | stringstream elementsDBstream(elementsDB,ios_base::in); | 
|---|
| [67c92b] | 86 | stringstream ElectronegativityDBstream(ElectronegativitiesDB,ios_base::in); | 
|---|
|  | 87 | stringstream valenceDBstream(valenceDB,ios_base::in); | 
|---|
|  | 88 | stringstream orbitalsDBstream(orbitalsDB,ios_base::in); | 
|---|
|  | 89 | stringstream HbondangleDBstream(HbondangleDB,ios_base::in); | 
|---|
|  | 90 | stringstream HbonddistanceDBstream(HbonddistanceDB,ios_base::in); | 
|---|
| [e5c0a1] | 91 | CPPUNIT_ASSERT(tafel->LoadElementsDatabase(elementsDBstream) && "General element initialization failed"); | 
|---|
| [67c92b] | 92 | CPPUNIT_ASSERT(tafel->LoadElectronegativityDatabase(ElectronegativityDBstream) && "Electronegativity entry of element initialization failed"); | 
|---|
|  | 93 | CPPUNIT_ASSERT(tafel->LoadValenceDatabase(valenceDBstream) && "Valence entry of element initialization failed"); | 
|---|
|  | 94 | CPPUNIT_ASSERT(tafel->LoadOrbitalsDatabase(orbitalsDBstream) && "Orbitals entry of element initialization failed"); | 
|---|
|  | 95 | CPPUNIT_ASSERT(tafel->LoadHBondAngleDatabase(HbondangleDBstream) && "HBond angle entry of element initialization failed"); | 
|---|
|  | 96 | CPPUNIT_ASSERT(tafel->LoadHBondLengthsDatabase(HbonddistanceDBstream) && "HBond distance entry of element initialization failed"); | 
|---|
| [4eb4fe] | 97 | // check presence of elements | 
|---|
|  | 98 | atomicNumber_t Z = 1; | 
|---|
|  | 99 | for(periodentafel::const_iterator ElementRunner = tafel->begin(); ElementRunner != tafel->end(); ++ElementRunner) | 
|---|
|  | 100 | CPPUNIT_ASSERT( (ElementRunner->second->getNumber() == Z++) && "element is missing in sequence"); | 
|---|
|  | 101 | }; | 
|---|