source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ e6fdbe

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

MEMLEAK: In many tests World, MemoryUsageObserver, logger or errorLogger being singletons were instantiated but not destroyed.

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