@@ -0,0 +1,87 | |||||
|
1 | #include <Data/DataSeriesUtils.h> | |||
|
2 | ||||
|
3 | #include <QObject> | |||
|
4 | #include <QtTest> | |||
|
5 | ||||
|
6 | class TestDataSeriesUtils : public QObject { | |||
|
7 | Q_OBJECT | |||
|
8 | ||||
|
9 | private slots: | |||
|
10 | /// Tests @sa DataSeriesUtils::fillDataHoles() method | |||
|
11 | void testFillDataHoles_data(); | |||
|
12 | void testFillDataHoles(); | |||
|
13 | }; | |||
|
14 | ||||
|
15 | void TestDataSeriesUtils::testFillDataHoles_data() | |||
|
16 | { | |||
|
17 | QTest::addColumn<std::vector<double> >("xAxisData"); | |||
|
18 | QTest::addColumn<std::vector<double> >("valuesData"); | |||
|
19 | QTest::addColumn<double>("resolution"); | |||
|
20 | QTest::addColumn<double>("fillValue"); | |||
|
21 | QTest::addColumn<std::vector<double> >( | |||
|
22 | "expectedXAxisData"); // expected x-axis data after filling holes | |||
|
23 | QTest::addColumn<std::vector<double> >( | |||
|
24 | "expectedValuesData"); // expected values data after filling holes | |||
|
25 | ||||
|
26 | auto nan = std::numeric_limits<double>::quiet_NaN(); | |||
|
27 | ||||
|
28 | QTest::newRow("fillDataHoles (basic case)") | |||
|
29 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. | |||
|
30 | << nan << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |||
|
31 | << std::vector<double>{0., 1., nan, 2., 3., nan, nan, nan, 4.}; | |||
|
32 | ||||
|
33 | QTest::newRow("fillDataHoles (change nb components)") | |||
|
34 | << std::vector<double>{0., 1., 5., 7., 14.} | |||
|
35 | << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan | |||
|
36 | << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |||
|
37 | << std::vector<double>{0., 1., 2., 3., nan, nan, 4., 5., 6., | |||
|
38 | 7., nan, nan, nan, nan, nan, nan, 8., 9.}; | |||
|
39 | ||||
|
40 | QTest::newRow("fillDataHoles (change resolution)") | |||
|
41 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} | |||
|
42 | << 1.5 << nan << std::vector<double>{0., 1., 2.5, 4., 5., 6.5, 7., 8.5, 10., 11.5, 13., 14.} | |||
|
43 | << std::vector<double>{0., 1., nan, nan, 2., nan, 3., nan, nan, nan, nan, 4.}; | |||
|
44 | ||||
|
45 | QTest::newRow("fillDataHoles (with no data (no changes made))") | |||
|
46 | << std::vector<double>{} << std::vector<double>{} << 2. << nan << std::vector<double>{} | |||
|
47 | << std::vector<double>{}; | |||
|
48 | ||||
|
49 | QTest::newRow("fillDataHoles (with no resolution (no changes made))") | |||
|
50 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 0. | |||
|
51 | << nan << std::vector<double>{0., 1., 5., 7., 14.} | |||
|
52 | << std::vector<double>{0., 1., 2., 3., 4.}; | |||
|
53 | ||||
|
54 | QTest::newRow("fillDataHoles (change fill value)") | |||
|
55 | << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2. | |||
|
56 | << -1. << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.} | |||
|
57 | << std::vector<double>{0., 1., -1., 2., 3., -1., -1., -1., 4.}; | |||
|
58 | } | |||
|
59 | ||||
|
60 | void TestDataSeriesUtils::testFillDataHoles() | |||
|
61 | { | |||
|
62 | QFETCH(std::vector<double>, xAxisData); | |||
|
63 | QFETCH(std::vector<double>, valuesData); | |||
|
64 | QFETCH(double, resolution); | |||
|
65 | QFETCH(double, fillValue); | |||
|
66 | ||||
|
67 | QFETCH(std::vector<double>, expectedXAxisData); | |||
|
68 | QFETCH(std::vector<double>, expectedValuesData); | |||
|
69 | ||||
|
70 | // Executes method (xAxisData and valuesData are modified) | |||
|
71 | DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue); | |||
|
72 | ||||
|
73 | // Checks results | |||
|
74 | auto equal = [](const auto &data, const auto &expectedData) { | |||
|
75 | // Compares with NaN values | |||
|
76 | return std::equal(data.begin(), data.end(), expectedData.begin(), expectedData.end(), | |||
|
77 | [](const auto &val, const auto &expectedVal) { | |||
|
78 | return (std::isnan(val) && std::isnan(expectedVal)) | |||
|
79 | || val == expectedVal; | |||
|
80 | }); | |||
|
81 | }; | |||
|
82 | QVERIFY(equal(xAxisData, expectedXAxisData)); | |||
|
83 | QVERIFY(equal(valuesData, expectedValuesData)); | |||
|
84 | } | |||
|
85 | ||||
|
86 | QTEST_MAIN(TestDataSeriesUtils) | |||
|
87 | #include "TestDataSeriesUtils.moc" |
@@ -27,6 +27,7 core_sources = [ | |||||
27 | 'src/Data/ArrayDataIterator.cpp', |
|
27 | 'src/Data/ArrayDataIterator.cpp', | |
28 | 'src/Data/VectorSeries.cpp', |
|
28 | 'src/Data/VectorSeries.cpp', | |
29 | 'src/Data/OptionalAxis.cpp', |
|
29 | 'src/Data/OptionalAxis.cpp', | |
|
30 | 'src/Data/DataSeriesUtils.cpp', | |||
30 | 'src/DataSource/DataSourceController.cpp', |
|
31 | 'src/DataSource/DataSourceController.cpp', | |
31 | 'src/DataSource/DataSourceItem.cpp', |
|
32 | 'src/DataSource/DataSourceItem.cpp', | |
32 | 'src/DataSource/DataSourceItemAction.cpp', |
|
33 | 'src/DataSource/DataSourceItemAction.cpp', |
@@ -8,6 +8,7 tests = [ | |||||
8 | [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'], |
|
8 | [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'], | |
9 | [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'], |
|
9 | [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'], | |
10 | [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'], |
|
10 | [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'], | |
|
11 | [['Data/TestDataSeriesUtils.cpp'],'test_dataseries_util','Data series utils test'], | |||
11 | [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'], |
|
12 | [['DataSource/TestDataSourceController.cpp'],'test_data_source','DataSourceController test'], | |
12 | [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'], |
|
13 | [['Variable/TestVariableCacheController.cpp'],'test_variable_cache','VariableCacheController test'], | |
13 | [['Variable/TestVariable.cpp'],'test_variable','Variable test'], |
|
14 | [['Variable/TestVariable.cpp'],'test_variable','Variable test'], |
General Comments 0
You need to be logged in to leave comments.
Login now