##// END OF EJS Templates
Update the test to include the fixed bug test
perrinel -
r297:c2fea8ceaaad
parent child
Show More
@@ -1,343 +1,353
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableCacheController.h>
3 3
4 4 #include <QObject>
5 5 #include <QtTest>
6 6
7 7 #include <memory>
8 8
9 9 class TestVariableCacheController : public QObject {
10 10 Q_OBJECT
11 11
12 12 private slots:
13 13 void testProvideNotInCacheDateTimeList();
14 14
15 15 void testAddDateTime();
16 16 };
17 17
18 18
19 19 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
20 20 {
21 21 VariableCacheController variableCacheController{};
22 22
23 23 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
24 24 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
25 25 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
26 26 static_cast<double>(te0.toMSecsSinceEpoch())};
27 27
28 28 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
29 29 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
30 30 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
31 31 static_cast<double>(te1.toMSecsSinceEpoch())};
32 32
33 33 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
34 34 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
35 35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
36 36 static_cast<double>(te2.toMSecsSinceEpoch())};
37 37
38 38 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
39 39
40 40 variableCacheController.addDateTime(var0, sqp0);
41 41 variableCacheController.addDateTime(var0, sqp1);
42 42 variableCacheController.addDateTime(var0, sqp2);
43 43
44 44 // first case [ts,te] < ts0
45 45 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
46 46 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
47 47 auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
48 48 static_cast<double>(te.toMSecsSinceEpoch())};
49 49
50 50
51 51 auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
52 52
53 53 QCOMPARE(notInCach.size(), 1);
54 54 auto notInCacheSqp = notInCach.first();
55 55 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
56 56 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
57 57
58 58
59 59 // second case ts < ts0 && ts0 < te <= te0
60 60 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
61 61 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
62 62 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
63 63 static_cast<double>(te.toMSecsSinceEpoch())};
64 64
65 65
66 66 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
67 67
68 68 QCOMPARE(notInCach.size(), 1);
69 69 notInCacheSqp = notInCach.first();
70 70 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
71 71 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
72 72
73 73 // 3th case ts < ts0 && te0 < te <= ts1
74 74 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
75 75 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
76 76 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
77 77 static_cast<double>(te.toMSecsSinceEpoch())};
78 78
79 79
80 80 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
81 81
82 82 QCOMPARE(notInCach.size(), 2);
83 83 notInCacheSqp = notInCach.first();
84 84 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
85 85 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
86 86
87 87 notInCacheSqp = notInCach.at(1);
88 88 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
89 89 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
90 90
91 91 // 4th case ts < ts0 && ts1 < te <= te1
92 92 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
93 93 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
94 94 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
95 95 static_cast<double>(te.toMSecsSinceEpoch())};
96 96
97 97
98 98 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
99 99
100 100 QCOMPARE(notInCach.size(), 2);
101 101 notInCacheSqp = notInCach.first();
102 102 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
103 103 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
104 104
105 105 notInCacheSqp = notInCach.at(1);
106 106 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
107 107 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
108 108
109 109 // 5th case ts < ts0 && te3 < te
110 110 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
111 111 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
112 112 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
113 113 static_cast<double>(te.toMSecsSinceEpoch())};
114 114
115 115
116 116 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
117 117
118 118 QCOMPARE(notInCach.size(), 4);
119 119 notInCacheSqp = notInCach.first();
120 120 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
121 121 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
122 122
123 123 notInCacheSqp = notInCach.at(1);
124 124 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
125 125 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
126 126
127 127 notInCacheSqp = notInCach.at(2);
128 128 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
129 129 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
130 130
131 131 notInCacheSqp = notInCach.at(3);
132 132 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
133 133 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
134 134
135 135
136 136 // 6th case ts2 < ts
137 137 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}};
138 138 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
139 139 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
140 140 static_cast<double>(te.toMSecsSinceEpoch())};
141 141
142 142
143 143 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
144 144
145 145 QCOMPARE(notInCach.size(), 1);
146 146 notInCacheSqp = notInCach.first();
147 147 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
148 148 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
149 149
150 150 // 7th case ts = te0 && te < ts1
151 151 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
152 152 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
153 153 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
154 154 static_cast<double>(te.toMSecsSinceEpoch())};
155 155
156 156
157 157 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
158 158
159 159 QCOMPARE(notInCach.size(), 1);
160 160 notInCacheSqp = notInCach.first();
161 161 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
162 162 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
163 163
164 164 // 8th case ts0 < ts < te0 && te < ts1
165 165 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
166 166 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
167 167 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
168 168 static_cast<double>(te.toMSecsSinceEpoch())};
169 169
170 170
171 171 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
172 172
173 173 QCOMPARE(notInCach.size(), 1);
174 174 notInCacheSqp = notInCach.first();
175 175 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
176 176 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
177 177
178 178 // 9th case ts0 < ts < te0 && ts1 < te < te1
179 179 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
180 180 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
181 181 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
182 182 static_cast<double>(te.toMSecsSinceEpoch())};
183 183
184 184
185 185 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
186 186
187 187 QCOMPARE(notInCach.size(), 1);
188 188 notInCacheSqp = notInCach.first();
189 189 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
190 190 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
191 191
192 192 // 10th case te1 < ts < te < ts2
193 193 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}};
194 194 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
195 195 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
196 196 static_cast<double>(te.toMSecsSinceEpoch())};
197 197
198 198
199 199 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
200 200
201 201 QCOMPARE(notInCach.size(), 1);
202 202 notInCacheSqp = notInCach.first();
203 203 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
204 204 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
205 205
206 206 // 11th case te0 < ts < ts1 && te3 < te
207 207 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
208 208 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
209 209 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
210 210 static_cast<double>(te.toMSecsSinceEpoch())};
211 211
212 212
213 213 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
214 214
215 215 QCOMPARE(notInCach.size(), 3);
216 216 notInCacheSqp = notInCach.first();
217 217 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
218 218 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
219 219
220 220 notInCacheSqp = notInCach.at(1);
221 221 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
222 222 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
223 223
224 224 notInCacheSqp = notInCach.at(2);
225 225 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
226 226 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
227 227
228 228 // 12th case te0 < ts < ts1 && te3 < te
229 229 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
230 230 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
231 231 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
232 232 static_cast<double>(te.toMSecsSinceEpoch())};
233 233
234 234 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
235 235
236 236 QCOMPARE(notInCach.size(), 2);
237 237 notInCacheSqp = notInCach.first();
238 238 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
239 239 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
240 240
241 241 notInCacheSqp = notInCach.at(1);
242 242 QCOMPARE(notInCacheSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
243 243 QCOMPARE(notInCacheSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
244
245
246 // 12th case ts0 < ts < te0
247 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 10, 0}};
248 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 50, 0}};
249 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
250 static_cast<double>(te.toMSecsSinceEpoch())};
251
252 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
253 QCOMPARE(notInCach.size(), 0);
244 254 }
245 255
246 256
247 257 void TestVariableCacheController::testAddDateTime()
248 258 {
249 259 VariableCacheController variableCacheController{};
250 260
251 261 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
252 262 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
253 263 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
254 264 static_cast<double>(te0.toMSecsSinceEpoch())};
255 265
256 266 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
257 267 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
258 268 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
259 269 static_cast<double>(te1.toMSecsSinceEpoch())};
260 270
261 271 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
262 272 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
263 273 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
264 274 static_cast<double>(te2.toMSecsSinceEpoch())};
265 275
266 276 auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
267 277 auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
268 278 auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()),
269 279 static_cast<double>(te01.toMSecsSinceEpoch())};
270 280
271 281 auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}};
272 282 auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}};
273 283 auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()),
274 284 static_cast<double>(te3.toMSecsSinceEpoch())};
275 285
276 286 auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
277 287 auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
278 288 auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()),
279 289 static_cast<double>(te03.toMSecsSinceEpoch())};
280 290
281 291
282 292 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
283 293
284 294
285 295 // First case: add the first interval to the variable :sqp0
286 296 variableCacheController.addDateTime(var0, sqp0);
287 297 auto dateCacheList = variableCacheController.dateCacheList(var0);
288 298 QCOMPARE(dateCacheList.count(), 1);
289 299 auto dateCache = dateCacheList.at(0);
290 300 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
291 301 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
292 302
293 303 // 2nd case: add a second interval : sqp1 > sqp0
294 304 variableCacheController.addDateTime(var0, sqp1);
295 305 dateCacheList = variableCacheController.dateCacheList(var0);
296 306 QCOMPARE(dateCacheList.count(), 2);
297 307 dateCache = dateCacheList.at(0);
298 308 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
299 309 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
300 310
301 311 dateCache = dateCacheList.at(1);
302 312 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch()));
303 313 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
304 314
305 315 // 3th case: merge sqp0 & sqp1 with sqp01
306 316 variableCacheController.addDateTime(var0, sqp01);
307 317 dateCacheList = variableCacheController.dateCacheList(var0);
308 318 QCOMPARE(dateCacheList.count(), 1);
309 319 dateCache = dateCacheList.at(0);
310 320 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
311 321 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
312 322
313 323
314 324 // 4th case: add a second interval : sqp1 > sqp0
315 325 variableCacheController.addDateTime(var0, sqp2);
316 326 variableCacheController.addDateTime(var0, sqp3);
317 327 dateCacheList = variableCacheController.dateCacheList(var0);
318 328 QCOMPARE(dateCacheList.count(), 3);
319 329 dateCache = dateCacheList.at(0);
320 330 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
321 331 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
322 332
323 333 dateCache = dateCacheList.at(1);
324 334 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch()));
325 335 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch()));
326 336
327 337 dateCache = dateCacheList.at(2);
328 338 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch()));
329 339 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch()));
330 340
331 341
332 342 // 5th case: merge all interval
333 343 variableCacheController.addDateTime(var0, sqp03);
334 344 dateCacheList = variableCacheController.dateCacheList(var0);
335 345 QCOMPARE(dateCacheList.count(), 1);
336 346 dateCache = dateCacheList.at(0);
337 347 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
338 348 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch()));
339 349 }
340 350
341 351
342 352 QTEST_MAIN(TestVariableCacheController)
343 353 #include "TestVariableCacheController.moc"
General Comments 0
You need to be logged in to leave comments. Login now