source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ cbc5fb

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

Made the world solely responsible for creating and erasing molecules.

  • Property mode set to 100644
File size: 7.0 KB
RevLine 
[c4d4df]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
[49e1ae]14#include <cstring>
15
[c4d4df]16#include "analysis_correlation.hpp"
17#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
18
[46d958]19#include "World.hpp"
[c4d4df]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
[a5551b]38 TestList = NULL;
[c4d4df]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");
[bbc338]51 strcpy(hydrogen->symbol, "H");
52 carbon = new element;
53 carbon->Z = 6;
54 strcpy(carbon->name, "carbon");
55 strcpy(carbon->symbol, "C");
[c4d4df]56
57 // construct periodentafel
[cbc5fb]58 tafel = World::get()->getPeriode();
[c4d4df]59 tafel->AddElement(hydrogen);
[bbc338]60 tafel->AddElement(carbon);
[c4d4df]61
[bbc338]62 // construct molecule (tetraeder of hydrogens) base
[cbc5fb]63 TestMolecule = World::get()->createMolecule();
[46d958]64 Walker = World::get()->createAtom();
[c4d4df]65 Walker->type = hydrogen;
66 Walker->node->Init(1., 0., 1. );
67 TestMolecule->AddAtom(Walker);
[46d958]68 Walker = World::get()->createAtom();
[c4d4df]69 Walker->type = hydrogen;
70 Walker->node->Init(0., 1., 1. );
71 TestMolecule->AddAtom(Walker);
[46d958]72 Walker = World::get()->createAtom();
[c4d4df]73 Walker->type = hydrogen;
74 Walker->node->Init(1., 1., 0. );
75 TestMolecule->AddAtom(Walker);
[46d958]76 Walker = World::get()->createAtom();
[c4d4df]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
[cbc5fb]84 TestList = World::get()->getMolecules();
[a5551b]85 TestMolecule->ActiveFlag = true;
86 TestList->insert(TestMolecule);
87
[c4d4df]88 // init tesselation and linked cell
89 Surface = new Tesselation;
[e138de]90 FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
[c4d4df]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
[bbc338]96 // add outer atoms
[46d958]97 Walker = World::get()->createAtom();
[bbc338]98 Walker->type = carbon;
99 Walker->node->Init(4., 0., 4. );
100 TestMolecule->AddAtom(Walker);
[46d958]101 Walker = World::get()->createAtom();
[bbc338]102 Walker->type = carbon;
103 Walker->node->Init(0., 4., 4. );
104 TestMolecule->AddAtom(Walker);
[46d958]105 Walker = World::get()->createAtom();
[bbc338]106 Walker->type = carbon;
107 Walker->node->Init(4., 4., 0. );
108 TestMolecule->AddAtom(Walker);
109 // add inner atoms
[46d958]110 Walker = World::get()->createAtom();
[bbc338]111 Walker->type = carbon;
112 Walker->node->Init(0.5, 0.5, 0.5 );
113 TestMolecule->AddAtom(Walker);
114
[c4d4df]115 // init maps
[bbc338]116 surfacemap = NULL;
[c4d4df]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
[776b64]129 delete(Surface);
130 // note that all the atoms are cleaned by TestMolecule
[c4d4df]131 delete(LC);
[cbc5fb]132 World::destroy();
[c4d4df]133};
134
135
136void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
137{
138 // do the pair correlation
[e138de]139 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[c4d4df]140 CPPUNIT_ASSERT( surfacemap != NULL );
141 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
142};
143
[bbc338]144void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
[c4d4df]145{
146 BinPairMap::iterator tester;
[e138de]147 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[c4d4df]148 // put pair correlation into bins and check with no range
[e138de]149 binmap = BinData( surfacemap, 0.5, 0., 0. );
[c4d4df]150 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
[e138de]151 //OutputCorrelation ( binmap );
[c4d4df]152 tester = binmap->begin();
153 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
154 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
155
156};
157
[bbc338]158void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
[c4d4df]159{
160 BinPairMap::iterator tester;
[e138de]161 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
[c4d4df]162 // ... and check with [0., 2.] range
[e138de]163 binmap = BinData( surfacemap, 0.5, 0., 2. );
[c4d4df]164 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
[e138de]165 //OutputCorrelation ( binmap );
[c4d4df]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
[bbc338]175void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
176{
177 BinPairMap::iterator tester;
[e138de]178 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
[bbc338]179 // put pair correlation into bins and check with no range
[e138de]180 binmap = BinData( surfacemap, 0.5, 0., 0. );
[bbc338]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
[7ea9e6]188 tester = binmap->lower_bound(-0.5);
[bbc338]189 CPPUNIT_ASSERT( tester != binmap->end() );
190 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
191};
192
193void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
194{
195 BinPairMap::iterator tester;
[e138de]196 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
[bbc338]197 // ... and check with [0., 2.] range
[e138de]198 binmap = BinData( surfacemap, 0.5, -2., 4. );
[bbc338]199 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
200 OutputCorrelation ( (ofstream *)&cout, binmap );
201 // three outside points
[7ea9e6]202 tester = binmap->lower_bound(3.);
[bbc338]203 CPPUNIT_ASSERT( tester != binmap->end() );
204 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
205 // inner point
[7ea9e6]206 tester = binmap->lower_bound(-0.5);
[bbc338]207 CPPUNIT_ASSERT( tester != binmap->end() );
208 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
209
210};
211
[c4d4df]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.