##// END OF EJS Templates
Makes unit test templated to use it for vectors too
Alexandre Leroux -
r611:ca3efd807a86
parent child
Show More
@@ -1,13 +1,64
1 1 #include "Data/DataSeries.h"
2 2 #include "Data/ScalarSeries.h"
3 #include "Data/VectorSeries.h"
3 4
4 5 #include <QObject>
5 6 #include <QtTest>
6 7
7 8 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
9 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
8 10
9 11 class TestDataSeries : public QObject {
10 12 Q_OBJECT
13 private:
14 template <typename T>
15 void testValuesBoundsStructure()
16 {
17 // ////////////// //
18 // Test structure //
19 // ////////////// //
20
21 // Data series to get values bounds
22 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
23
24 // x-axis range
25 QTest::addColumn<double>("minXAxis");
26 QTest::addColumn<double>("maxXAxis");
27
28 // Expected results
29 QTest::addColumn<bool>(
30 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
31 QTest::addColumn<double>("expectedMinValue");
32 QTest::addColumn<double>("expectedMaxValue");
33 }
34
35 template <typename T>
36 void testValuesBounds()
37 {
38 QFETCH(std::shared_ptr<T>, dataSeries);
39 QFETCH(double, minXAxis);
40 QFETCH(double, maxXAxis);
41
42 QFETCH(bool, expectedOK);
43 QFETCH(double, expectedMinValue);
44 QFETCH(double, expectedMaxValue);
45
46 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
47 auto end = dataSeries->cend();
48
49 // Checks iterators with expected result
50 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
51
52 if (expectedOK) {
53 auto compare = [](const auto &v1, const auto &v2) {
54 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
55 };
56
57 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
58 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
59 }
60 }
61
11 62 private slots:
12 63 /// Input test data
13 64 /// @sa testCtor()
@@ -45,11 +96,11 private slots:
45 96 void testXAxisRange();
46 97
47 98 /// Input test data
48 /// @sa testValuesBounds()
49 void testValuesBounds_data();
99 /// @sa testValuesBoundsScalar()
100 void testValuesBoundsScalar_data();
50 101
51 /// Tests get values bounds of a data series
52 void testValuesBounds();
102 /// Tests get values bounds of a scalar series
103 void testValuesBoundsScalar();
53 104 };
54 105
55 106 void TestDataSeries::testCtor_data()
@@ -365,24 +416,9 void TestDataSeries::testXAxisRange()
365 416 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
366 417 }
367 418
368 void TestDataSeries::testValuesBounds_data()
419 void TestDataSeries::testValuesBoundsScalar_data()
369 420 {
370 // ////////////// //
371 // Test structure //
372 // ////////////// //
373
374 // Data series to get values bounds
375 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
376
377 // x-axis range
378 QTest::addColumn<double>("minXAxis");
379 QTest::addColumn<double>("maxXAxis");
380
381 // Expected results
382 QTest::addColumn<bool>(
383 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
384 QTest::addColumn<double>("expectedMinValue");
385 QTest::addColumn<double>("expectedMaxValue");
421 testValuesBoundsStructure<ScalarSeries>();
386 422
387 423 // ////////// //
388 424 // Test cases //
@@ -422,30 +458,9 void TestDataSeries::testValuesBounds_data()
422 458 << std::numeric_limits<double>::quiet_NaN();
423 459 }
424 460
425 void TestDataSeries::testValuesBounds()
461 void TestDataSeries::testValuesBoundsScalar()
426 462 {
427 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
428 QFETCH(double, minXAxis);
429 QFETCH(double, maxXAxis);
430
431 QFETCH(bool, expectedOK);
432 QFETCH(double, expectedMinValue);
433 QFETCH(double, expectedMaxValue);
434
435 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
436 auto end = dataSeries->cend();
437
438 // Checks iterators with expected result
439 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
440
441 if (expectedOK) {
442 auto compare = [](const auto &v1, const auto &v2) {
443 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
444 };
445
446 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
447 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
448 }
463 testValuesBounds<ScalarSeries>();
449 464 }
450 465
451 466 QTEST_MAIN(TestDataSeries)
General Comments 0
You need to be logged in to leave comments. Login now