Mercurial Hosting > traffic-intelligence
comparison trajectorymanagement/test/PointOperationsTest.h @ 1159:e1e7acef8eab
moved trajectory management library into Traffic Intelligence
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 22 Feb 2021 22:09:35 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1158:7eb972942f22 | 1159:e1e7acef8eab |
---|---|
1 #ifndef POINTOPERATIONSTEST_H_ | |
2 #define POINTOPERATIONSTEST_H_ | |
3 | |
4 #include "../src/Trajectory.h" | |
5 | |
6 #include <cppunit/extensions/HelperMacros.h> | |
7 | |
8 using namespace std; | |
9 | |
10 class PointOperationsTest: public CPPUNIT_NS::TestCase | |
11 { | |
12 CPPUNIT_TEST_SUITE(PointOperationsTest); | |
13 CPPUNIT_TEST(testInitPoint); | |
14 CPPUNIT_TEST(testNorm); | |
15 CPPUNIT_TEST(testDim); | |
16 CPPUNIT_TEST(testMinMax); | |
17 CPPUNIT_TEST(testOperatorEqNotEq); | |
18 CPPUNIT_TEST(testOperatorMi1); | |
19 CPPUNIT_TEST(testOperatorPl); | |
20 CPPUNIT_TEST(testOperatorMi2); | |
21 //CPPUNIT_TEST(testOperatorInOut); | |
22 CPPUNIT_TEST_SUITE_END(); | |
23 | |
24 protected: | |
25 void testInitPoint(void); | |
26 void testNorm(void); | |
27 void testDim(void); | |
28 void testMinMax(void); | |
29 void testOperatorEqNotEq(void); | |
30 void testOperatorMi1(void); | |
31 void testOperatorPl(void); | |
32 void testOperatorMi2(void); | |
33 void testOperatorInOut(void); | |
34 | |
35 private: | |
36 template<typename Tclass, typename Tparam> | |
37 void testInitPoint2D(const Tclass &correctPoint, const Tparam x, const Tparam y, const Tparam z) | |
38 { | |
39 Tclass point; | |
40 initPoint(point, x, y); | |
41 CPPUNIT_ASSERT_EQUAL(point, correctPoint); | |
42 | |
43 testInitPoint3D(correctPoint, x, y, z); | |
44 } | |
45 | |
46 template<typename Tclass, typename Tparam> | |
47 void testInitPoint3D(const Tclass &correctPoint, const Tparam x, const Tparam y, const Tparam z) | |
48 { | |
49 Tclass point; | |
50 initPoint(point, x, y, z); | |
51 CPPUNIT_ASSERT_EQUAL(point, correctPoint); | |
52 } | |
53 | |
54 template<typename Tclass, typename Tparam> | |
55 void testMinMax(Tparam x1, Tparam y1, Tparam z1, Tparam x2, Tparam y2, Tparam z2) | |
56 { | |
57 Tclass point1, point2, pointMin, pointMax; | |
58 initPoint(point1, x1, y1, z1); | |
59 initPoint(point2, x2, y2, z2); | |
60 initPoint(pointMin, min(x1, x2), min(y1, y2), min(z1, z2)); | |
61 initPoint(pointMax, max(x1, x2), max(y1, y2), max(z1, z2)); | |
62 CPPUNIT_ASSERT_EQUAL(min(point1, point2), pointMin); | |
63 CPPUNIT_ASSERT_EQUAL(min(point2, point1), pointMin); | |
64 CPPUNIT_ASSERT_EQUAL(max(point1, point2), pointMax); | |
65 CPPUNIT_ASSERT_EQUAL(max(point2, point1), pointMax); | |
66 } | |
67 | |
68 template<typename Tclass, typename Tparam> | |
69 void testOperatorEqNotEq(const Tparam x1, const Tparam y1, const Tparam z1, const Tparam delta) | |
70 { | |
71 Tclass point1; | |
72 initPoint(point1, x1, y1, z1); | |
73 | |
74 const Tclass point2 = point1; | |
75 | |
76 initPoint(point1, x1, y1, z1); | |
77 CPPUNIT_ASSERT(point2 == point1); | |
78 CPPUNIT_ASSERT(!(point2 != point1)); | |
79 | |
80 initPoint(point1, (Tparam) (x1 + delta), y1, z1); | |
81 CPPUNIT_ASSERT(point2 != point1); | |
82 CPPUNIT_ASSERT(!(point2 == point1)); | |
83 | |
84 initPoint(point1, (Tparam) (x1 - delta), y1, z1); | |
85 CPPUNIT_ASSERT(point2 != point1); | |
86 CPPUNIT_ASSERT(!(point2 == point1)); | |
87 | |
88 initPoint(point1, x1, (Tparam) (y1 + delta), z1); | |
89 CPPUNIT_ASSERT(point2 != point1); | |
90 CPPUNIT_ASSERT(!(point2 == point1)); | |
91 | |
92 initPoint(point1, x1, (Tparam) (y1 - delta), z1); | |
93 CPPUNIT_ASSERT(point2 != point1); | |
94 CPPUNIT_ASSERT(!(point2 == point1)); | |
95 | |
96 initPoint(point1, x1, y1, (Tparam) (z1 + delta)); | |
97 if (dim(point1) == 2) | |
98 { | |
99 CPPUNIT_ASSERT(point2 == point1); | |
100 CPPUNIT_ASSERT(!(point2 != point1)); | |
101 } | |
102 else if (dim(point1) == 3) | |
103 { | |
104 CPPUNIT_ASSERT(point2 != point1); | |
105 CPPUNIT_ASSERT(!(point2 == point1)); | |
106 } | |
107 | |
108 initPoint(point1, x1, y1, (Tparam) (z1 - delta)); | |
109 if (dim(point1) == 2) | |
110 { | |
111 CPPUNIT_ASSERT(point2 == point1); | |
112 CPPUNIT_ASSERT(!(point2 != point1)); | |
113 } | |
114 else if (dim(point1) == 3) | |
115 { | |
116 CPPUNIT_ASSERT(point2 != point1); | |
117 CPPUNIT_ASSERT(!(point2 == point1)); | |
118 } | |
119 } | |
120 | |
121 template<typename T> | |
122 void testOperatorPl(const T point1, const T point2, const T point3) | |
123 { | |
124 const T point4 = point1 + point2; | |
125 CPPUNIT_ASSERT_EQUAL(point3, point4); | |
126 | |
127 T point5 = point1; | |
128 point5 += point2; | |
129 | |
130 CPPUNIT_ASSERT_EQUAL(point3, point5); | |
131 } | |
132 | |
133 template<typename T> | |
134 void testOperatorMi(const T point3, const T point2, const T point1) | |
135 { | |
136 const T point4 = point1 - point2; | |
137 CPPUNIT_ASSERT_EQUAL(point3, point4); | |
138 | |
139 T point5 = point1; | |
140 point5 -= point2; | |
141 | |
142 CPPUNIT_ASSERT_EQUAL(point3, point5); | |
143 } | |
144 | |
145 // problem: different format using the opencv Point to string with the proposed one for CvPoint | |
146 template<typename T> | |
147 void testOperatorInOut(const T point1, string s) | |
148 { | |
149 stringstream ss; | |
150 ss << point1; | |
151 CPPUNIT_ASSERT_EQUAL(ss.str(), s); | |
152 | |
153 T point2; | |
154 istringstream is(s); | |
155 is >> point2; | |
156 CPPUNIT_ASSERT_EQUAL(point1, point2); | |
157 } | |
158 }; | |
159 | |
160 #endif /* POINTOPERATIONSTEST_H_ */ |