source: src/unittests/PlaneUnittest.cpp@ 673c7f

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 673c7f was fa5a6a, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added unittests for planes

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * PlaneUnittest.cpp
3 *
4 * Created on: Apr 30, 2010
5 * Author: crueger
6 */
7
8#include "PlaneUnittest.hpp"
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#ifdef HAVE_TESTRUNNER
15#include "UnitTestMain.hpp"
16#endif /*HAVE_TESTRUNNER*/
17
18#include "vector.hpp"
19
20CPPUNIT_TEST_SUITE_REGISTRATION( PlaneUnittest );
21
22void PlaneUnittest::setUp(){
23 p1 = new Plane(e1,e2,e3);
24 p2 = new Plane(e1,e2,zeroVec);
25 p3 = new Plane(e1,zeroVec,e3);
26 p4 = new Plane(zeroVec,e2,e3);
27}
28
29void PlaneUnittest::tearDown(){
30 delete p1;
31 delete p2;
32 delete p3;
33 delete p4;
34}
35
36void PlaneUnittest::constructionErrorTest(){
37 // try several method of construction..
38 // see if error checking works
39
40 // three points
41 CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,e3));
42 // when only two points are differnt this gives an error
43 CPPUNIT_ASSERT_THROW(Plane(e1,e2,e2),LinearDependenceException);
44 // same with only one point
45 CPPUNIT_ASSERT_THROW(Plane(e1,e1,e1),LinearDependenceException);
46
47 // use two vector giving two directions
48 CPPUNIT_ASSERT_NO_THROW(Plane(e1,e2,0));
49 // and again this is actually only one vector
50 CPPUNIT_ASSERT_THROW(Plane(e1,e1,0),LinearDependenceException);
51 // Zero vector does not give a good direction
52 CPPUNIT_ASSERT_THROW(Plane(e1,zeroVec,0),ZeroVectorException);
53
54 // use a normalvector and an scalar offset
55 CPPUNIT_ASSERT_NO_THROW(Plane(e1,0));
56 // The zero vector is no good as a normalvector
57 CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException);
58
59 // use a normalvector and an offset vector
60 CPPUNIT_ASSERT_NO_THROW(Plane(e1,zeroVec));
61 // and the bad zeroVector again
62 CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException);
63}
64
65
66// we need to test normals independent of the direction
67bool testNormal(const Vector &normal1, const Vector &normal2){
68 return (normal1==normal2) || (normal1==-1*normal2);
69}
70
71void PlaneUnittest::constructionResultTest(){
72 {
73 // construct with three points on plane
74 Plane p1(e1,e2,zeroVec);
75 CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
76 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
77
78 Plane p2(e1,e3,zeroVec);
79 CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
80 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
81
82 Plane p3(e2,e3,zeroVec);
83 CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
84 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
85 }
86 {
87 // construct with two directions + offset
88 Plane p1(e1,e2,0);
89 CPPUNIT_ASSERT(testNormal(e3,p1.getNormal()));
90 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
91
92 Plane p2(e1,e3,0);
93 CPPUNIT_ASSERT(testNormal(e2,p2.getNormal()));
94 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
95
96 Plane p3(e2,e3,0);
97 CPPUNIT_ASSERT(testNormal(e1,p3.getNormal()));
98 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
99 }
100}
101
102void PlaneUnittest::pointsTest(){
103 std::vector<Vector> points1 = p1->getPointsOnPlane();
104 CPPUNIT_ASSERT(p1->isContained(points1[0]));
105 CPPUNIT_ASSERT(p1->isContained(points1[1]));
106 CPPUNIT_ASSERT(p1->isContained(points1[2]));
107 // check that the three points differ
108 CPPUNIT_ASSERT(points1[0]!=points1[1]);
109 CPPUNIT_ASSERT(points1[0]!=points1[2]);
110 CPPUNIT_ASSERT(points1[1]!=points1[2]);
111
112
113 std::vector<Vector> points2 = p2->getPointsOnPlane();
114 CPPUNIT_ASSERT(p2->isContained(points2[0]));
115 CPPUNIT_ASSERT(p2->isContained(points2[1]));
116 CPPUNIT_ASSERT(p2->isContained(points2[2]));
117 // check that the three points differ
118 CPPUNIT_ASSERT(points2[0]!=points2[1]);
119 CPPUNIT_ASSERT(points2[0]!=points2[2]);
120 CPPUNIT_ASSERT(points2[1]!=points2[2]);
121
122 std::vector<Vector> points3 = p3->getPointsOnPlane();
123 CPPUNIT_ASSERT(p3->isContained(points3[0]));
124 CPPUNIT_ASSERT(p3->isContained(points3[1]));
125 CPPUNIT_ASSERT(p3->isContained(points3[2]));
126 // check that the three points differ
127 CPPUNIT_ASSERT(points3[0]!=points3[1]);
128 CPPUNIT_ASSERT(points3[0]!=points3[2]);
129 CPPUNIT_ASSERT(points3[1]!=points3[2]);
130
131 std::vector<Vector> points4 = p4->getPointsOnPlane();
132 CPPUNIT_ASSERT(p4->isContained(points4[0]));
133 CPPUNIT_ASSERT(p4->isContained(points4[1]));
134 CPPUNIT_ASSERT(p4->isContained(points4[2]));
135 // check that the three points differ
136 CPPUNIT_ASSERT(points4[0]!=points4[1]);
137 CPPUNIT_ASSERT(points4[0]!=points4[2]);
138 CPPUNIT_ASSERT(points4[1]!=points4[2]);
139}
140
141
142void PlaneUnittest::operationsTest(){
143 {
144 Vector t = (1./3.)*(e1+e2+e3);
145 CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) < MYEPSILON);
146 CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec));
147 }
148
149 CPPUNIT_ASSERT(fabs(p2->distance(e3)-1) < MYEPSILON);
150 CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(e3));
151 CPPUNIT_ASSERT(fabs(p3->distance(e2)-1) < MYEPSILON);
152 CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(e2));
153 CPPUNIT_ASSERT(fabs(p4->distance(e1)-1) < MYEPSILON);
154 CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(e1));
155
156
157}
Note: See TracBrowser for help on using the repository browser.