source: src/unittests/tesselation_boundarytriangleunittest.cpp@ d5f216

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

Unit test for BoundaryTriangleSet member functions added.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * tesselation_boundarytriangleunittest.cpp
3 *
4 * Created on: Jan 13, 2010
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <cstring>
15
16#include "defs.hpp"
17#include "tesselation.hpp"
18#include "tesselation_boundarytriangleunittest.hpp"
19
20#define SPHERERADIUS 2.
21
22/********************************************** Test classes **************************************/
23
24// Registers the fixture into the 'registry'
25CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
26
27
28void TesselationBoundaryTriangleTest::setUp()
29{
30 setVerbosity(5);
31
32 // create nodes
33 TesselPoint *Walker = NULL;
34 Walker = new TesselPoint;
35 Walker->node = new Vector(0., 0., 0.);
36 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
37 strcpy(Walker->Name, "1");
38 Walker->nr = 1;
39 points[0] = new BoundaryPointSet(Walker);
40 Walker = new TesselPoint;
41 Walker->node = new Vector(0., 1., 0.);
42 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
43 strcpy(Walker->Name, "2");
44 Walker->nr = 2;
45 points[1] = new BoundaryPointSet(Walker);
46 Walker = new TesselPoint;
47 Walker->node = new Vector(1., 0., 0.);
48 Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
49 strcpy(Walker->Name, "3");
50 Walker->nr = 3;
51 points[2] = new BoundaryPointSet(Walker);
52
53 // create line
54 lines[0] = new BoundaryLineSet(points[0], points[1], 0);
55 lines[1] = new BoundaryLineSet(points[1], points[2], 1);
56 lines[2] = new BoundaryLineSet(points[0], points[2], 2);
57
58 // create triangle
59 triangle = new BoundaryTriangleSet(lines, 0);
60 triangle->GetNormalVector(Vector(0.,0.,1.));
61};
62
63
64void TesselationBoundaryTriangleTest::tearDown()
65{
66 delete(triangle);
67 MemoryUsageObserver::purgeInstance();
68 logger::purgeInstance();
69 errorLogger::purgeInstance();
70};
71
72/** UnitTest for Tesselation::IsInnerPoint()
73 */
74void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
75{
76 Vector TestIntersection;
77 Vector Point;
78
79 // simple test on y line
80 Point.Init(-1.,0.5,0.);
81 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
82 Point.Init(0.,0.5,0.);
83 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
84 Point.Init(-4.,0.5,0.);
85 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
86 Point.Init(0.,0.5,0.);
87 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
88
89 // simple test on x line
90 Point.Init(0.5,-1.,0.);
91 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
92 Point.Init(0.5,0.,0.);
93 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
94 Point.Init(0.5,-6.,0.);
95 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
96 Point.Init(0.5,0.,0.);
97 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
98
99 // simple test on slanted line
100 Point.Init(1.,1.,0.);
101 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
102 Point.Init(0.5,0.5,0.);
103 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
104 Point.Init(5.,5.,0.);
105 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
106 Point.Init(0.5,0.5,0.);
107 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
108
109 // simple test on first node
110 Point.Init(-1.,-1.,0.);
111 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
112 Point.Init(0.,0.,0.);
113 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
114
115 // simple test on second node
116 Point.Init(0.,2.,0.);
117 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
118 Point.Init(0.,1.,0.);
119 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
120
121 // simple test on third node
122 Point.Init(2.,0.,0.);
123 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
124 Point.Init(1.,0.,0.);
125 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
126};
127
128/** UnitTest for Tesselation::IsInnerPoint()
129 */
130void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
131{
132 Vector TestIntersection;
133 Vector Point;
134
135 // straight down/up
136 Point.Init(1./3.,1./3.,+5.);
137 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
138 Point.Init(1./3.,1./3.,0.);
139 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
140 Point.Init(1./3.,1./3.,-5.);
141 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
142 Point.Init(1./3.,1./3.,0.);
143 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
144
145 // simple test on y line
146 Point.Init(-1.,0.5,+2.);
147 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
148 Point.Init(0.,0.5,0.);
149 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
150 Point.Init(-1.,0.5,-3.);
151 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
152 Point.Init(0.,0.5,0.);
153 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
154
155 // simple test on x line
156 Point.Init(0.5,-1.,+1.);
157 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
158 Point.Init(0.5,0.,0.);
159 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
160 Point.Init(0.5,-1.,-2.);
161 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
162 Point.Init(0.5,0.,0.);
163 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
164
165 // simple test on slanted line
166 Point.Init(1.,1.,+3.);
167 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
168 Point.Init(0.5,0.5,0.);
169 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
170 Point.Init(1.,1.,-4.);
171 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
172 Point.Init(0.5,0.5,0.);
173 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
174
175 // simple test on first node
176 Point.Init(-1.,-1.,5.);
177 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
178 Point.Init(0.,0.,0.);
179 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
180
181 // simple test on second node
182 Point.Init(0.,2.,5.);
183 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
184 Point.Init(0.,1.,0.);
185 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
186
187 // simple test on third node
188 Point.Init(2.,0.,5.);
189 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
190 Point.Init(1.,0.,0.);
191 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
192};
193
194
195/********************************************** Main routine **************************************/
196
197int main(int argc, char **argv)
198{
199 // Get the top level suite from the registry
200 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
201
202 // Adds the test to the list of test to run
203 CppUnit::TextUi::TestRunner runner;
204 runner.addTest( suite );
205
206 // Change the default outputter to a compiler error format outputter
207 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
208 std::cerr ) );
209 // Run the tests.
210 bool wasSucessful = runner.run();
211
212 // Return error code 1 if the one of test failed.
213 return wasSucessful ? 0 : 1;
214};
Note: See TracBrowser for help on using the repository browser.