source: src/unittests/tesselationunittest.cpp@ bd58fb

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

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 6.7 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 "tesselation.hpp"
19#include "tesselationunittest.hpp"
20
21#ifdef HAVE_TESTRUNNER
22#include "UnitTestMain.hpp"
23#endif /*HAVE_TESTRUNNER*/
24
25#define SPHERERADIUS 2.
26
27/********************************************** Test classes **************************************/
28
29// Registers the fixture into the 'registry'
30CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
31
32
33void TesselationTest::setUp()
34{
35 // create corners
36 class TesselPoint *Walker;
37 Walker = new TesselPoint;
38 Walker->node = new Vector(1., 0., -1.);
39 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
40 strcpy(Walker->Name, "1");
41 Walker->nr = 1;
42 Corners.push_back(Walker);
43 Walker = new TesselPoint;
44 Walker->node = new Vector(-1., 1., -1.);
45 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
46 strcpy(Walker->Name, "2");
47 Walker->nr = 2;
48 Corners.push_back(Walker);
49 Walker = new TesselPoint;
50 Walker->node = new Vector(-1., -1., -1.);
51 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
52 strcpy(Walker->Name, "3");
53 Walker->nr = 3;
54 Corners.push_back(Walker);
55 Walker = new TesselPoint;
56 Walker->node = new Vector(-1., 0., 1.);
57 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
58 strcpy(Walker->Name, "4");
59 Walker->nr = 4;
60 Corners.push_back(Walker);
61
62 // create linkedcell
63 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
64
65 // create tesselation
66 TesselStruct = new Tesselation;
67 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
68 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
69 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
70 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
71
72 CandidateForTesselation *baseline = NULL;
73 BoundaryTriangleSet *T = NULL;
74 bool OneLoopWithoutSuccessFlag = true;
75 bool TesselationFailFlag = false;
76 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
77 // 2a. fill all new OpenLines
78 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
79 baseline = Runner->second;
80 if (baseline->pointlist.empty()) {
81 T = (((baseline->BaseLine->triangles.begin()))->second);
82 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
83 }
84 }
85
86 // 2b. search for smallest ShortestAngle among all candidates
87 double ShortestAngle = 4.*M_PI;
88 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
89 if (Runner->second->ShortestAngle < ShortestAngle) {
90 baseline = Runner->second;
91 ShortestAngle = baseline->ShortestAngle;
92 }
93 }
94 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
95 OneLoopWithoutSuccessFlag = false;
96 else {
97 TesselStruct->AddCandidateTriangle(*baseline);
98 }
99 }
100};
101
102
103void TesselationTest::tearDown()
104{
105 delete(LinkedList);
106 delete(TesselStruct);
107 for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
108 delete((*Runner)->node);
109 delete(*Runner);
110 }
111 Corners.clear();
112 MemoryUsageObserver::purgeInstance();
113 logger::purgeInstance();
114 errorLogger::purgeInstance();
115};
116
117/** UnitTest for Contains...()
118 *
119 */
120void TesselationTest::ContainmentTest()
121{
122 class BoundaryPointSet *point = NULL;
123 class BoundaryLineSet *line = NULL;
124
125 // check ContainsBoundaryPoint
126 for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
127 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
128 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
129 }
130 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
131 for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
132 point = PointRunner->second;
133 for (int i=0;i<3;i++)
134 if (point == (Runner->second)->endpoints[i])
135 point = NULL;
136 if (point != NULL)
137 break;
138 }
139 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
140 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
141 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
142 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
143 }
144
145 // check ContainsBoundaryLine
146 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
147 for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
148 line = LineRunner->second;
149 for (int i=0;i<3;i++)
150 if (line == (Runner->second)->lines[i])
151 line = NULL;
152 if (line != NULL)
153 break;
154 }
155 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
156 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
157 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
158 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
159 }
160
161 // check IsPresentTupel
162 CPPUNIT_ASSERT_EQUAL( true, true );
163}
164
165/** UnitTest for Tesselation::GetAllTriangles()
166 *
167 */
168void TesselationTest::GetAllTrianglesTest()
169{
170 class BoundaryPointSet *Walker = NULL;
171
172 // check that there are three adjacent triangles for every boundary point
173 for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
174 Walker = Runner->second;
175 set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
176 CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
177 // check that the returned triangle all contain the Walker
178 for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
179 CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
180 delete(triangles);
181 }
182}
Note: See TracBrowser for help on using the repository browser.