source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 975a11

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