[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[bcf653] | 21 | */
|
---|
| 22 |
|
---|
[4eb4fe] | 23 | /*
|
---|
[f844ef] | 24 | * PeriodentafelUnitTest.cpp
|
---|
[4eb4fe] | 25 | *
|
---|
| 26 | * Created on: May 18, 2010
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[bf3817] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[4eb4fe] | 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
[e5c0a1] | 41 | #include <sstream>
|
---|
| 42 | #include <iostream>
|
---|
| 43 |
|
---|
[ad011c] | 44 | #include "CodePatterns/Assert.hpp"
|
---|
[4eb4fe] | 45 |
|
---|
[3bdb6d] | 46 | #include "Element/element.hpp"
|
---|
[37ef6d] | 47 | #include "Element/ion.hpp"
|
---|
[3bdb6d] | 48 | #include "Element/elements_db.hpp"
|
---|
| 49 | #include "Element/periodentafel.hpp"
|
---|
[4eb4fe] | 50 |
|
---|
[f844ef] | 51 | #include "PeriodentafelUnitTest.hpp"
|
---|
| 52 |
|
---|
[b60804] | 53 | // include headers that implement a archive in simple text format
|
---|
| 54 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 55 | #include <boost/archive/text_iarchive.hpp>
|
---|
| 56 |
|
---|
[4eb4fe] | 57 | #ifdef HAVE_TESTRUNNER
|
---|
| 58 | #include "UnitTestMain.hpp"
|
---|
| 59 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 60 |
|
---|
| 61 | /********************************************** Test classes **************************************/
|
---|
| 62 |
|
---|
| 63 | // Registers the fixture into the 'registry'
|
---|
| 64 | CPPUNIT_TEST_SUITE_REGISTRATION( periodentafelTest );
|
---|
| 65 |
|
---|
| 66 |
|
---|
| 67 | void periodentafelTest::setUp()
|
---|
| 68 | {
|
---|
| 69 | // make sure world is present
|
---|
[4ae823] | 70 | tafel = new periodentafel(true);
|
---|
[4eb4fe] | 71 | CPPUNIT_ASSERT(tafel != NULL && "could not obtain periodentafel");
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | void periodentafelTest::tearDown()
|
---|
| 76 | {
|
---|
[3bdb6d] | 77 | delete tafel;
|
---|
[4eb4fe] | 78 | };
|
---|
| 79 |
|
---|
| 80 | /** UnitTest for AddRemoveTest().
|
---|
| 81 | */
|
---|
| 82 | void periodentafelTest::AddRemoveTest()
|
---|
| 83 | {
|
---|
| 84 | // copy the element
|
---|
| 85 | const element * ElementPtr = tafel->FindElement(3);
|
---|
| 86 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find element lithium");
|
---|
| 87 | element *Elemental = new element(*ElementPtr);
|
---|
| 88 | // remove element
|
---|
| 89 | tafel->RemoveElement((element * const)ElementPtr);
|
---|
| 90 | ElementPtr = tafel->FindElement(3);
|
---|
| 91 | CPPUNIT_ASSERT_EQUAL( (const element *)NULL, ElementPtr );
|
---|
| 92 | // add element again
|
---|
| 93 | tafel->AddElement((element * const)Elemental);
|
---|
| 94 | ElementPtr = tafel->FindElement(3);
|
---|
| 95 | CPPUNIT_ASSERT( ElementPtr != NULL && "could not find re-added element lithium");
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 | /** UnitTest for LoadStoreTest().
|
---|
| 99 | * TODO: periodentafelTest::LoadStoreTest() not implemented yet
|
---|
| 100 | */
|
---|
| 101 | void periodentafelTest::LoadStoreTest()
|
---|
| 102 | {
|
---|
| 103 | // reload all databases
|
---|
[e5c0a1] | 104 | stringstream elementsDBstream(elementsDB,ios_base::in);
|
---|
[67c92b] | 105 | stringstream ElectronegativityDBstream(ElectronegativitiesDB,ios_base::in);
|
---|
| 106 | stringstream valenceDBstream(valenceDB,ios_base::in);
|
---|
| 107 | stringstream orbitalsDBstream(orbitalsDB,ios_base::in);
|
---|
| 108 | stringstream HbondangleDBstream(HbondangleDB,ios_base::in);
|
---|
| 109 | stringstream HbonddistanceDBstream(HbonddistanceDB,ios_base::in);
|
---|
[064178] | 110 | stringstream ColorDBstream(ColorDB,ios_base::in);
|
---|
[e5c0a1] | 111 | CPPUNIT_ASSERT(tafel->LoadElementsDatabase(elementsDBstream) && "General element initialization failed");
|
---|
[67c92b] | 112 | CPPUNIT_ASSERT(tafel->LoadElectronegativityDatabase(ElectronegativityDBstream) && "Electronegativity entry of element initialization failed");
|
---|
| 113 | CPPUNIT_ASSERT(tafel->LoadValenceDatabase(valenceDBstream) && "Valence entry of element initialization failed");
|
---|
| 114 | CPPUNIT_ASSERT(tafel->LoadOrbitalsDatabase(orbitalsDBstream) && "Orbitals entry of element initialization failed");
|
---|
| 115 | CPPUNIT_ASSERT(tafel->LoadHBondAngleDatabase(HbondangleDBstream) && "HBond angle entry of element initialization failed");
|
---|
| 116 | CPPUNIT_ASSERT(tafel->LoadHBondLengthsDatabase(HbonddistanceDBstream) && "HBond distance entry of element initialization failed");
|
---|
[064178] | 117 | CPPUNIT_ASSERT(tafel->LoadColorDatabase(ColorDBstream) && "color entry of element initialization failed");
|
---|
[4eb4fe] | 118 | // check presence of elements
|
---|
| 119 | atomicNumber_t Z = 1;
|
---|
| 120 | for(periodentafel::const_iterator ElementRunner = tafel->begin(); ElementRunner != tafel->end(); ++ElementRunner)
|
---|
[ed26ae] | 121 | CPPUNIT_ASSERT( (ElementRunner->second->getAtomicNumber() == Z++) && "element is missing in sequence");
|
---|
[4eb4fe] | 122 | };
|
---|
[b60804] | 123 |
|
---|
| 124 | /** UnitTest for serialization
|
---|
| 125 | *
|
---|
| 126 | */
|
---|
| 127 | void periodentafelTest::ComparisonTest()
|
---|
| 128 | {
|
---|
[4ae823] | 129 | periodentafel *newtafel = new periodentafel(true);
|
---|
[b60804] | 130 |
|
---|
| 131 | CPPUNIT_ASSERT (*newtafel == *tafel );
|
---|
| 132 |
|
---|
| 133 | element *Elemental = new element();
|
---|
| 134 | newtafel->AddElement((element * const)Elemental);
|
---|
| 135 |
|
---|
| 136 | CPPUNIT_ASSERT (*newtafel != *tafel );
|
---|
| 137 |
|
---|
| 138 | delete newtafel;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[3bdb6d] | 141 | std::string gatherUndoInformation(const periodentafel *tafel)
|
---|
[b60804] | 142 | {
|
---|
| 143 | // create undo state
|
---|
| 144 | std::stringstream undostream;
|
---|
| 145 | boost::archive::text_oarchive oa(undostream);
|
---|
[3bdb6d] | 146 | oa << tafel;
|
---|
[b60804] | 147 | return undostream.str();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | /** UnitTest for serialization
|
---|
| 151 | *
|
---|
| 152 | */
|
---|
| 153 | void periodentafelTest::SerializeTest()
|
---|
| 154 | {
|
---|
| 155 | // write element to stream
|
---|
[3bdb6d] | 156 | std::stringstream stream(gatherUndoInformation(tafel));
|
---|
[b60804] | 157 | // boost::archive::text_oarchive oa(stream);
|
---|
| 158 | // oa << World::getInstance().getPeriode();
|
---|
| 159 | // //oa << tafel;
|
---|
| 160 | //
|
---|
| 161 | // //std::cout << "Contents of archive is " << stream.str() << std::endl;
|
---|
| 162 | //
|
---|
| 163 | // // create and open an archive for input
|
---|
| 164 | boost::archive::text_iarchive ia(stream);
|
---|
| 165 | // read class state from archive
|
---|
| 166 | periodentafel * newtafel;
|
---|
| 167 |
|
---|
| 168 | ia >> newtafel;
|
---|
| 169 |
|
---|
| 170 | CPPUNIT_ASSERT (*tafel == *newtafel);
|
---|
| 171 | }
|
---|