source: src/Element/unittests/PeriodentafelUnitTest.cpp@ 88bb6b

Last change on this file since 88bb6b was 94d5ac6, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
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/>.
21 */
22
23/*
24 * PeriodentafelUnitTest.cpp
25 *
26 * Created on: May 18, 2010
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include <sstream>
42#include <iostream>
43
44#include "CodePatterns/Assert.hpp"
45
46#include "Element/element.hpp"
47#include "Element/elements_db.hpp"
48#include "Element/periodentafel.hpp"
49
50#include "PeriodentafelUnitTest.hpp"
51
52// include headers that implement a archive in simple text format
53#include <boost/archive/text_oarchive.hpp>
54#include <boost/archive/text_iarchive.hpp>
55
56#ifdef HAVE_TESTRUNNER
57#include "UnitTestMain.hpp"
58#endif /*HAVE_TESTRUNNER*/
59
60/********************************************** Test classes **************************************/
61
62// Registers the fixture into the 'registry'
63CPPUNIT_TEST_SUITE_REGISTRATION( periodentafelTest );
64
65
66void periodentafelTest::setUp()
67{
68 // make sure world is present
69 tafel = new periodentafel(true);
70 CPPUNIT_ASSERT(tafel != NULL && "could not obtain periodentafel");
71};
72
73
74void periodentafelTest::tearDown()
75{
76 delete tafel;
77};
78
79/** UnitTest for AddRemoveTest().
80 */
81void periodentafelTest::AddRemoveTest()
82{
83 // copy the element
84 const element * ElementPtr = tafel->FindElement(3);
85 CPPUNIT_ASSERT( ElementPtr != NULL && "could not find element lithium");
86 element *Elemental = new element(*ElementPtr);
87 // remove element
88 tafel->RemoveElement((element * const)ElementPtr);
89 ElementPtr = tafel->FindElement(3);
90 CPPUNIT_ASSERT_EQUAL( (const element *)NULL, ElementPtr );
91 // add element again
92 tafel->AddElement((element * const)Elemental);
93 ElementPtr = tafel->FindElement(3);
94 CPPUNIT_ASSERT( ElementPtr != NULL && "could not find re-added element lithium");
95};
96
97/** UnitTest for LoadStoreTest().
98 * TODO: periodentafelTest::LoadStoreTest() not implemented yet
99 */
100void periodentafelTest::LoadStoreTest()
101{
102 // reload all databases
103 stringstream elementsDBstream(elementsDB,ios_base::in);
104 stringstream ElectronegativityDBstream(ElectronegativitiesDB,ios_base::in);
105 stringstream valenceDBstream(valenceDB,ios_base::in);
106 stringstream orbitalsDBstream(orbitalsDB,ios_base::in);
107 stringstream HbondangleDBstream(HbondangleDB,ios_base::in);
108 stringstream HbonddistanceDBstream(HbonddistanceDB,ios_base::in);
109 stringstream ColorDBstream(ColorDB,ios_base::in);
110 CPPUNIT_ASSERT(tafel->LoadElementsDatabase(elementsDBstream) && "General element initialization failed");
111 CPPUNIT_ASSERT(tafel->LoadElectronegativityDatabase(ElectronegativityDBstream) && "Electronegativity entry of element initialization failed");
112 CPPUNIT_ASSERT(tafel->LoadValenceDatabase(valenceDBstream) && "Valence entry of element initialization failed");
113 CPPUNIT_ASSERT(tafel->LoadOrbitalsDatabase(orbitalsDBstream) && "Orbitals entry of element initialization failed");
114 CPPUNIT_ASSERT(tafel->LoadHBondAngleDatabase(HbondangleDBstream) && "HBond angle entry of element initialization failed");
115 CPPUNIT_ASSERT(tafel->LoadHBondLengthsDatabase(HbonddistanceDBstream) && "HBond distance entry of element initialization failed");
116 CPPUNIT_ASSERT(tafel->LoadColorDatabase(ColorDBstream) && "color entry of element initialization failed");
117 // check presence of elements
118 atomicNumber_t Z = 1;
119 for(periodentafel::const_iterator ElementRunner = tafel->begin(); ElementRunner != tafel->end(); ++ElementRunner)
120 CPPUNIT_ASSERT( (ElementRunner->second->getAtomicNumber() == Z++) && "element is missing in sequence");
121};
122
123/** UnitTest for serialization
124 *
125 */
126void periodentafelTest::ComparisonTest()
127{
128 periodentafel *newtafel = new periodentafel(true);
129
130 CPPUNIT_ASSERT (*newtafel == *tafel );
131
132 element *Elemental = new element();
133 newtafel->AddElement((element * const)Elemental);
134
135 CPPUNIT_ASSERT (*newtafel != *tafel );
136
137 delete newtafel;
138}
139
140std::string gatherUndoInformation(const periodentafel *tafel)
141{
142 // create undo state
143 std::stringstream undostream;
144 boost::archive::text_oarchive oa(undostream);
145 oa << tafel;
146 return undostream.str();
147}
148
149/** UnitTest for serialization
150 *
151 */
152void periodentafelTest::SerializeTest()
153{
154 // write element to stream
155 std::stringstream stream(gatherUndoInformation(tafel));
156// boost::archive::text_oarchive oa(stream);
157// oa << World::getInstance().getPeriode();
158// //oa << tafel;
159//
160// //std::cout << "Contents of archive is " << stream.str() << std::endl;
161//
162// // create and open an archive for input
163 boost::archive::text_iarchive ia(stream);
164 // read class state from archive
165 periodentafel * newtafel;
166
167 ia >> newtafel;
168
169 CPPUNIT_ASSERT (*tafel == *newtafel);
170}
Note: See TracBrowser for help on using the repository browser.