@@ -1,13 +1,64 | |||||
1 | #include "Data/DataSeries.h" |
|
1 | #include "Data/DataSeries.h" | |
2 | #include "Data/ScalarSeries.h" |
|
2 | #include "Data/ScalarSeries.h" | |
|
3 | #include "Data/VectorSeries.h" | |||
3 |
|
4 | |||
4 | #include <QObject> |
|
5 | #include <QObject> | |
5 | #include <QtTest> |
|
6 | #include <QtTest> | |
6 |
|
7 | |||
7 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) |
|
8 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) | |
|
9 | Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>) | |||
8 |
|
10 | |||
9 | class TestDataSeries : public QObject { |
|
11 | class TestDataSeries : public QObject { | |
10 | Q_OBJECT |
|
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 | private slots: |
|
62 | private slots: | |
12 | /// Input test data |
|
63 | /// Input test data | |
13 | /// @sa testCtor() |
|
64 | /// @sa testCtor() | |
@@ -45,11 +96,11 private slots: | |||||
45 | void testXAxisRange(); |
|
96 | void testXAxisRange(); | |
46 |
|
97 | |||
47 | /// Input test data |
|
98 | /// Input test data | |
48 | /// @sa testValuesBounds() |
|
99 | /// @sa testValuesBoundsScalar() | |
49 | void testValuesBounds_data(); |
|
100 | void testValuesBoundsScalar_data(); | |
50 |
|
101 | |||
51 |
/// Tests get values bounds of a |
|
102 | /// Tests get values bounds of a scalar series | |
52 | void testValuesBounds(); |
|
103 | void testValuesBoundsScalar(); | |
53 | }; |
|
104 | }; | |
54 |
|
105 | |||
55 | void TestDataSeries::testCtor_data() |
|
106 | void TestDataSeries::testCtor_data() | |
@@ -365,24 +416,9 void TestDataSeries::testXAxisRange() | |||||
365 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); |
|
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 | // ////////////// // |
|
421 | testValuesBoundsStructure<ScalarSeries>(); | |
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"); |
|
|||
386 |
|
422 | |||
387 | // ////////// // |
|
423 | // ////////// // | |
388 | // Test cases // |
|
424 | // Test cases // | |
@@ -422,30 +458,9 void TestDataSeries::testValuesBounds_data() | |||||
422 | << std::numeric_limits<double>::quiet_NaN(); |
|
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); |
|
463 | testValuesBounds<ScalarSeries>(); | |
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 | } |
|
|||
449 | } |
|
464 | } | |
450 |
|
465 | |||
451 | QTEST_MAIN(TestDataSeries) |
|
466 | QTEST_MAIN(TestDataSeries) |
General Comments 0
You need to be logged in to leave comments.
Login now