source: src/unittests/TesselationUnitTest.cpp@ 1f91f4

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 1f91f4 was f844ef, checked in by Frederik Heber <heber@…>, 14 years ago

Renamed all remaining unit tests in src/unittests to Capitalized naming scheme.

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