source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 776b64

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

Huge refactoring to make const what is const (ticket #38), continued.

  • too many changes because of too many cross-references to be able to list them up here.
  • NOTE that "make check" runs fine and did catch several error.
  • note that we had to use const_iterator several times when the map, ... was declared const.
  • at times we changed an allocated LinkedCell LCList(...) into

const LinkedCell *LCList;
LCList = new LinkedCell(...);

  • also mutable (see ticket #5) was used, e.g. for molecule::InternalPointer (PointCloud changes are allowed, because they are just accounting).

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 7.0 KB
Line 
1/*
2 * AnalysisCorrelationToSurfaceUnitTest.cpp
3 *
4 * Created on: Oct 13, 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 "analysis_correlation.hpp"
15#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
16
17#include "atom.hpp"
18#include "boundary.hpp"
19#include "element.hpp"
20#include "molecule.hpp"
21#include "linkedcell.hpp"
22#include "periodentafel.hpp"
23#include "tesselation.hpp"
24
25/********************************************** Test classes **************************************/
26
27// Registers the fixture into the 'registry'
28CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
29
30void AnalysisCorrelationToSurfaceUnitTest::setUp()
31{
32 atom *Walker = NULL;
33
34 // init private all pointers to zero
35 TestMolecule = NULL;
36 hydrogen = NULL;
37 tafel = NULL;
38 surfacemap = NULL;
39 binmap = NULL;
40 Surface = NULL;
41 LC = NULL;
42
43
44 // construct element
45 hydrogen = new element;
46 hydrogen->Z = 1;
47 strcpy(hydrogen->name, "hydrogen");
48 strcpy(hydrogen->symbol, "H");
49 carbon = new element;
50 carbon->Z = 6;
51 strcpy(carbon->name, "carbon");
52 strcpy(carbon->symbol, "C");
53
54 // construct periodentafel
55 tafel = new periodentafel;
56 tafel->AddElement(hydrogen);
57 tafel->AddElement(carbon);
58
59 // construct molecule (tetraeder of hydrogens) base
60 TestMolecule = new molecule(tafel);
61 Walker = new atom();
62 Walker->type = hydrogen;
63 Walker->node->Init(1., 0., 1. );
64 TestMolecule->AddAtom(Walker);
65 Walker = new atom();
66 Walker->type = hydrogen;
67 Walker->node->Init(0., 1., 1. );
68 TestMolecule->AddAtom(Walker);
69 Walker = new atom();
70 Walker->type = hydrogen;
71 Walker->node->Init(1., 1., 0. );
72 TestMolecule->AddAtom(Walker);
73 Walker = new atom();
74 Walker->type = hydrogen;
75 Walker->node->Init(0., 0., 0. );
76 TestMolecule->AddAtom(Walker);
77
78 // check that TestMolecule was correctly constructed
79 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
80
81 // init tesselation and linked cell
82 Surface = new Tesselation;
83 FindNonConvexBorder((ofstream *)&cerr, TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
84 LC = new LinkedCell(TestMolecule, 5.);
85 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
86 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
87 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
88
89 // add outer atoms
90 Walker = new atom();
91 Walker->type = carbon;
92 Walker->node->Init(4., 0., 4. );
93 TestMolecule->AddAtom(Walker);
94 Walker = new atom();
95 Walker->type = carbon;
96 Walker->node->Init(0., 4., 4. );
97 TestMolecule->AddAtom(Walker);
98 Walker = new atom();
99 Walker->type = carbon;
100 Walker->node->Init(4., 4., 0. );
101 TestMolecule->AddAtom(Walker);
102 // add inner atoms
103 Walker = new atom();
104 Walker->type = carbon;
105 Walker->node->Init(0.5, 0.5, 0.5 );
106 TestMolecule->AddAtom(Walker);
107
108 // init maps
109 surfacemap = NULL;
110 binmap = NULL;
111
112};
113
114
115void AnalysisCorrelationToSurfaceUnitTest::tearDown()
116{
117 if (surfacemap != NULL)
118 delete(surfacemap);
119 if (binmap != NULL)
120 delete(binmap);
121
122 // remove
123 delete(TestMolecule);
124 delete(Surface);
125 // note that all the atoms are cleaned by TestMolecule
126 delete(LC);
127 delete(tafel);
128 // note that element is cleaned by periodentafel
129};
130
131
132void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
133{
134 // do the pair correlation
135 surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
136 CPPUNIT_ASSERT( surfacemap != NULL );
137 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
138};
139
140void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
141{
142 BinPairMap::iterator tester;
143 surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
144 // put pair correlation into bins and check with no range
145 binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 0. );
146 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
147 //OutputCorrelation ( (ofstream *)&cout, binmap );
148 tester = binmap->begin();
149 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
150 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
151
152};
153
154void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
155{
156 BinPairMap::iterator tester;
157 surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, hydrogen, Surface, LC );
158 // ... and check with [0., 2.] range
159 binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 2. );
160 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
161 //OutputCorrelation ( (ofstream *)&cout, binmap );
162 tester = binmap->begin();
163 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
164 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
165 tester = binmap->find(1.);
166 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
167 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
168
169};
170
171void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
172{
173 BinPairMap::iterator tester;
174 surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, carbon, Surface, LC );
175 // put pair correlation into bins and check with no range
176 binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, 0., 0. );
177 CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
178 OutputCorrelation ( (ofstream *)&cout, binmap );
179 // inside point is first and must have negative value
180 tester = binmap->lower_bound(2.95); // start depends on the min value and
181 CPPUNIT_ASSERT( tester != binmap->end() );
182 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
183 // inner point
184 tester = binmap->lower_bound(0.);
185 CPPUNIT_ASSERT( tester != binmap->end() );
186 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
187};
188
189void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
190{
191 BinPairMap::iterator tester;
192 surfacemap = CorrelationToSurface( (ofstream *)&cout, TestMolecule, carbon, Surface, LC );
193 // ... and check with [0., 2.] range
194 binmap = BinData( (ofstream *)&cout, surfacemap, 0.5, -2., 4. );
195 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
196 OutputCorrelation ( (ofstream *)&cout, binmap );
197 // three outside points
198 tester = binmap->find(3.);
199 CPPUNIT_ASSERT( tester != binmap->end() );
200 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
201 // inner point
202 tester = binmap->find(0.);
203 CPPUNIT_ASSERT( tester != binmap->end() );
204 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
205
206};
207
208/********************************************** Main routine **************************************/
209
210int main(int argc, char **argv)
211{
212 // Get the top level suite from the registry
213 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
214
215 // Adds the test to the list of test to run
216 CppUnit::TextUi::TestRunner runner;
217 runner.addTest( suite );
218
219 // Change the default outputter to a compiler error format outputter
220 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
221 std::cerr ) );
222 // Run the tests.
223 bool wasSucessful = runner.run();
224
225 // Return error code 1 if the one of test failed.
226 return wasSucessful ? 0 : 1;
227};
Note: See TracBrowser for help on using the repository browser.