source: src/unittests/tesselationunittest.cpp@ b5c53d

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 b5c53d was 88b400, checked in by Frederik Heber <heber@…>, 14 years ago

converted #define's to enums, consts and typedefs [Meyers, "Effective C++", item 1].

basic changes:

  • #define bla 1.3 -> const double bla = 1.3
  • #define bla "test" -> const char * const bla = "test
  • use class specific constants! (HULLEPSILON)

const int Class::bla = 1.3; (in .cpp)
static const int bla; (in .hpp inside class private section)

  • "enum hack": #define bla 5 -> enum { bla = 5 };
    • if const int bla=5; impossible
    • e.g. necessary if constant is used in array declaration (int blabla[bla];)

details:

  • new file defs.cpp where const double reside in and are referenced by extern "C" const double
  • joiner.cpp: main() had to be changed due to concatenation of two #define possible, of two const char * not
  • class specific constants: HULLEPSILON, BONDTHRESHOLD, SPHERERADIUS
  • extended GetPathLengthonCircumCircle to additional parameter HULLEPSILON
  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * tesselationunittest.cpp
3 *
4 * Created on: Aug 26, 2009
5 * Author: heber
6 */
7
8
9using namespace std;
10
11#include <cppunit/CompilerOutputter.h>
12#include <cppunit/extensions/TestFactoryRegistry.h>
13#include <cppunit/ui/text/TestRunner.h>
14
15#include <cstring>
16
17#include "defs.hpp"
18#include "TesselPoint.hpp"
19#include "BoundaryLineSet.hpp"
20#include "BoundaryTriangleSet.hpp"
21#include "CandidateForTesselation.hpp"
22#include "tesselationunittest.hpp"
23
24#ifdef HAVE_TESTRUNNER
25#include "UnitTestMain.hpp"
26#endif /*HAVE_TESTRUNNER*/
27
28const double TesselationTest::SPHERERADIUS=2.;
29
30/********************************************** Test classes **************************************/
31
32// Registers the fixture into the 'registry'
33CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
34
35
36void TesselationTest::setUp()
37{
38 // create corners
39 class TesselPoint *Walker;
40 Walker = new TesselPoint;
41 Walker->setPosition(Vector(1., 0., -1.));
42 Walker->setName("1");
43 Walker->nr = 1;
44 Corners.push_back(Walker);
45 Walker = new TesselPoint;
46 Walker->setPosition(Vector(-1., 1., -1.));
47 Walker->setName("2");
48 Walker->nr = 2;
49 Corners.push_back(Walker);
50 Walker = new TesselPoint;
51 Walker->setPosition(Vector(-1., -1., -1.));
52 Walker->setName("3");
53 Walker->nr = 3;
54 Corners.push_back(Walker);
55 Walker = new TesselPoint;
56 Walker->setPosition(Vector(-1., 0., 1.));
57 Walker->setName("4");
58 Walker->nr = 4;
59 Corners.push_back(Walker);
60
61 // create linkedcell
62 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
63
64 // create tesselation
65 TesselStruct = new Tesselation;
66 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
67 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
68 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
69 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
70
71 CandidateForTesselation *baseline = NULL;
72 BoundaryTriangleSet *T = NULL;
73 bool OneLoopWithoutSuccessFlag = true;
74 bool TesselationFailFlag = false;
75 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
76 // 2a. fill all new OpenLines
77 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
78 baseline = Runner->second;
79 if (baseline->pointlist.empty()) {
80 T = (((baseline->BaseLine->triangles.begin()))->second);
81 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
82 }
83 }
84
85 // 2b. search for smallest ShortestAngle among all candidates
86 double ShortestAngle = 4.*M_PI;
87 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
88 if (Runner->second->ShortestAngle < ShortestAngle) {
89 baseline = Runner->second;
90 ShortestAngle = baseline->ShortestAngle;
91 }
92 }
93 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
94 OneLoopWithoutSuccessFlag = false;
95 else {
96 TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
97 }
98 }
99};
100
101
102void TesselationTest::tearDown()
103{
104 delete(LinkedList);
105 delete(TesselStruct);
106 for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
107 delete(*Runner);
108 Corners.clear();
109 logger::purgeInstance();
110 errorLogger::purgeInstance();
111};
112
113/** UnitTest for Contains...()
114 *
115 */
116void TesselationTest::ContainmentTest()
117{
118 class BoundaryPointSet *point = NULL;
119 class BoundaryLineSet *line = NULL;
120
121 // check ContainsBoundaryPoint
122 for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
123 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
124 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
125 }
126 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
127 for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
128 point = PointRunner->second;
129 for (int i=0;i<3;i++)
130 if (point == (Runner->second)->endpoints[i])
131 point = NULL;
132 if (point != NULL)
133 break;
134 }
135 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
136 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
137 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
138 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
139 }
140
141 // check ContainsBoundaryLine
142 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
143 for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
144 line = LineRunner->second;
145 for (int i=0;i<3;i++)
146 if (line == (Runner->second)->lines[i])
147 line = NULL;
148 if (line != NULL)
149 break;
150 }
151 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
152 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
153 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
154 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
155 }
156
157 // check IsPresentTupel
158 CPPUNIT_ASSERT_EQUAL( true, true );
159}
160
161/** UnitTest for Tesselation::GetAllTriangles()
162 *
163 */
164void TesselationTest::GetAllTrianglesTest()
165{
166 class BoundaryPointSet *Walker = NULL;
167
168 // check that there are three adjacent triangles for every boundary point
169 for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
170 Walker = Runner->second;
171 set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
172 CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
173 // check that the returned triangle all contain the Walker
174 for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
175 CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
176 delete(triangles);
177 }
178}
Note: See TracBrowser for help on using the repository browser.