source: src/unittests/ElementUnitTest.cpp@ 3bdb6d

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 3bdb6d was 3bdb6d, checked in by Frederik Heber <heber@…>, 13 years ago

Moved all stuff related to elements into own subfolder and has its own convenience library.

  • this induced massive changes in includes in other files.
  • we adapted PeriodentafelUnitTest to not get instance from world, but we create it ourselves.
  • also moved all .db files related to elements into subfolder Element/.
  • Property mode set to 100644
File size: 4.4 KB
Line 
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
8/*
9 * ElementUnitTest.cpp
10 *
11 * Created on: Oct 29, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include <sstream>
27
28#include "Element/element.hpp"
29
30// include headers that implement a archive in simple text format
31#include <boost/archive/text_oarchive.hpp>
32#include <boost/archive/text_iarchive.hpp>
33
34#include "ElementUnitTest.hpp"
35
36#ifdef HAVE_TESTRUNNER
37#include "UnitTestMain.hpp"
38#endif /*HAVE_TESTRUNNER*/
39
40/********************************************** Test classes **************************************/
41
42// Registers the fixture into the 'registry'
43CPPUNIT_TEST_SUITE_REGISTRATION( ElementTest );
44
45
46void ElementTest::setUp()
47{
48 testelement = new element();
49 testelement->setSymbol("H");
50};
51
52
53void ElementTest::tearDown()
54{
55 delete testelement;
56};
57
58/** Test whether assignment works
59 *
60 */
61void ElementTest::AssignmentTest()
62{
63 element * otherelement = new element();
64 element * const backup = otherelement;
65 CPPUNIT_ASSERT( otherelement != testelement );
66 otherelement = testelement;
67 CPPUNIT_ASSERT( otherelement == testelement );
68 otherelement = backup;
69 *otherelement = *testelement;
70 CPPUNIT_ASSERT( *otherelement == *testelement );
71 delete backup;
72
73 otherelement = new element(*testelement);
74 CPPUNIT_ASSERT( otherelement != testelement );
75 CPPUNIT_ASSERT( *otherelement == *testelement );
76 delete otherelement;
77}
78
79/** Test whether the getters are working.
80 *
81 */
82void ElementTest::GetterTest()
83{
84 CPPUNIT_ASSERT_EQUAL( (atomId_t)0, testelement->getNumber() );
85 CPPUNIT_ASSERT_EQUAL( 0., testelement->getMass() );
86 const unsigned char * color = testelement->getColor();
87 for (size_t i = 0; i < 3; ++i)
88 CPPUNIT_ASSERT_EQUAL( (unsigned char)0, color[i] );
89 CPPUNIT_ASSERT_EQUAL( 0., testelement->getCovalentRadius() );
90 CPPUNIT_ASSERT_EQUAL( 0., testelement->getElectronegativity() );
91 CPPUNIT_ASSERT_EQUAL( 0., testelement->getVanDerWaalsRadius() );
92 CPPUNIT_ASSERT_EQUAL( 0, testelement->getAtomicNumber() );
93 CPPUNIT_ASSERT_EQUAL( 0., testelement->getValence() );
94 CPPUNIT_ASSERT_EQUAL( 0, testelement->getNoValenceOrbitals() );
95 CPPUNIT_ASSERT_EQUAL( 0, testelement->getNoValenceOrbitals() );
96 for (size_t i = 0; i < 3; ++i)
97 CPPUNIT_ASSERT_EQUAL( 0., testelement->getHBondDistance(i) );
98 for (size_t i = 0; i < 3; ++i)
99 CPPUNIT_ASSERT_EQUAL( 0., testelement->getHBondAngle(i) );
100}
101
102/** Test whether the setters are working.
103 *
104 */
105void ElementTest::SetterTest()
106{
107 // symbol
108 CPPUNIT_ASSERT( testelement->getSymbol() != std::string("He") );
109 testelement->setSymbol("He");
110 CPPUNIT_ASSERT_EQUAL( std::string("He"), testelement->getSymbol() );
111
112 // name
113 CPPUNIT_ASSERT( testelement->getName() != std::string("Helium") );
114 testelement->setName("Helium");
115 CPPUNIT_ASSERT_EQUAL( std::string("Helium"), testelement->getName() );
116}
117
118/** Unit test for operator==()
119 */
120void ElementTest::ComparisonTest()
121{
122 testelement->setSymbol("He");
123 testelement->setName("Helium");
124 element * newelement = new element();
125 newelement->setSymbol("H");
126 newelement->setName("Hydrogen");
127
128 CPPUNIT_ASSERT( *testelement != *newelement );
129
130 newelement->setSymbol("He");
131 newelement->setName("Helium");
132
133 CPPUNIT_ASSERT( *testelement == *newelement );
134
135 delete newelement;
136}
137
138/** Tests whether serialization of the class works
139 */
140void ElementTest::SerializeTest()
141{
142 const std::string he("He");
143 const std::string helium("Helium");
144 testelement->setSymbol(he);
145 testelement->setName(helium);
146
147 CPPUNIT_ASSERT_EQUAL ( he, testelement->getSymbol() );
148 CPPUNIT_ASSERT_EQUAL( helium, testelement->getName() );
149
150 // write element to stream
151 std::stringstream stream;
152 boost::archive::text_oarchive oa(stream);
153 oa << testelement;
154
155 std::cout << "Contents of archive is " << stream.str() << std::endl;
156
157 // create and open an archive for input
158 boost::archive::text_iarchive ia(stream);
159 // read class state from archive
160 element * newelement;
161
162 ia >> newelement;
163
164 CPPUNIT_ASSERT_EQUAL( he, newelement->getSymbol() );
165 CPPUNIT_ASSERT_EQUAL( helium, newelement->getName() );
166
167 CPPUNIT_ASSERT (*testelement == *newelement);
168
169 delete newelement;
170};
Note: See TracBrowser for help on using the repository browser.