##// END OF EJS Templates
Adds unit test for filling data holes at beginning/end of the series
Alexandre Leroux -
r956:ddfbc1763776
parent child
Show More
@@ -18,6 +18,8 void TestDataSeriesUtils::testFillDataHoles_data()
18 QTest::addColumn<std::vector<double> >("valuesData");
18 QTest::addColumn<std::vector<double> >("valuesData");
19 QTest::addColumn<double>("resolution");
19 QTest::addColumn<double>("resolution");
20 QTest::addColumn<double>("fillValue");
20 QTest::addColumn<double>("fillValue");
21 QTest::addColumn<double>("minBound");
22 QTest::addColumn<double>("maxBound");
21 QTest::addColumn<std::vector<double> >(
23 QTest::addColumn<std::vector<double> >(
22 "expectedXAxisData"); // expected x-axis data after filling holes
24 "expectedXAxisData"); // expected x-axis data after filling holes
23 QTest::addColumn<std::vector<double> >(
25 QTest::addColumn<std::vector<double> >(
@@ -27,34 +29,50 void TestDataSeriesUtils::testFillDataHoles_data()
27
29
28 QTest::newRow("fillDataHoles (basic case)")
30 QTest::newRow("fillDataHoles (basic case)")
29 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2.
31 << 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.}
32 << nan << nan << 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.};
33 << std::vector<double>{0., 1., nan, 2., 3., nan, nan, nan, 4.};
32
34
33 QTest::newRow("fillDataHoles (change nb components)")
35 QTest::newRow("fillDataHoles (change nb components)")
34 << std::vector<double>{0., 1., 5., 7., 14.}
36 << std::vector<double>{0., 1., 5., 7., 14.}
35 << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan
37 << std::vector<double>{0., 1., 2., 3., 4., 5., 6., 7., 8., 9.} << 2. << nan << nan << nan
36 << std::vector<double>{0., 1., 3., 5., 7., 9., 11., 13., 14.}
38 << 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.,
39 << std::vector<double>{0., 1., 2., 3., nan, nan, 4., 5., 6.,
38 7., nan, nan, nan, nan, nan, nan, 8., 9.};
40 7., nan, nan, nan, nan, nan, nan, 8., 9.};
39
41
40 QTest::newRow("fillDataHoles (change resolution)")
42 QTest::newRow("fillDataHoles (change resolution)")
41 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.}
43 << 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.}
44 << 1.5 << nan << nan << nan
45 << 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.};
46 << std::vector<double>{0., 1., nan, nan, 2., nan, 3., nan, nan, nan, nan, 4.};
44
47
45 QTest::newRow("fillDataHoles (with no data (no changes made))")
48 QTest::newRow("fillDataHoles (with no data (no changes made))")
46 << std::vector<double>{} << std::vector<double>{} << 2. << nan << std::vector<double>{}
49 << std::vector<double>{} << std::vector<double>{} << 2. << nan << nan << nan
47 << std::vector<double>{};
50 << std::vector<double>{} << std::vector<double>{};
48
51
49 QTest::newRow("fillDataHoles (with no resolution (no changes made))")
52 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.
53 << 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.}
54 << nan << nan << nan << std::vector<double>{0., 1., 5., 7., 14.}
52 << std::vector<double>{0., 1., 2., 3., 4.};
55 << std::vector<double>{0., 1., 2., 3., 4.};
53
56
54 QTest::newRow("fillDataHoles (change fill value)")
57 QTest::newRow("fillDataHoles (change fill value)")
55 << std::vector<double>{0., 1., 5., 7., 14.} << std::vector<double>{0., 1., 2., 3., 4.} << 2.
58 << 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.}
59 << -1. << nan << nan << 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.};
60 << std::vector<double>{0., 1., -1., 2., 3., -1., -1., -1., 4.};
61
62 QTest::newRow("fillDataHoles (add data holes to the beginning)")
63 << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.}
64 << 2. << nan << 0. << nan << std::vector<double>{1., 3., 5., 7., 9., 11., 13.}
65 << std::vector<double>{nan, nan, 0., 1., 2., 3., 4.};
66
67 QTest::newRow("fillDataHoles (add data holes to the end)")
68 << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.}
69 << 2. << nan << nan << 21. << std::vector<double>{5., 7., 9., 11., 13., 15., 17., 19., 21.}
70 << std::vector<double>{0., 1., 2., 3., 4., nan, nan, nan, nan};
71
72 QTest::newRow("fillDataHoles (invalid min/max bounds (no changes made))")
73 << std::vector<double>{5., 7., 9., 11., 13.} << std::vector<double>{0., 1., 2., 3., 4.}
74 << 2. << nan << 8. << 13. << std::vector<double>{5., 7., 9., 11., 13.}
75 << std::vector<double>{0., 1., 2., 3., 4.};
58 }
76 }
59
77
60 void TestDataSeriesUtils::testFillDataHoles()
78 void TestDataSeriesUtils::testFillDataHoles()
@@ -63,12 +81,15 void TestDataSeriesUtils::testFillDataHoles()
63 QFETCH(std::vector<double>, valuesData);
81 QFETCH(std::vector<double>, valuesData);
64 QFETCH(double, resolution);
82 QFETCH(double, resolution);
65 QFETCH(double, fillValue);
83 QFETCH(double, fillValue);
84 QFETCH(double, minBound);
85 QFETCH(double, maxBound);
66
86
67 QFETCH(std::vector<double>, expectedXAxisData);
87 QFETCH(std::vector<double>, expectedXAxisData);
68 QFETCH(std::vector<double>, expectedValuesData);
88 QFETCH(std::vector<double>, expectedValuesData);
69
89
70 // Executes method (xAxisData and valuesData are modified)
90 // Executes method (xAxisData and valuesData are modified)
71 DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue);
91 DataSeriesUtils::fillDataHoles(xAxisData, valuesData, resolution, fillValue, minBound,
92 maxBound);
72
93
73 // Checks results
94 // Checks results
74 auto equal = [](const auto &data, const auto &expectedData) {
95 auto equal = [](const auto &data, const auto &expectedData) {
General Comments 0
You need to be logged in to leave comments. Login now