source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 80c63d

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 80c63d was 80c63d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added more functionality to custom asserts.

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