##// END OF EJS Templates
Units tests on sorting data series
Alexandre Leroux -
r421:df8e44ec6007
parent child
Show More
@@ -0,0 +1,164
1 #include "Data/DataSeries.h"
2 #include "Data/ScalarSeries.h"
3
4 #include <QObject>
5 #include <QtTest>
6
7 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
8
9 class TestDataSeries : public QObject {
10 Q_OBJECT
11 private slots:
12 /// Input test data
13 /// @sa testCtor()
14 void testCtor_data();
15
16 /// Tests construction of a data series
17 void testCtor();
18
19 /// Input test data
20 /// @sa testMerge()
21 void testMerge_data();
22
23 /// Tests merge of two data series
24 void testMerge();
25 };
26
27 void TestDataSeries::testCtor_data()
28 {
29 // ////////////// //
30 // Test structure //
31 // ////////////// //
32
33 // x-axis data
34 QTest::addColumn<QVector<double> >("xAxisData");
35 // values data
36 QTest::addColumn<QVector<double> >("valuesData");
37
38 // expected x-axis data
39 QTest::addColumn<QVector<double> >("expectedXAxisData");
40 // expected values data
41 QTest::addColumn<QVector<double> >("expectedValuesData");
42
43 // ////////// //
44 // Test cases //
45 // ////////// //
46
47 QTest::newRow("invalidData (different sizes of vectors)")
48 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.}
49 << QVector<double>{} << QVector<double>{};
50
51 QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.}
52 << QVector<double>{100., 200., 300., 400., 500.}
53 << QVector<double>{1., 2., 3., 4., 5.}
54 << QVector<double>{100., 200., 300., 400., 500.};
55
56 QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.}
57 << QVector<double>{100., 200., 300., 400., 500.}
58 << QVector<double>{1., 2., 3., 4., 5.}
59 << QVector<double>{500., 400., 300., 200., 100.};
60
61 QTest::newRow("unsortedData2")
62 << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.}
63 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.};
64 }
65
66 void TestDataSeries::testCtor()
67 {
68 // Creates series
69 QFETCH(QVector<double>, xAxisData);
70 QFETCH(QVector<double>, valuesData);
71
72 auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
73 Unit{}, Unit{});
74
75 // Validates results : we check that the data series is sorted on its x-axis data
76 QFETCH(QVector<double>, expectedXAxisData);
77 QFETCH(QVector<double>, expectedValuesData);
78
79 auto seriesXAxisData = series->xAxisData()->data();
80 auto seriesValuesData = series->valuesData()->data();
81
82 QVERIFY(
83 std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin()));
84 QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(),
85 seriesValuesData.cbegin()));
86 }
87
88 namespace {
89
90 std::shared_ptr<ScalarSeries> createSeries(QVector<double> xAxisData, QVector<double> valuesData)
91 {
92 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
93 Unit{});
94 }
95
96 } // namespace
97
98 void TestDataSeries::testMerge_data()
99 {
100 // ////////////// //
101 // Test structure //
102 // ////////////// //
103
104 // Data series to merge
105 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
106 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2");
107
108 // Expected values in the first data series after merge
109 QTest::addColumn<QVector<double> >("expectedXAxisData");
110 QTest::addColumn<QVector<double> >("expectedValuesData");
111
112 // ////////// //
113 // Test cases //
114 // ////////// //
115
116 QTest::newRow("sortedMerge")
117 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
118 << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
119 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
120 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
121
122 QTest::newRow("unsortedMerge")
123 << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
124 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
125 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
126 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
127
128 QTest::newRow("unsortedMerge2")
129 << createSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.})
130 << createSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.})
131 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
132 << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.};
133
134 QTest::newRow("unsortedMerge3")
135 << createSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.})
136 << createSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.})
137 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
138 << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.};
139 }
140
141 void TestDataSeries::testMerge()
142 {
143 // Merges series
144 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
145 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2);
146
147 dataSeries->merge(dataSeries2.get());
148
149 // Validates results : we check that the merge is valid and the data series is sorted on its
150 // x-axis data
151 QFETCH(QVector<double>, expectedXAxisData);
152 QFETCH(QVector<double>, expectedValuesData);
153
154 auto seriesXAxisData = dataSeries->xAxisData()->data();
155 auto seriesValuesData = dataSeries->valuesData()->data();
156
157 QVERIFY(
158 std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin()));
159 QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(),
160 seriesValuesData.cbegin()));
161 }
162
163 QTEST_MAIN(TestDataSeries)
164 #include "TestDataSeries.moc"
General Comments 0
You need to be logged in to leave comments. Login now