source: src/unittests/analysisbondsunittest.cpp@ 5e5283

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 5e5283 was 9b6b2f, checked in by Frederik Heber <heber@…>, 15 years ago

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * analysisbondsunittest.cpp
3 *
4 * Created on: Nov 7, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <iostream>
15#include <stdio.h>
16#include <cstring>
17
18#include "analysis_bonds.hpp"
19#include "analysisbondsunittest.hpp"
20#include "atom.hpp"
21#include "bond.hpp"
22#include "bondgraph.hpp"
23#include "element.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
26
27#ifdef HAVE_TESTRUNNER
28#include "UnitTestMain.hpp"
29#endif /*HAVE_TESTRUNNER*/
30
31/********************************************** Test classes **************************************/
32
33// Registers the fixture into the 'registry'
34CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisBondsTest );
35
36
37void AnalysisBondsTest::setUp()
38{
39 atom *Walker = NULL;
40
41 // init private all pointers to zero
42 TestMolecule = NULL;
43 hydrogen = NULL;
44 tafel = NULL;
45
46 // construct element
47 hydrogen = new element;
48 hydrogen->Z = 1;
49 hydrogen->Valence = 1;
50 hydrogen->NoValenceOrbitals = 1;
51 strcpy(hydrogen->name, "hydrogen");
52 strcpy(hydrogen->symbol, "H");
53 carbon = new element;
54 carbon->Z = 1;
55 carbon->Valence = 4;
56 carbon->NoValenceOrbitals = 4;
57 strcpy(carbon->name, "carbon");
58 strcpy(carbon->symbol, "C");
59
60
61 // construct periodentafel
62 tafel = new periodentafel;
63 tafel->AddElement(hydrogen);
64 tafel->AddElement(carbon);
65
66 // construct molecule (tetraeder of hydrogens)
67 TestMolecule = new molecule(tafel);
68 Walker = new atom();
69 Walker->type = hydrogen;
70 Walker->node->Init(1.5, 0., 1.5 );
71 TestMolecule->AddAtom(Walker);
72 Walker = new atom();
73 Walker->type = hydrogen;
74 Walker->node->Init(0., 1.5, 1.5 );
75 TestMolecule->AddAtom(Walker);
76 Walker = new atom();
77 Walker->type = hydrogen;
78 Walker->node->Init(1.5, 1.5, 0. );
79 TestMolecule->AddAtom(Walker);
80 Walker = new atom();
81 Walker->type = hydrogen;
82 Walker->node->Init(0., 0., 0. );
83 TestMolecule->AddAtom(Walker);
84 Walker = new atom();
85 Walker->type = carbon;
86 Walker->node->Init(0.5, 0.5, 0.5 );
87 TestMolecule->AddAtom(Walker);
88
89 // check that TestMolecule was correctly constructed
90 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
91
92 // create a small file with table
93 filename = new string("test.dat");
94 ofstream test(filename->c_str());
95 test << ".\tH\tC\n";
96 test << "H\t1.\t1.2\n";
97 test << "C\t1.2\t1.5\n";
98 test.close();
99 BG = new BondGraph(true);
100
101 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
102 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
103 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
104 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
105
106 BG->ConstructBondGraph(TestMolecule);
107};
108
109
110void AnalysisBondsTest::tearDown()
111{
112 // remove the file
113 remove(filename->c_str());
114 delete(filename);
115 delete(BG);
116
117 // remove molecule
118 delete(TestMolecule);
119 // note that all the atoms are cleaned by TestMolecule
120 delete(tafel);
121 // note that element is cleaned by periodentafel
122};
123
124/** UnitTest for GetMaxMinMeanBondCount().
125 */
126void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
127{
128 double Min = 20.; // check that initialization resets these arbitrary values
129 double Mean = 200.;
130 double Max = 1e-6;
131 GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
132 CPPUNIT_ASSERT_EQUAL( 1., Min );
133 CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
134 CPPUNIT_ASSERT_EQUAL( 4., Max );
135
136};
137
138/** UnitTest for MinMaxBondDistanceBetweenElements().
139 */
140void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
141{
142 double Min = 20.; // check that initialization resets these arbitrary values
143 double Mean = 2e+6;
144 double Max = 1e-6;
145 double Min2 = 20.;
146 double Mean2 = 2e+6;
147 double Max2 = 1e-6;
148 const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
149 const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
150 const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
151 // check bond lengths C-H
152 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
153 CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
154 CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
155 CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
156
157 // check that elements are symmetric, i.e. C-H == H-C
158 MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
159 CPPUNIT_ASSERT_EQUAL( Min , Min2 );
160 CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
161 CPPUNIT_ASSERT_EQUAL( Max , Max2 );
162
163 // check no bond case (no bonds H-H in system!)
164 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
165 CPPUNIT_ASSERT_EQUAL( 0. , Min );
166 CPPUNIT_ASSERT_EQUAL( 0. , Mean );
167 CPPUNIT_ASSERT_EQUAL( 0. , Max );
168};
Note: See TracBrowser for help on using the repository browser.