From 0cb0a50bdd1318f529783e39904ac8427962ec71 2017-08-31 10:28:47 From: Alexandre Leroux Date: 2017-08-31 10:28:47 Subject: [PATCH] Implements unit tests --- diff --git a/core/tests/Data/TestDataSeries.cpp b/core/tests/Data/TestDataSeries.cpp index adb30f6..0a9fa4c 100644 --- a/core/tests/Data/TestDataSeries.cpp +++ b/core/tests/Data/TestDataSeries.cpp @@ -22,6 +22,20 @@ void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVec [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); } +void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector &xData, + const QVector > &valuesData) +{ + QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), + [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); + for (auto i = 0; i < valuesData.size(); ++i) { + auto componentData = valuesData.at(i); + + QVERIFY(std::equal( + first, last, componentData.cbegin(), componentData.cend(), + [i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; })); + } +} + } // namespace class TestDataSeries : public QObject { @@ -75,7 +89,42 @@ private: } } + template + void testPurgeStructure() + { + // ////////////// // + // Test structure // + // ////////////// // + + // Data series to purge + QTest::addColumn >("dataSeries"); + QTest::addColumn("min"); + QTest::addColumn("max"); + + // Expected values after purge + QTest::addColumn >("expectedXAxisData"); + QTest::addColumn > >("expectedValuesData"); + } + + template + void testPurge() + { + QFETCH(std::shared_ptr, dataSeries); + QFETCH(double, min); + QFETCH(double, max); + + dataSeries->purge(min, max); + + // Validates results + QFETCH(QVector, expectedXAxisData); + QFETCH(QVector >, expectedValuesData); + + validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, + expectedValuesData); + } + private slots: + /// Input test data /// @sa testCtor() void testCtor_data(); @@ -91,6 +140,20 @@ private slots: void testMerge(); /// Input test data + /// @sa testPurgeScalar() + void testPurgeScalar_data(); + + /// Tests purge of a scalar series + void testPurgeScalar(); + + /// Input test data + /// @sa testPurgeVector() + void testPurgeVector_data(); + + /// Tests purge of a vector series + void testPurgeVector(); + + /// Input test data /// @sa testMinXAxisData() void testMinXAxisData_data(); @@ -261,6 +324,62 @@ void TestDataSeries::testMerge() validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData); } +void TestDataSeries::testPurgeScalar_data() +{ + testPurgeStructure(); + + // ////////// // + // Test cases // + // ////////// // + + QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 2. << 4. << QVector{2., 3., 4.} + << QVector >{{200., 300., 400.}}; + QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 0. << 2.5 << QVector{1., 2.} + << QVector >{{100., 200.}}; + QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 3.5 << 7. << QVector{4., 5.} + << QVector >{{400., 500.}}; + QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 0. << 7. << QVector{1., 2., 3., 4., 5.} + << QVector >{{100., 200., 300., 400., 500.}}; + QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 5.5 << 7. << QVector{} + << QVector >{{}}; +} + +void TestDataSeries::testPurgeScalar() +{ + testPurge(); +} + +void TestDataSeries::testPurgeVector_data() +{ + testPurgeStructure(); + + // ////////// // + // Test cases // + // ////////// // + + QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, + {11., 12., 13., 14., 15.}, + {16., 17., 18., 19., 20.}) + << 2. << 4. << QVector{2., 3., 4.} + << QVector >{ + {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}}; +} + +void TestDataSeries::testPurgeVector() +{ + testPurge(); +} + void TestDataSeries::testMinXAxisData_data() { // ////////////// //