source: src/unittests/tesselationunittest.cpp@ 9fb860

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

Changes to FindClosest...ToVector() and use of ..Map,..Set,..List defines in tesselation.cpp.

  • Property mode set to 100644
File size: 7.3 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 "defs.hpp"
16#include "tesselation.hpp"
17#include "tesselationunittest.hpp"
18
19#define SPHERERADIUS 2.
20
21/********************************************** Test classes **************************************/
22
23// Registers the fixture into the 'registry'
24CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
25
26
27void TesselationTest::setUp()
28{
29 // create corners
30 class TesselPoint *Walker;
31 Walker = new TesselPoint;
32 Walker->node = new Vector(1., 0., -1.);
33 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
34 strcpy(Walker->Name, "1");
35 Walker->nr = 1;
36 Corners.push_back(Walker);
37 Walker = new TesselPoint;
38 Walker->node = new Vector(-1., 1., -1.);
39 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
40 strcpy(Walker->Name, "2");
41 Walker->nr = 2;
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, "3");
47 Walker->nr = 3;
48 Corners.push_back(Walker);
49 Walker = new TesselPoint;
50 Walker->node = new Vector(-1., 0., 1.);
51 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
52 strcpy(Walker->Name, "4");
53 Walker->nr = 4;
54 Corners.push_back(Walker);
55
56 // create linkedcell
57 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
58
59 // create tesselation
60 TesselStruct = new Tesselation;
61 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
62 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
63 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
64 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
65
66 CandidateForTesselation *baseline = NULL;
67 BoundaryTriangleSet *T = NULL;
68 bool OneLoopWithoutSuccessFlag = true;
69 bool TesselationFailFlag = false;
70 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
71 // 2a. fill all new OpenLines
72 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
73 baseline = Runner->second;
74 if (baseline->pointlist.empty()) {
75 T = (((baseline->BaseLine->triangles.begin()))->second);
76 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
77 }
78 }
79
80 // 2b. search for smallest ShortestAngle among all candidates
81 double ShortestAngle = 4.*M_PI;
82 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
83 if (Runner->second->ShortestAngle < ShortestAngle) {
84 baseline = Runner->second;
85 ShortestAngle = baseline->ShortestAngle;
86 }
87 }
88 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
89 OneLoopWithoutSuccessFlag = false;
90 else {
91 TesselStruct->AddCandidateTriangle(*baseline);
92 }
93 }
94};
95
96
97void TesselationTest::tearDown()
98{
99 delete(LinkedList);
100 delete(TesselStruct);
101 for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
102 delete((*Runner)->node);
103 delete(*Runner);
104 }
105 Corners.clear();
106 MemoryUsageObserver::purgeInstance();
107 logger::purgeInstance();
108 errorLogger::purgeInstance();
109};
110
111/** UnitTest for Contains...()
112 *
113 */
114void TesselationTest::ContainmentTest()
115{
116 class BoundaryPointSet *point = NULL;
117 class BoundaryLineSet *line = NULL;
118
119 // check ContainsBoundaryPoint
120 for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
121 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
122 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
123 }
124 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
125 for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
126 point = PointRunner->second;
127 for (int i=0;i<3;i++)
128 if (point == (Runner->second)->endpoints[i])
129 point = NULL;
130 if (point != NULL)
131 break;
132 }
133 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
134 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
135 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
136 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
137 }
138
139 // check ContainsBoundaryLine
140 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
141 for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
142 line = LineRunner->second;
143 for (int i=0;i<3;i++)
144 if (line == (Runner->second)->lines[i])
145 line = NULL;
146 if (line != NULL)
147 break;
148 }
149 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
150 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
151 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
152 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
153 }
154
155 // check IsPresentTupel
156 CPPUNIT_ASSERT_EQUAL( true, true );
157}
158
159/** UnitTest for Tesselation::GetAllTriangles()
160 *
161 */
162void TesselationTest::GetAllTrianglesTest()
163{
164 class BoundaryPointSet *Walker = NULL;
165
166 // check that there are three adjacent triangles for every boundary point
167 for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
168 Walker = Runner->second;
169 set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
170 CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
171 // check that the returned triangle all contain the Walker
172 for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
173 CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
174 delete(triangles);
175 }
176}
177
178/********************************************** Main routine **************************************/
179
180int main(int argc, char **argv)
181{
182 // Get the top level suite from the registry
183 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
184
185 // Adds the test to the list of test to run
186 CppUnit::TextUi::TestRunner runner;
187 runner.addTest( suite );
188
189 // Change the default outputter to a compiler error format outputter
190 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
191 std::cerr ) );
192 // Run the tests.
193 bool wasSucessful = runner.run();
194
195 // Return error code 1 if the one of test failed.
196 return wasSucessful ? 0 : 1;
197};
Note: See TracBrowser for help on using the repository browser.