source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ e138de

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

Huge change from ofstream * (const) out --> Log().

  • first shift was done via regular expressions
  • then via error messages from the code
  • note that class atom, class element and class molecule kept in parts their output stream, was they print to file.
  • make check runs fine
  • MISSING: Verbosity is not fixed for everything (i.e. if no endl; is present and next has Verbose(0) ...)

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

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