1 | /*
|
---|
2 | * BaseShapesUnittest.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jun 18, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "BaseShapesUnittest.hpp"
|
---|
9 |
|
---|
10 | #include <cppunit/CompilerOutputter.h>
|
---|
11 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
12 | #include <cppunit/ui/text/TestRunner.h>
|
---|
13 |
|
---|
14 | #include <cmath>
|
---|
15 |
|
---|
16 | #ifdef HAVE_TESTRUNNER
|
---|
17 | #include "UnitTestMain.hpp"
|
---|
18 | #endif /*HAVE_TESTRUNNER*/
|
---|
19 |
|
---|
20 | #include "LinearAlgebra/Vector.hpp"
|
---|
21 | #include "Shapes/Shape.hpp"
|
---|
22 |
|
---|
23 | #include "Shapes/BaseShapes.hpp"
|
---|
24 |
|
---|
25 | // Registers the fixture into the 'registry'
|
---|
26 | CPPUNIT_TEST_SUITE_REGISTRATION( BaseShapesUnittest );
|
---|
27 |
|
---|
28 | void BaseShapesUnittest::setUp()
|
---|
29 | {
|
---|
30 | v000 = 0*e1+0*e2+0*e3;
|
---|
31 | v100 = 1*e1+0*e2+0*e3;
|
---|
32 | v200 = -1*e1+0*e2+0*e3;
|
---|
33 | v010 = 0*e1+1*e2+0*e3;
|
---|
34 | v110 = 1*e1+1*e2+0*e3;
|
---|
35 | v210 = -1*e1+1*e2+0*e3;
|
---|
36 | v020 = 0*e1-1*e2+0*e3;
|
---|
37 | v120 = 1*e1-1*e2+0*e3;
|
---|
38 | v220 = -1*e1-1*e2+0*e3;
|
---|
39 | v001 = 0*e1+0*e2+1*e3;
|
---|
40 | v101 = 1*e1+0*e2+1*e3;
|
---|
41 | v201 = -1*e1+0*e2+1*e3;
|
---|
42 | v011 = 0*e1+1*e2+1*e3;
|
---|
43 | v111 = 1*e1+1*e2+1*e3;
|
---|
44 | v211 = -1*e1+1*e2+1*e3;
|
---|
45 | v021 = 0*e1-1*e2+1*e3;
|
---|
46 | v121 = 1*e1-1*e2+1*e3;
|
---|
47 | v221 = -1*e1-1*e2+1*e3;
|
---|
48 | v002 = 0*e1+0*e2-1*e3;
|
---|
49 | v102 = 1*e1+0*e2-1*e3;
|
---|
50 | v202 = -1*e1+0*e2-1*e3;
|
---|
51 | v012 = 0*e1+1*e2-1*e3;
|
---|
52 | v112 = 1*e1+1*e2-1*e3;
|
---|
53 | v212 = -1*e1+1*e2-1*e3;
|
---|
54 | v022 = 0*e1-1*e2-1*e3;
|
---|
55 | v122 = 1*e1-1*e2-1*e3;
|
---|
56 | v222 = -1*e1-1*e2-1*e3;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void BaseShapesUnittest::tearDown()
|
---|
60 | {}
|
---|
61 |
|
---|
62 |
|
---|
63 | void BaseShapesUnittest::isInsideTest(){
|
---|
64 | Shape s1 = Sphere();
|
---|
65 |
|
---|
66 | CPPUNIT_ASSERT(s1.isInside(v000));
|
---|
67 | CPPUNIT_ASSERT(s1.isInside(v100));
|
---|
68 | CPPUNIT_ASSERT(s1.isInside(v200));
|
---|
69 | CPPUNIT_ASSERT(s1.isInside(v010));
|
---|
70 | CPPUNIT_ASSERT(!s1.isInside(v110));
|
---|
71 | CPPUNIT_ASSERT(!s1.isInside(v210));
|
---|
72 | CPPUNIT_ASSERT(s1.isInside(v020));
|
---|
73 | CPPUNIT_ASSERT(!s1.isInside(v120));
|
---|
74 | CPPUNIT_ASSERT(!s1.isInside(v220));
|
---|
75 | CPPUNIT_ASSERT(s1.isInside(v001));
|
---|
76 | CPPUNIT_ASSERT(!s1.isInside(v101));
|
---|
77 | CPPUNIT_ASSERT(!s1.isInside(v201));
|
---|
78 | CPPUNIT_ASSERT(!s1.isInside(v011));
|
---|
79 | CPPUNIT_ASSERT(!s1.isInside(v111));
|
---|
80 | CPPUNIT_ASSERT(!s1.isInside(v211));
|
---|
81 | CPPUNIT_ASSERT(!s1.isInside(v021));
|
---|
82 | CPPUNIT_ASSERT(!s1.isInside(v121));
|
---|
83 | CPPUNIT_ASSERT(!s1.isInside(v221));
|
---|
84 | CPPUNIT_ASSERT(s1.isInside(v002));
|
---|
85 | CPPUNIT_ASSERT(!s1.isInside(v102));
|
---|
86 | CPPUNIT_ASSERT(!s1.isInside(v202));
|
---|
87 | CPPUNIT_ASSERT(!s1.isInside(v012));
|
---|
88 | CPPUNIT_ASSERT(!s1.isInside(v112));
|
---|
89 | CPPUNIT_ASSERT(!s1.isInside(v212));
|
---|
90 | CPPUNIT_ASSERT(!s1.isInside(v022));
|
---|
91 | CPPUNIT_ASSERT(!s1.isInside(v122));
|
---|
92 | CPPUNIT_ASSERT(!s1.isInside(v222));
|
---|
93 |
|
---|
94 | Shape s2 = Cuboid();
|
---|
95 |
|
---|
96 | CPPUNIT_ASSERT(s2.isInside(v000));
|
---|
97 | CPPUNIT_ASSERT(s2.isInside(v100));
|
---|
98 | CPPUNIT_ASSERT(!s2.isInside(v200));
|
---|
99 | CPPUNIT_ASSERT(s2.isInside(v010));
|
---|
100 | CPPUNIT_ASSERT(s2.isInside(v110));
|
---|
101 | CPPUNIT_ASSERT(!s2.isInside(v210));
|
---|
102 | CPPUNIT_ASSERT(!s2.isInside(v020));
|
---|
103 | CPPUNIT_ASSERT(!s2.isInside(v120));
|
---|
104 | CPPUNIT_ASSERT(!s2.isInside(v220));
|
---|
105 | CPPUNIT_ASSERT(s2.isInside(v001));
|
---|
106 | CPPUNIT_ASSERT(s2.isInside(v101));
|
---|
107 | CPPUNIT_ASSERT(!s2.isInside(v201));
|
---|
108 | CPPUNIT_ASSERT(s2.isInside(v011));
|
---|
109 | CPPUNIT_ASSERT(s2.isInside(v111));
|
---|
110 | CPPUNIT_ASSERT(!s2.isInside(v211));
|
---|
111 | CPPUNIT_ASSERT(!s2.isInside(v021));
|
---|
112 | CPPUNIT_ASSERT(!s2.isInside(v121));
|
---|
113 | CPPUNIT_ASSERT(!s2.isInside(v221));
|
---|
114 | CPPUNIT_ASSERT(!s2.isInside(v002));
|
---|
115 | CPPUNIT_ASSERT(!s2.isInside(v102));
|
---|
116 | CPPUNIT_ASSERT(!s2.isInside(v202));
|
---|
117 | CPPUNIT_ASSERT(!s2.isInside(v012));
|
---|
118 | CPPUNIT_ASSERT(!s2.isInside(v112));
|
---|
119 | CPPUNIT_ASSERT(!s2.isInside(v212));
|
---|
120 | CPPUNIT_ASSERT(!s2.isInside(v022));
|
---|
121 | CPPUNIT_ASSERT(!s2.isInside(v122));
|
---|
122 | CPPUNIT_ASSERT(!s2.isInside(v222));
|
---|
123 |
|
---|
124 | }
|
---|
125 |
|
---|
126 | void BaseShapesUnittest::PointsOnSurfaceTest(){
|
---|
127 | Shape s = Sphere();
|
---|
128 | const size_t N = 200;
|
---|
129 | std::vector<Vector> PointsOnSurface = s.getHomogeneousPointsOnSurface(N);
|
---|
130 | for (std::vector<Vector>::const_iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
|
---|
131 | CPPUNIT_ASSERT(fabs(1. - (*iter).NormSquared()) < MYEPSILON);
|
---|
132 | }
|
---|
133 | CPPUNIT_ASSERT_EQUAL(N, PointsOnSurface.size());
|
---|
134 | }
|
---|
135 |
|
---|