##// END OF EJS Templates
Implements unit tests
Alexandre Leroux -
r678:0cb0a50bdd13
parent child
Show More
@@ -1,519 +1,638
1 1 #include "Data/DataSeries.h"
2 2 #include "Data/ScalarSeries.h"
3 3 #include "Data/VectorSeries.h"
4 4
5 5 #include <cmath>
6 6
7 7 #include <QObject>
8 8 #include <QtTest>
9 9
10 10 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
11 11 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
12 12
13 13 namespace {
14 14
15 15 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
16 16 const QVector<double> &valuesData)
17 17 {
18 18 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
19 19 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
20 20 QVERIFY(std::equal(
21 21 first, last, valuesData.cbegin(), valuesData.cend(),
22 22 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
23 23 }
24 24
25 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
26 const QVector<QVector<double> > &valuesData)
27 {
28 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
29 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
30 for (auto i = 0; i < valuesData.size(); ++i) {
31 auto componentData = valuesData.at(i);
32
33 QVERIFY(std::equal(
34 first, last, componentData.cbegin(), componentData.cend(),
35 [i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; }));
36 }
37 }
38
25 39 } // namespace
26 40
27 41 class TestDataSeries : public QObject {
28 42 Q_OBJECT
29 43 private:
30 44 template <typename T>
31 45 void testValuesBoundsStructure()
32 46 {
33 47 // ////////////// //
34 48 // Test structure //
35 49 // ////////////// //
36 50
37 51 // Data series to get values bounds
38 52 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
39 53
40 54 // x-axis range
41 55 QTest::addColumn<double>("minXAxis");
42 56 QTest::addColumn<double>("maxXAxis");
43 57
44 58 // Expected results
45 59 QTest::addColumn<bool>(
46 60 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
47 61 QTest::addColumn<double>("expectedMinValue");
48 62 QTest::addColumn<double>("expectedMaxValue");
49 63 }
50 64
51 65 template <typename T>
52 66 void testValuesBounds()
53 67 {
54 68 QFETCH(std::shared_ptr<T>, dataSeries);
55 69 QFETCH(double, minXAxis);
56 70 QFETCH(double, maxXAxis);
57 71
58 72 QFETCH(bool, expectedOK);
59 73 QFETCH(double, expectedMinValue);
60 74 QFETCH(double, expectedMaxValue);
61 75
62 76 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
63 77 auto end = dataSeries->cend();
64 78
65 79 // Checks iterators with expected result
66 80 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
67 81
68 82 if (expectedOK) {
69 83 auto compare = [](const auto &v1, const auto &v2) {
70 84 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
71 85 };
72 86
73 87 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
74 88 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
75 89 }
76 90 }
77 91
92 template <typename T>
93 void testPurgeStructure()
94 {
95 // ////////////// //
96 // Test structure //
97 // ////////////// //
98
99 // Data series to purge
100 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
101 QTest::addColumn<double>("min");
102 QTest::addColumn<double>("max");
103
104 // Expected values after purge
105 QTest::addColumn<QVector<double> >("expectedXAxisData");
106 QTest::addColumn<QVector<QVector<double> > >("expectedValuesData");
107 }
108
109 template <typename T>
110 void testPurge()
111 {
112 QFETCH(std::shared_ptr<T>, dataSeries);
113 QFETCH(double, min);
114 QFETCH(double, max);
115
116 dataSeries->purge(min, max);
117
118 // Validates results
119 QFETCH(QVector<double>, expectedXAxisData);
120 QFETCH(QVector<QVector<double> >, expectedValuesData);
121
122 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData,
123 expectedValuesData);
124 }
125
78 126 private slots:
127
79 128 /// Input test data
80 129 /// @sa testCtor()
81 130 void testCtor_data();
82 131
83 132 /// Tests construction of a data series
84 133 void testCtor();
85 134
86 135 /// Input test data
87 136 /// @sa testMerge()
88 137 void testMerge_data();
89 138
90 139 /// Tests merge of two data series
91 140 void testMerge();
92 141
93 142 /// Input test data
143 /// @sa testPurgeScalar()
144 void testPurgeScalar_data();
145
146 /// Tests purge of a scalar series
147 void testPurgeScalar();
148
149 /// Input test data
150 /// @sa testPurgeVector()
151 void testPurgeVector_data();
152
153 /// Tests purge of a vector series
154 void testPurgeVector();
155
156 /// Input test data
94 157 /// @sa testMinXAxisData()
95 158 void testMinXAxisData_data();
96 159
97 160 /// Tests get min x-axis data of a data series
98 161 void testMinXAxisData();
99 162
100 163 /// Input test data
101 164 /// @sa testMaxXAxisData()
102 165 void testMaxXAxisData_data();
103 166
104 167 /// Tests get max x-axis data of a data series
105 168 void testMaxXAxisData();
106 169
107 170 /// Input test data
108 171 /// @sa testXAxisRange()
109 172 void testXAxisRange_data();
110 173
111 174 /// Tests get x-axis range of a data series
112 175 void testXAxisRange();
113 176
114 177 /// Input test data
115 178 /// @sa testValuesBoundsScalar()
116 179 void testValuesBoundsScalar_data();
117 180
118 181 /// Tests get values bounds of a scalar series
119 182 void testValuesBoundsScalar();
120 183
121 184 /// Input test data
122 185 /// @sa testValuesBoundsVector()
123 186 void testValuesBoundsVector_data();
124 187
125 188 /// Tests get values bounds of a vector series
126 189 void testValuesBoundsVector();
127 190 };
128 191
129 192 void TestDataSeries::testCtor_data()
130 193 {
131 194 // ////////////// //
132 195 // Test structure //
133 196 // ////////////// //
134 197
135 198 // x-axis data
136 199 QTest::addColumn<QVector<double> >("xAxisData");
137 200 // values data
138 201 QTest::addColumn<QVector<double> >("valuesData");
139 202
140 203 // expected x-axis data
141 204 QTest::addColumn<QVector<double> >("expectedXAxisData");
142 205 // expected values data
143 206 QTest::addColumn<QVector<double> >("expectedValuesData");
144 207
145 208 // ////////// //
146 209 // Test cases //
147 210 // ////////// //
148 211
149 212 QTest::newRow("invalidData (different sizes of vectors)")
150 213 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.}
151 214 << QVector<double>{} << QVector<double>{};
152 215
153 216 QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.}
154 217 << QVector<double>{100., 200., 300., 400., 500.}
155 218 << QVector<double>{1., 2., 3., 4., 5.}
156 219 << QVector<double>{100., 200., 300., 400., 500.};
157 220
158 221 QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.}
159 222 << QVector<double>{100., 200., 300., 400., 500.}
160 223 << QVector<double>{1., 2., 3., 4., 5.}
161 224 << QVector<double>{500., 400., 300., 200., 100.};
162 225
163 226 QTest::newRow("unsortedData2")
164 227 << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.}
165 228 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.};
166 229 }
167 230
168 231 void TestDataSeries::testCtor()
169 232 {
170 233 // Creates series
171 234 QFETCH(QVector<double>, xAxisData);
172 235 QFETCH(QVector<double>, valuesData);
173 236
174 237 auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
175 238 Unit{}, Unit{});
176 239
177 240 // Validates results : we check that the data series is sorted on its x-axis data
178 241 QFETCH(QVector<double>, expectedXAxisData);
179 242 QFETCH(QVector<double>, expectedValuesData);
180 243
181 244 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData);
182 245 }
183 246
184 247 namespace {
185 248
186 249 std::shared_ptr<ScalarSeries> createScalarSeries(QVector<double> xAxisData,
187 250 QVector<double> valuesData)
188 251 {
189 252 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
190 253 Unit{});
191 254 }
192 255
193 256 std::shared_ptr<VectorSeries> createVectorSeries(QVector<double> xAxisData,
194 257 QVector<double> xValuesData,
195 258 QVector<double> yValuesData,
196 259 QVector<double> zValuesData)
197 260 {
198 261 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(xValuesData),
199 262 std::move(yValuesData), std::move(zValuesData), Unit{},
200 263 Unit{});
201 264 }
202 265
203 266 } // namespace
204 267
205 268 void TestDataSeries::testMerge_data()
206 269 {
207 270 // ////////////// //
208 271 // Test structure //
209 272 // ////////////// //
210 273
211 274 // Data series to merge
212 275 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
213 276 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2");
214 277
215 278 // Expected values in the first data series after merge
216 279 QTest::addColumn<QVector<double> >("expectedXAxisData");
217 280 QTest::addColumn<QVector<double> >("expectedValuesData");
218 281
219 282 // ////////// //
220 283 // Test cases //
221 284 // ////////// //
222 285
223 286 QTest::newRow("sortedMerge")
224 287 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
225 288 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
226 289 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
227 290 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
228 291
229 292 QTest::newRow("unsortedMerge")
230 293 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
231 294 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
232 295 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
233 296 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
234 297
235 298 QTest::newRow("unsortedMerge2")
236 299 << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.})
237 300 << createScalarSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.})
238 301 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
239 302 << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.};
240 303
241 304 QTest::newRow("unsortedMerge3")
242 305 << createScalarSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.})
243 306 << createScalarSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.})
244 307 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
245 308 << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.};
246 309 }
247 310
248 311 void TestDataSeries::testMerge()
249 312 {
250 313 // Merges series
251 314 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
252 315 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2);
253 316
254 317 dataSeries->merge(dataSeries2.get());
255 318
256 319 // Validates results : we check that the merge is valid and the data series is sorted on its
257 320 // x-axis data
258 321 QFETCH(QVector<double>, expectedXAxisData);
259 322 QFETCH(QVector<double>, expectedValuesData);
260 323
261 324 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
262 325 }
263 326
327 void TestDataSeries::testPurgeScalar_data()
328 {
329 testPurgeStructure<ScalarSeries>();
330
331 // ////////// //
332 // Test cases //
333 // ////////// //
334
335 QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.},
336 {100., 200., 300., 400., 500.})
337 << 2. << 4. << QVector<double>{2., 3., 4.}
338 << QVector<QVector<double> >{{200., 300., 400.}};
339 QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.},
340 {100., 200., 300., 400., 500.})
341 << 0. << 2.5 << QVector<double>{1., 2.}
342 << QVector<QVector<double> >{{100., 200.}};
343 QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.},
344 {100., 200., 300., 400., 500.})
345 << 3.5 << 7. << QVector<double>{4., 5.}
346 << QVector<QVector<double> >{{400., 500.}};
347 QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.},
348 {100., 200., 300., 400., 500.})
349 << 0. << 7. << QVector<double>{1., 2., 3., 4., 5.}
350 << QVector<QVector<double> >{{100., 200., 300., 400., 500.}};
351 QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.},
352 {100., 200., 300., 400., 500.})
353 << 5.5 << 7. << QVector<double>{}
354 << QVector<QVector<double> >{{}};
355 }
356
357 void TestDataSeries::testPurgeScalar()
358 {
359 testPurge<ScalarSeries>();
360 }
361
362 void TestDataSeries::testPurgeVector_data()
363 {
364 testPurgeStructure<VectorSeries>();
365
366 // ////////// //
367 // Test cases //
368 // ////////// //
369
370 QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.},
371 {11., 12., 13., 14., 15.},
372 {16., 17., 18., 19., 20.})
373 << 2. << 4. << QVector<double>{2., 3., 4.}
374 << QVector<QVector<double> >{
375 {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}};
376 }
377
378 void TestDataSeries::testPurgeVector()
379 {
380 testPurge<VectorSeries>();
381 }
382
264 383 void TestDataSeries::testMinXAxisData_data()
265 384 {
266 385 // ////////////// //
267 386 // Test structure //
268 387 // ////////////// //
269 388
270 389 // Data series to get min data
271 390 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
272 391
273 392 // Min data
274 393 QTest::addColumn<double>("min");
275 394
276 395 // Expected results
277 396 QTest::addColumn<bool>(
278 397 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
279 398 QTest::addColumn<double>(
280 399 "expectedMin"); // Expected value when method doesn't return end iterator
281 400
282 401 // ////////// //
283 402 // Test cases //
284 403 // ////////// //
285 404
286 405 QTest::newRow("minData1") << createScalarSeries({1., 2., 3., 4., 5.},
287 406 {100., 200., 300., 400., 500.})
288 407 << 0. << true << 1.;
289 408 QTest::newRow("minData2") << createScalarSeries({1., 2., 3., 4., 5.},
290 409 {100., 200., 300., 400., 500.})
291 410 << 1. << true << 1.;
292 411 QTest::newRow("minData3") << createScalarSeries({1., 2., 3., 4., 5.},
293 412 {100., 200., 300., 400., 500.})
294 413 << 1.1 << true << 2.;
295 414 QTest::newRow("minData4") << createScalarSeries({1., 2., 3., 4., 5.},
296 415 {100., 200., 300., 400., 500.})
297 416 << 5. << true << 5.;
298 417 QTest::newRow("minData5") << createScalarSeries({1., 2., 3., 4., 5.},
299 418 {100., 200., 300., 400., 500.})
300 419 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
301 420 QTest::newRow("minData6") << createScalarSeries({}, {}) << 1.1 << false
302 421 << std::numeric_limits<double>::quiet_NaN();
303 422 }
304 423
305 424 void TestDataSeries::testMinXAxisData()
306 425 {
307 426 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
308 427 QFETCH(double, min);
309 428
310 429 QFETCH(bool, expectedOK);
311 430 QFETCH(double, expectedMin);
312 431
313 432 auto it = dataSeries->minXAxisData(min);
314 433
315 434 QCOMPARE(expectedOK, it != dataSeries->cend());
316 435
317 436 // If the method doesn't return a end iterator, checks with expected value
318 437 if (expectedOK) {
319 438 QCOMPARE(expectedMin, it->x());
320 439 }
321 440 }
322 441
323 442 void TestDataSeries::testMaxXAxisData_data()
324 443 {
325 444 // ////////////// //
326 445 // Test structure //
327 446 // ////////////// //
328 447
329 448 // Data series to get max data
330 449 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
331 450
332 451 // Max data
333 452 QTest::addColumn<double>("max");
334 453
335 454 // Expected results
336 455 QTest::addColumn<bool>(
337 456 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
338 457 QTest::addColumn<double>(
339 458 "expectedMax"); // Expected value when method doesn't return end iterator
340 459
341 460 // ////////// //
342 461 // Test cases //
343 462 // ////////// //
344 463
345 464 QTest::newRow("maxData1") << createScalarSeries({1., 2., 3., 4., 5.},
346 465 {100., 200., 300., 400., 500.})
347 466 << 6. << true << 5.;
348 467 QTest::newRow("maxData2") << createScalarSeries({1., 2., 3., 4., 5.},
349 468 {100., 200., 300., 400., 500.})
350 469 << 5. << true << 5.;
351 470 QTest::newRow("maxData3") << createScalarSeries({1., 2., 3., 4., 5.},
352 471 {100., 200., 300., 400., 500.})
353 472 << 4.9 << true << 4.;
354 473 QTest::newRow("maxData4") << createScalarSeries({1., 2., 3., 4., 5.},
355 474 {100., 200., 300., 400., 500.})
356 475 << 1.1 << true << 1.;
357 476 QTest::newRow("maxData5") << createScalarSeries({1., 2., 3., 4., 5.},
358 477 {100., 200., 300., 400., 500.})
359 478 << 1. << true << 1.;
360 479 QTest::newRow("maxData6") << createScalarSeries({}, {}) << 1.1 << false
361 480 << std::numeric_limits<double>::quiet_NaN();
362 481 }
363 482
364 483 void TestDataSeries::testMaxXAxisData()
365 484 {
366 485 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
367 486 QFETCH(double, max);
368 487
369 488 QFETCH(bool, expectedOK);
370 489 QFETCH(double, expectedMax);
371 490
372 491 auto it = dataSeries->maxXAxisData(max);
373 492
374 493 QCOMPARE(expectedOK, it != dataSeries->cend());
375 494
376 495 // If the method doesn't return a end iterator, checks with expected value
377 496 if (expectedOK) {
378 497 QCOMPARE(expectedMax, it->x());
379 498 }
380 499 }
381 500
382 501 void TestDataSeries::testXAxisRange_data()
383 502 {
384 503 // ////////////// //
385 504 // Test structure //
386 505 // ////////////// //
387 506
388 507 // Data series to get x-axis range
389 508 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
390 509
391 510 // Min/max values
392 511 QTest::addColumn<double>("min");
393 512 QTest::addColumn<double>("max");
394 513
395 514 // Expected values
396 515 QTest::addColumn<QVector<double> >("expectedXAxisData");
397 516 QTest::addColumn<QVector<double> >("expectedValuesData");
398 517
399 518 // ////////// //
400 519 // Test cases //
401 520 // ////////// //
402 521
403 522 QTest::newRow("xAxisRange1") << createScalarSeries({1., 2., 3., 4., 5.},
404 523 {100., 200., 300., 400., 500.})
405 524 << -1. << 3.2 << QVector<double>{1., 2., 3.}
406 525 << QVector<double>{100., 200., 300.};
407 526 QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.},
408 527 {100., 200., 300., 400., 500.})
409 528 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
410 529 << QVector<double>{100., 200., 300., 400.};
411 530 QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.},
412 531 {100., 200., 300., 400., 500.})
413 532 << 1. << 3.9 << QVector<double>{1., 2., 3.}
414 533 << QVector<double>{100., 200., 300.};
415 534 QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.},
416 535 {100., 200., 300., 400., 500.})
417 536 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
418 537 QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.},
419 538 {100., 200., 300., 400., 500.})
420 539 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
421 540 QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.},
422 541 {100., 200., 300., 400., 500.})
423 542 << 2.1 << 6. << QVector<double>{3., 4., 5.}
424 543 << QVector<double>{300., 400., 500.};
425 544 QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.},
426 545 {100., 200., 300., 400., 500.})
427 546 << 6. << 9. << QVector<double>{} << QVector<double>{};
428 547 QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.},
429 548 {100., 200., 300., 400., 500.})
430 549 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
431 550 }
432 551
433 552 void TestDataSeries::testXAxisRange()
434 553 {
435 554 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
436 555 QFETCH(double, min);
437 556 QFETCH(double, max);
438 557
439 558 QFETCH(QVector<double>, expectedXAxisData);
440 559 QFETCH(QVector<double>, expectedValuesData);
441 560
442 561 auto bounds = dataSeries->xAxisRange(min, max);
443 562 validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData);
444 563 }
445 564
446 565 void TestDataSeries::testValuesBoundsScalar_data()
447 566 {
448 567 testValuesBoundsStructure<ScalarSeries>();
449 568
450 569 // ////////// //
451 570 // Test cases //
452 571 // ////////// //
453 572 auto nan = std::numeric_limits<double>::quiet_NaN();
454 573
455 574 QTest::newRow("scalarBounds1")
456 575 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6.
457 576 << true << 100. << 500.;
458 577 QTest::newRow("scalarBounds2")
459 578 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4.
460 579 << true << 200. << 400.;
461 580 QTest::newRow("scalarBounds3")
462 581 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5
463 582 << false << nan << nan;
464 583 QTest::newRow("scalarBounds4")
465 584 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6.
466 585 << false << nan << nan;
467 586 QTest::newRow("scalarBounds5") << createScalarSeries({1.}, {100.}) << 0. << 2. << true << 100.
468 587 << 100.;
469 588 QTest::newRow("scalarBounds6") << createScalarSeries({}, {}) << 0. << 2. << false << nan << nan;
470 589
471 590 // Tests with NaN values: NaN values are not included in min/max search
472 591 QTest::newRow("scalarBounds7")
473 592 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, 200., 300., 400., nan}) << 0. << 6.
474 593 << true << 200. << 400.;
475 594 QTest::newRow("scalarBounds8")
476 595 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, nan, nan, nan, nan}) << 0. << 6. << true
477 596 << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
478 597 }
479 598
480 599 void TestDataSeries::testValuesBoundsScalar()
481 600 {
482 601 testValuesBounds<ScalarSeries>();
483 602 }
484 603
485 604 void TestDataSeries::testValuesBoundsVector_data()
486 605 {
487 606 testValuesBoundsStructure<VectorSeries>();
488 607
489 608 // ////////// //
490 609 // Test cases //
491 610 // ////////// //
492 611 auto nan = std::numeric_limits<double>::quiet_NaN();
493 612
494 613 QTest::newRow("vectorBounds1")
495 614 << createVectorSeries({1., 2., 3., 4., 5.}, {10., 15., 20., 13., 12.},
496 615 {35., 24., 10., 9., 0.3}, {13., 14., 12., 9., 24.})
497 616 << 0. << 6. << true << 0.3 << 35.; // min/max in same component
498 617 QTest::newRow("vectorBounds2")
499 618 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
500 619 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
501 620 << 0. << 6. << true << 2.3 << 35.; // min/max in same entry
502 621 QTest::newRow("vectorBounds3")
503 622 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
504 623 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
505 624 << 2. << 3. << true << 10. << 24.;
506 625
507 626 // Tests with NaN values: NaN values are not included in min/max search
508 627 QTest::newRow("vectorBounds4")
509 628 << createVectorSeries({1., 2.}, {nan, nan}, {nan, nan}, {nan, nan}) << 0. << 6. << true
510 629 << nan << nan;
511 630 }
512 631
513 632 void TestDataSeries::testValuesBoundsVector()
514 633 {
515 634 testValuesBounds<VectorSeries>();
516 635 }
517 636
518 637 QTEST_MAIN(TestDataSeries)
519 638 #include "TestDataSeries.moc"
General Comments 0
You need to be logged in to leave comments. Login now