source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ a7b761b

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 Candidate_v1.7.0 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 a7b761b was a7b761b, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge branch 'MoleculeStartEndSwitch' into StructureRefactoring

Conflicts:

molecuilder/src/Helpers/Assert.cpp
molecuilder/src/Helpers/Assert.hpp
molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/Patterns/Cacheable.hpp
molecuilder/src/Patterns/Observer.cpp
molecuilder/src/Patterns/Observer.hpp
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule.hpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/ObserverTest.cpp
molecuilder/src/unittests/ObserverTest.hpp

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