source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 46d958

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

Made the world solely responsible for creating and destroying atoms.

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