source: src/Element/unittests/ElementUnitTest.cpp@ ed26ae

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 ed26ae was ed26ae, checked in by Frederik Heber <heber@…>, 13 years ago

Renamed calls to element::getNumber() -> ::getAtomicNumber().

  • dropped element::getNumber() as getAtomicNumber has same functionality.
  • 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-2012 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->getAtomicNumber() );
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->getValence() );
93 CPPUNIT_ASSERT_EQUAL( 0, testelement->getNoValenceOrbitals() );
94 CPPUNIT_ASSERT_EQUAL( 0, testelement->getNoValenceOrbitals() );
95 for (size_t i = 0; i < 3; ++i)
96 CPPUNIT_ASSERT_EQUAL( 0., testelement->getHBondDistance(i) );
97 for (size_t i = 0; i < 3; ++i)
98 CPPUNIT_ASSERT_EQUAL( 0., testelement->getHBondAngle(i) );
99}
100
101/** Test whether the setters are working.
102 *
103 */
104void ElementTest::SetterTest()
105{
106 // symbol
107 CPPUNIT_ASSERT( testelement->getSymbol() != std::string("He") );
108 testelement->setSymbol("He");
109 CPPUNIT_ASSERT_EQUAL( std::string("He"), testelement->getSymbol() );
110
111 // name
112 CPPUNIT_ASSERT( testelement->getName() != std::string("Helium") );
113 testelement->setName("Helium");
114 CPPUNIT_ASSERT_EQUAL( std::string("Helium"), testelement->getName() );
115}
116
117/** Unit test for operator==()
118 */
119void ElementTest::ComparisonTest()
120{
121 testelement->setSymbol("He");
122 testelement->setName("Helium");
123 element * newelement = new element();
124 newelement->setSymbol("H");
125 newelement->setName("Hydrogen");
126
127 CPPUNIT_ASSERT( *testelement != *newelement );
128
129 newelement->setSymbol("He");
130 newelement->setName("Helium");
131
132 CPPUNIT_ASSERT( *testelement == *newelement );
133
134 delete newelement;
135}
136
137/** Tests whether serialization of the class works
138 */
139void ElementTest::SerializeTest()
140{
141 const std::string he("He");
142 const std::string helium("Helium");
143 testelement->setSymbol(he);
144 testelement->setName(helium);
145
146 CPPUNIT_ASSERT_EQUAL ( he, testelement->getSymbol() );
147 CPPUNIT_ASSERT_EQUAL( helium, testelement->getName() );
148
149 // write element to stream
150 std::stringstream stream;
151 boost::archive::text_oarchive oa(stream);
152 oa << testelement;
153
154 std::cout << "Contents of archive is " << stream.str() << std::endl;
155
156 // create and open an archive for input
157 boost::archive::text_iarchive ia(stream);
158 // read class state from archive
159 element * newelement;
160
161 ia >> newelement;
162
163 CPPUNIT_ASSERT_EQUAL( he, newelement->getSymbol() );
164 CPPUNIT_ASSERT_EQUAL( helium, newelement->getName() );
165
166 CPPUNIT_ASSERT (*testelement == *newelement);
167
168 delete newelement;
169};
Note: See TracBrowser for help on using the repository browser.