comparison trajectorymanagement/test/TrajectoryElementTest.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 TRAJECTORYELEMENTTEST_H_
2 #define TRAJECTORYELEMENTTEST_H_
3
4 #include "../src/TrajectoryElement.h"
5 #include "../src/PointOperations.h"
6
7 #include <cppunit/extensions/HelperMacros.h>
8
9 using namespace std;
10
11 template<typename T>
12 class TrajectoryElementTest: public CPPUNIT_NS::TestCase
13 {
14 CPPUNIT_TEST_SUITE(TrajectoryElementTest);
15 CPPUNIT_TEST(testTrajectoryElement1);
16 CPPUNIT_TEST(testTrajectoryElement2);
17 CPPUNIT_TEST(testSetFrameNumber);
18 CPPUNIT_TEST(testSetPoint);
19 CPPUNIT_TEST(testShift1);
20 CPPUNIT_TEST(testShift2);
21 CPPUNIT_TEST(testOperatorEq1);
22 CPPUNIT_TEST(testOperatorEq2);
23 CPPUNIT_TEST(testOperatorEq3);
24 CPPUNIT_TEST(testOperatorEq4);
25 CPPUNIT_TEST(testOperatorEq5);
26 // CPPUNIT_TEST(testOperatorIn1);
27 // CPPUNIT_TEST(testOperatorIn2);
28 // CPPUNIT_TEST(testOperatorOut1);
29 // CPPUNIT_TEST(testOperatorOut2);
30 CPPUNIT_TEST_SUITE_END();
31
32 public:
33 void setUp(void)
34 {
35 trajectoryElement.setFrameNumber(2);
36
37 T point;
38 initPoint(point, int(4), int(8), int(16));
39 trajectoryElement.setPoint(point);
40 }
41
42 void tearDown(void)
43 {
44 }
45
46 protected:
47 void testTrajectoryElement1(void)
48 {
49 T point;
50 initPoint(point, int(4), int(8), int(16));
51 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getFrameNumber(), (unsigned int) 2);
52 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getPoint(), point);
53 }
54
55 void testTrajectoryElement2(void)
56 {
57 TrajectoryElement<T> trajectoryElement2(trajectoryElement);
58 CPPUNIT_ASSERT_EQUAL(trajectoryElement, trajectoryElement2);
59 }
60
61 void testSetFrameNumber(void)
62 {
63 for (unsigned int i = 0; i < 20; ++i)
64 {
65 trajectoryElement.setFrameNumber(i);
66 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getFrameNumber(), i);
67 }
68 }
69
70 void testSetPoint(void)
71 {
72 T point1, point2;
73 for (unsigned int i = 0; i < 20; ++i)
74 {
75 initPoint(point1, int(4), int(8), int(16));
76 initPoint(point2, int(4), int(8), int(16));
77 trajectoryElement.setPoint(point1);
78 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getPoint(), point2);
79 }
80 }
81
82 void testShift1(void)
83 {
84 T shiftPoint, endPoint;
85 initPoint(shiftPoint, int(32), int(16), int(4));
86 initPoint(endPoint, int(36), int(24), int(20));
87 trajectoryElement.shift(shiftPoint);
88 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getPoint(), endPoint);
89 }
90
91 void testShift2(void)
92 {
93 T shiftPoint1, shiftPoint2, endPoint;
94 initPoint(shiftPoint1, int(32), int(16), int(4));
95 initPoint(shiftPoint2, int(2), int(4), int(28));
96 initPoint(endPoint, int(38), int(28), int(48));
97 trajectoryElement.shift(shiftPoint1);
98 trajectoryElement.shift(shiftPoint2);
99 CPPUNIT_ASSERT_EQUAL(trajectoryElement.getPoint(), endPoint);
100 }
101
102 void testOperatorEq1(void)
103 {
104 CPPUNIT_ASSERT(trajectoryElement == trajectoryElement);
105
106 trajectoryElement.setFrameNumber(2);
107 CPPUNIT_ASSERT(trajectoryElement == trajectoryElement);
108
109 T point;
110 initPoint(point, int(10), int(20), int(30));
111 trajectoryElement.setPoint(point);
112 CPPUNIT_ASSERT(trajectoryElement == trajectoryElement);
113 }
114
115 void testOperatorEq2(void)
116 {
117 TrajectoryElement<T> trajectoryElement2(trajectoryElement);
118 CPPUNIT_ASSERT(trajectoryElement2 == trajectoryElement);
119 }
120
121 void testOperatorEq3(void)
122 {
123 TrajectoryElement<T> trajectoryElement2;
124 trajectoryElement2 = trajectoryElement;
125 CPPUNIT_ASSERT(trajectoryElement2 == trajectoryElement);
126 }
127
128 void testOperatorEq4(void)
129 {
130 const TrajectoryElement<T> trajectoryElement2(trajectoryElement);
131 trajectoryElement.setFrameNumber(16);
132 CPPUNIT_ASSERT(trajectoryElement != trajectoryElement2);
133 }
134
135 void testOperatorEq5(void)
136 {
137 const TrajectoryElement<T> trajectoryElement2(trajectoryElement);
138
139 T point;
140
141 initPoint(point, int(4), int(8), int(16));
142 trajectoryElement.setPoint(point);
143 CPPUNIT_ASSERT(trajectoryElement == trajectoryElement2);
144
145 initPoint(point, int(4 + 10), int(8), int(16));
146 trajectoryElement.setPoint(point);
147 CPPUNIT_ASSERT(trajectoryElement != trajectoryElement2);
148
149 initPoint(point, int(4), int(8 + 10), int(16));
150 trajectoryElement.setPoint(point);
151 CPPUNIT_ASSERT(trajectoryElement != trajectoryElement2);
152
153 initPoint(point, int(4), int(8), int(16 + 10));
154 trajectoryElement.setPoint(point);
155 if (dim(point) == 2)
156 {
157 CPPUNIT_ASSERT(trajectoryElement == trajectoryElement2);
158 }
159 else if (dim(point) == 3)
160 {
161 CPPUNIT_ASSERT(trajectoryElement != trajectoryElement2);
162 }
163 }
164
165 void testOperatorIn1(void)
166 {
167 stringstream ss;
168 ss << trajectoryElement;
169
170 string s("2 4 8");
171 if (dim(trajectoryElement.getPoint()) == 3)
172 {
173 s += string(" 16");
174 }
175
176 CPPUNIT_ASSERT_EQUAL(ss.str(), s);
177 }
178
179 void testOperatorIn2(void)
180 {
181 trajectoryElement.setFrameNumber(4);
182
183 T point;
184 initPoint(point, int(10), int(20), int(30));
185 trajectoryElement.setPoint(point);
186
187 stringstream ss;
188 ss << trajectoryElement;
189
190 string s("4 10 20");
191 if (dim(trajectoryElement.getPoint()) == 3)
192 {
193 s += string(" 30");
194 }
195
196 CPPUNIT_ASSERT_EQUAL(ss.str(), s);
197 }
198
199 void testOperatorOut1(void)
200 {
201 stringstream ss;
202 ss << trajectoryElement;
203
204 TrajectoryElement<T> trajectoryElement2;
205 istringstream is(ss.str());
206 is >> trajectoryElement2;
207
208 CPPUNIT_ASSERT_EQUAL(trajectoryElement, trajectoryElement2);
209 }
210
211 void testOperatorOut2(void)
212 {
213 trajectoryElement.setFrameNumber(4);
214
215 T point;
216 initPoint(point, int(10), int(20), int(30));
217 trajectoryElement.setPoint(point);
218
219 stringstream ss;
220 ss << trajectoryElement;
221
222 TrajectoryElement<T> trajectoryElement2;
223 istringstream is(ss.str());
224 is >> trajectoryElement2;
225
226 CPPUNIT_ASSERT_EQUAL(trajectoryElement, trajectoryElement2);
227 }
228
229 private:
230 TrajectoryElement<T> trajectoryElement;
231 };
232
233 #endif /* TRAJECTORYELEMENTTEST_H_ */