source: src/unittests/tesselationunittest.cpp@ 63c1f6

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 63c1f6 was 49e1ae, checked in by Frederik Heber <heber@…>, 15 years ago

cstring header was missing in files, supplying definition of strlen, strcpy, and so on.

This was noted on laptop with gcc 4.1 (on workstation we have gcc 4.2)

  • 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 <cstring>
16
17#include "defs.hpp"
18#include "tesselation.hpp"
19#include "tesselationunittest.hpp"
20
21#define SPHERERADIUS 2.
22
23/********************************************** Test classes **************************************/
24
25// Registers the fixture into the 'registry'
26CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
27
28
29void TesselationTest::setUp()
30{
31 // create corners
32 class TesselPoint *Walker;
33 Walker = new TesselPoint;
34 Walker->node = new Vector(1., 0., -1.);
35 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
36 strcpy(Walker->Name, "1");
37 Walker->nr = 1;
38 Corners.push_back(Walker);
39 Walker = new TesselPoint;
40 Walker->node = new Vector(-1., 1., -1.);
41 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
42 strcpy(Walker->Name, "2");
43 Walker->nr = 2;
44 Corners.push_back(Walker);
45 Walker = new TesselPoint;
46 Walker->node = new Vector(-1., -1., -1.);
47 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
48 strcpy(Walker->Name, "3");
49 Walker->nr = 3;
50 Corners.push_back(Walker);
51 Walker = new TesselPoint;
52 Walker->node = new Vector(-1., 0., 1.);
53 Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
54 strcpy(Walker->Name, "4");
55 Walker->nr = 4;
56 Corners.push_back(Walker);
57
58 // create linkedcell
59 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
60
61 // create tesselation
62 TesselStruct = new Tesselation;
63 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
64 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
65 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
66 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
67
68 CandidateForTesselation *baseline = NULL;
69 BoundaryTriangleSet *T = NULL;
70 bool OneLoopWithoutSuccessFlag = true;
71 bool TesselationFailFlag = false;
72 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
73 // 2a. fill all new OpenLines
74 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
75 baseline = Runner->second;
76 if (baseline->pointlist.empty()) {
77 T = (((baseline->BaseLine->triangles.begin()))->second);
78 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
79 }
80 }
81
82 // 2b. search for smallest ShortestAngle among all candidates
83 double ShortestAngle = 4.*M_PI;
84 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
85 if (Runner->second->ShortestAngle < ShortestAngle) {
86 baseline = Runner->second;
87 ShortestAngle = baseline->ShortestAngle;
88 }
89 }
90 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
91 OneLoopWithoutSuccessFlag = false;
92 else {
93 TesselStruct->AddCandidateTriangle(*baseline);
94 }
95 }
96};
97
98
99void TesselationTest::tearDown()
100{
101 delete(LinkedList);
102 delete(TesselStruct);
103 for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
104 delete((*Runner)->node);
105 delete(*Runner);
106 }
107 Corners.clear();
108 MemoryUsageObserver::purgeInstance();
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}
179
180/********************************************** Main routine **************************************/
181
182int main(int argc, char **argv)
183{
184 // Get the top level suite from the registry
185 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
186
187 // Adds the test to the list of test to run
188 CppUnit::TextUi::TestRunner runner;
189 runner.addTest( suite );
190
191 // Change the default outputter to a compiler error format outputter
192 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
193 std::cerr ) );
194 // Run the tests.
195 bool wasSucessful = runner.run();
196
197 // Return error code 1 if the one of test failed.
198 return wasSucessful ? 0 : 1;
199};
Note: See TracBrowser for help on using the repository browser.