##// END OF EJS Templates
Implements unit tests
Alexandre Leroux -
r678:0cb0a50bdd13
parent child
Show More
@@ -1,519 +1,638
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 #include "Data/VectorSeries.h"
4
4
5 #include <cmath>
5 #include <cmath>
6
6
7 #include <QObject>
7 #include <QObject>
8 #include <QtTest>
8 #include <QtTest>
9
9
10 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
10 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
11 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
11 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
12
12
13 namespace {
13 namespace {
14
14
15 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
15 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
16 const QVector<double> &valuesData)
16 const QVector<double> &valuesData)
17 {
17 {
18 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
18 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
19 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
19 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
20 QVERIFY(std::equal(
20 QVERIFY(std::equal(
21 first, last, valuesData.cbegin(), valuesData.cend(),
21 first, last, valuesData.cbegin(), valuesData.cend(),
22 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
22 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
23 }
23 }
24
24
25 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData,
26 const QVector<QVector<double> > &valuesData)
27 {
28 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
29 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
30 for (auto i = 0; i < valuesData.size(); ++i) {
31 auto componentData = valuesData.at(i);
32
33 QVERIFY(std::equal(
34 first, last, componentData.cbegin(), componentData.cend(),
35 [i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; }));
36 }
37 }
38
25 } // namespace
39 } // namespace
26
40
27 class TestDataSeries : public QObject {
41 class TestDataSeries : public QObject {
28 Q_OBJECT
42 Q_OBJECT
29 private:
43 private:
30 template <typename T>
44 template <typename T>
31 void testValuesBoundsStructure()
45 void testValuesBoundsStructure()
32 {
46 {
33 // ////////////// //
47 // ////////////// //
34 // Test structure //
48 // Test structure //
35 // ////////////// //
49 // ////////////// //
36
50
37 // Data series to get values bounds
51 // Data series to get values bounds
38 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
52 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
39
53
40 // x-axis range
54 // x-axis range
41 QTest::addColumn<double>("minXAxis");
55 QTest::addColumn<double>("minXAxis");
42 QTest::addColumn<double>("maxXAxis");
56 QTest::addColumn<double>("maxXAxis");
43
57
44 // Expected results
58 // Expected results
45 QTest::addColumn<bool>(
59 QTest::addColumn<bool>(
46 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
60 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
47 QTest::addColumn<double>("expectedMinValue");
61 QTest::addColumn<double>("expectedMinValue");
48 QTest::addColumn<double>("expectedMaxValue");
62 QTest::addColumn<double>("expectedMaxValue");
49 }
63 }
50
64
51 template <typename T>
65 template <typename T>
52 void testValuesBounds()
66 void testValuesBounds()
53 {
67 {
54 QFETCH(std::shared_ptr<T>, dataSeries);
68 QFETCH(std::shared_ptr<T>, dataSeries);
55 QFETCH(double, minXAxis);
69 QFETCH(double, minXAxis);
56 QFETCH(double, maxXAxis);
70 QFETCH(double, maxXAxis);
57
71
58 QFETCH(bool, expectedOK);
72 QFETCH(bool, expectedOK);
59 QFETCH(double, expectedMinValue);
73 QFETCH(double, expectedMinValue);
60 QFETCH(double, expectedMaxValue);
74 QFETCH(double, expectedMaxValue);
61
75
62 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
76 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
63 auto end = dataSeries->cend();
77 auto end = dataSeries->cend();
64
78
65 // Checks iterators with expected result
79 // Checks iterators with expected result
66 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
80 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
67
81
68 if (expectedOK) {
82 if (expectedOK) {
69 auto compare = [](const auto &v1, const auto &v2) {
83 auto compare = [](const auto &v1, const auto &v2) {
70 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
84 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
71 };
85 };
72
86
73 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
87 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
74 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
88 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
75 }
89 }
76 }
90 }
77
91
92 template <typename T>
93 void testPurgeStructure()
94 {
95 // ////////////// //
96 // Test structure //
97 // ////////////// //
98
99 // Data series to purge
100 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
101 QTest::addColumn<double>("min");
102 QTest::addColumn<double>("max");
103
104 // Expected values after purge
105 QTest::addColumn<QVector<double> >("expectedXAxisData");
106 QTest::addColumn<QVector<QVector<double> > >("expectedValuesData");
107 }
108
109 template <typename T>
110 void testPurge()
111 {
112 QFETCH(std::shared_ptr<T>, dataSeries);
113 QFETCH(double, min);
114 QFETCH(double, max);
115
116 dataSeries->purge(min, max);
117
118 // Validates results
119 QFETCH(QVector<double>, expectedXAxisData);
120 QFETCH(QVector<QVector<double> >, expectedValuesData);
121
122 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData,
123 expectedValuesData);
124 }
125
78 private slots:
126 private slots:
127
79 /// Input test data
128 /// Input test data
80 /// @sa testCtor()
129 /// @sa testCtor()
81 void testCtor_data();
130 void testCtor_data();
82
131
83 /// Tests construction of a data series
132 /// Tests construction of a data series
84 void testCtor();
133 void testCtor();
85
134
86 /// Input test data
135 /// Input test data
87 /// @sa testMerge()
136 /// @sa testMerge()
88 void testMerge_data();
137 void testMerge_data();
89
138
90 /// Tests merge of two data series
139 /// Tests merge of two data series
91 void testMerge();
140 void testMerge();
92
141
93 /// Input test data
142 /// Input test data
143 /// @sa testPurgeScalar()
144 void testPurgeScalar_data();
145
146 /// Tests purge of a scalar series
147 void testPurgeScalar();
148
149 /// Input test data
150 /// @sa testPurgeVector()
151 void testPurgeVector_data();
152
153 /// Tests purge of a vector series
154 void testPurgeVector();
155
156 /// Input test data
94 /// @sa testMinXAxisData()
157 /// @sa testMinXAxisData()
95 void testMinXAxisData_data();
158 void testMinXAxisData_data();
96
159
97 /// Tests get min x-axis data of a data series
160 /// Tests get min x-axis data of a data series
98 void testMinXAxisData();
161 void testMinXAxisData();
99
162
100 /// Input test data
163 /// Input test data
101 /// @sa testMaxXAxisData()
164 /// @sa testMaxXAxisData()
102 void testMaxXAxisData_data();
165 void testMaxXAxisData_data();
103
166
104 /// Tests get max x-axis data of a data series
167 /// Tests get max x-axis data of a data series
105 void testMaxXAxisData();
168 void testMaxXAxisData();
106
169
107 /// Input test data
170 /// Input test data
108 /// @sa testXAxisRange()
171 /// @sa testXAxisRange()
109 void testXAxisRange_data();
172 void testXAxisRange_data();
110
173
111 /// Tests get x-axis range of a data series
174 /// Tests get x-axis range of a data series
112 void testXAxisRange();
175 void testXAxisRange();
113
176
114 /// Input test data
177 /// Input test data
115 /// @sa testValuesBoundsScalar()
178 /// @sa testValuesBoundsScalar()
116 void testValuesBoundsScalar_data();
179 void testValuesBoundsScalar_data();
117
180
118 /// Tests get values bounds of a scalar series
181 /// Tests get values bounds of a scalar series
119 void testValuesBoundsScalar();
182 void testValuesBoundsScalar();
120
183
121 /// Input test data
184 /// Input test data
122 /// @sa testValuesBoundsVector()
185 /// @sa testValuesBoundsVector()
123 void testValuesBoundsVector_data();
186 void testValuesBoundsVector_data();
124
187
125 /// Tests get values bounds of a vector series
188 /// Tests get values bounds of a vector series
126 void testValuesBoundsVector();
189 void testValuesBoundsVector();
127 };
190 };
128
191
129 void TestDataSeries::testCtor_data()
192 void TestDataSeries::testCtor_data()
130 {
193 {
131 // ////////////// //
194 // ////////////// //
132 // Test structure //
195 // Test structure //
133 // ////////////// //
196 // ////////////// //
134
197
135 // x-axis data
198 // x-axis data
136 QTest::addColumn<QVector<double> >("xAxisData");
199 QTest::addColumn<QVector<double> >("xAxisData");
137 // values data
200 // values data
138 QTest::addColumn<QVector<double> >("valuesData");
201 QTest::addColumn<QVector<double> >("valuesData");
139
202
140 // expected x-axis data
203 // expected x-axis data
141 QTest::addColumn<QVector<double> >("expectedXAxisData");
204 QTest::addColumn<QVector<double> >("expectedXAxisData");
142 // expected values data
205 // expected values data
143 QTest::addColumn<QVector<double> >("expectedValuesData");
206 QTest::addColumn<QVector<double> >("expectedValuesData");
144
207
145 // ////////// //
208 // ////////// //
146 // Test cases //
209 // Test cases //
147 // ////////// //
210 // ////////// //
148
211
149 QTest::newRow("invalidData (different sizes of vectors)")
212 QTest::newRow("invalidData (different sizes of vectors)")
150 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.}
213 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.}
151 << QVector<double>{} << QVector<double>{};
214 << QVector<double>{} << QVector<double>{};
152
215
153 QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.}
216 QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.}
154 << QVector<double>{100., 200., 300., 400., 500.}
217 << QVector<double>{100., 200., 300., 400., 500.}
155 << QVector<double>{1., 2., 3., 4., 5.}
218 << QVector<double>{1., 2., 3., 4., 5.}
156 << QVector<double>{100., 200., 300., 400., 500.};
219 << QVector<double>{100., 200., 300., 400., 500.};
157
220
158 QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.}
221 QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.}
159 << QVector<double>{100., 200., 300., 400., 500.}
222 << QVector<double>{100., 200., 300., 400., 500.}
160 << QVector<double>{1., 2., 3., 4., 5.}
223 << QVector<double>{1., 2., 3., 4., 5.}
161 << QVector<double>{500., 400., 300., 200., 100.};
224 << QVector<double>{500., 400., 300., 200., 100.};
162
225
163 QTest::newRow("unsortedData2")
226 QTest::newRow("unsortedData2")
164 << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.}
227 << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.}
165 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.};
228 << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.};
166 }
229 }
167
230
168 void TestDataSeries::testCtor()
231 void TestDataSeries::testCtor()
169 {
232 {
170 // Creates series
233 // Creates series
171 QFETCH(QVector<double>, xAxisData);
234 QFETCH(QVector<double>, xAxisData);
172 QFETCH(QVector<double>, valuesData);
235 QFETCH(QVector<double>, valuesData);
173
236
174 auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
237 auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
175 Unit{}, Unit{});
238 Unit{}, Unit{});
176
239
177 // Validates results : we check that the data series is sorted on its x-axis data
240 // Validates results : we check that the data series is sorted on its x-axis data
178 QFETCH(QVector<double>, expectedXAxisData);
241 QFETCH(QVector<double>, expectedXAxisData);
179 QFETCH(QVector<double>, expectedValuesData);
242 QFETCH(QVector<double>, expectedValuesData);
180
243
181 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData);
244 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData);
182 }
245 }
183
246
184 namespace {
247 namespace {
185
248
186 std::shared_ptr<ScalarSeries> createScalarSeries(QVector<double> xAxisData,
249 std::shared_ptr<ScalarSeries> createScalarSeries(QVector<double> xAxisData,
187 QVector<double> valuesData)
250 QVector<double> valuesData)
188 {
251 {
189 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
252 return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
190 Unit{});
253 Unit{});
191 }
254 }
192
255
193 std::shared_ptr<VectorSeries> createVectorSeries(QVector<double> xAxisData,
256 std::shared_ptr<VectorSeries> createVectorSeries(QVector<double> xAxisData,
194 QVector<double> xValuesData,
257 QVector<double> xValuesData,
195 QVector<double> yValuesData,
258 QVector<double> yValuesData,
196 QVector<double> zValuesData)
259 QVector<double> zValuesData)
197 {
260 {
198 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(xValuesData),
261 return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(xValuesData),
199 std::move(yValuesData), std::move(zValuesData), Unit{},
262 std::move(yValuesData), std::move(zValuesData), Unit{},
200 Unit{});
263 Unit{});
201 }
264 }
202
265
203 } // namespace
266 } // namespace
204
267
205 void TestDataSeries::testMerge_data()
268 void TestDataSeries::testMerge_data()
206 {
269 {
207 // ////////////// //
270 // ////////////// //
208 // Test structure //
271 // Test structure //
209 // ////////////// //
272 // ////////////// //
210
273
211 // Data series to merge
274 // Data series to merge
212 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
275 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
213 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2");
276 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2");
214
277
215 // Expected values in the first data series after merge
278 // Expected values in the first data series after merge
216 QTest::addColumn<QVector<double> >("expectedXAxisData");
279 QTest::addColumn<QVector<double> >("expectedXAxisData");
217 QTest::addColumn<QVector<double> >("expectedValuesData");
280 QTest::addColumn<QVector<double> >("expectedValuesData");
218
281
219 // ////////// //
282 // ////////// //
220 // Test cases //
283 // Test cases //
221 // ////////// //
284 // ////////// //
222
285
223 QTest::newRow("sortedMerge")
286 QTest::newRow("sortedMerge")
224 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
287 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
225 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
288 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
226 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
289 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
227 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
290 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
228
291
229 QTest::newRow("unsortedMerge")
292 QTest::newRow("unsortedMerge")
230 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
293 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
231 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
294 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
232 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
295 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
233 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
296 << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
234
297
235 QTest::newRow("unsortedMerge2")
298 QTest::newRow("unsortedMerge2")
236 << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.})
299 << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.})
237 << createScalarSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.})
300 << createScalarSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.})
238 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
301 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
239 << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.};
302 << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.};
240
303
241 QTest::newRow("unsortedMerge3")
304 QTest::newRow("unsortedMerge3")
242 << createScalarSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.})
305 << createScalarSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.})
243 << createScalarSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.})
306 << createScalarSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.})
244 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
307 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
245 << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.};
308 << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.};
246 }
309 }
247
310
248 void TestDataSeries::testMerge()
311 void TestDataSeries::testMerge()
249 {
312 {
250 // Merges series
313 // Merges series
251 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
314 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
252 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2);
315 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2);
253
316
254 dataSeries->merge(dataSeries2.get());
317 dataSeries->merge(dataSeries2.get());
255
318
256 // Validates results : we check that the merge is valid and the data series is sorted on its
319 // Validates results : we check that the merge is valid and the data series is sorted on its
257 // x-axis data
320 // x-axis data
258 QFETCH(QVector<double>, expectedXAxisData);
321 QFETCH(QVector<double>, expectedXAxisData);
259 QFETCH(QVector<double>, expectedValuesData);
322 QFETCH(QVector<double>, expectedValuesData);
260
323
261 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
324 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
262 }
325 }
263
326
327 void TestDataSeries::testPurgeScalar_data()
328 {
329 testPurgeStructure<ScalarSeries>();
330
331 // ////////// //
332 // Test cases //
333 // ////////// //
334
335 QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.},
336 {100., 200., 300., 400., 500.})
337 << 2. << 4. << QVector<double>{2., 3., 4.}
338 << QVector<QVector<double> >{{200., 300., 400.}};
339 QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.},
340 {100., 200., 300., 400., 500.})
341 << 0. << 2.5 << QVector<double>{1., 2.}
342 << QVector<QVector<double> >{{100., 200.}};
343 QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.},
344 {100., 200., 300., 400., 500.})
345 << 3.5 << 7. << QVector<double>{4., 5.}
346 << QVector<QVector<double> >{{400., 500.}};
347 QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.},
348 {100., 200., 300., 400., 500.})
349 << 0. << 7. << QVector<double>{1., 2., 3., 4., 5.}
350 << QVector<QVector<double> >{{100., 200., 300., 400., 500.}};
351 QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.},
352 {100., 200., 300., 400., 500.})
353 << 5.5 << 7. << QVector<double>{}
354 << QVector<QVector<double> >{{}};
355 }
356
357 void TestDataSeries::testPurgeScalar()
358 {
359 testPurge<ScalarSeries>();
360 }
361
362 void TestDataSeries::testPurgeVector_data()
363 {
364 testPurgeStructure<VectorSeries>();
365
366 // ////////// //
367 // Test cases //
368 // ////////// //
369
370 QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.},
371 {11., 12., 13., 14., 15.},
372 {16., 17., 18., 19., 20.})
373 << 2. << 4. << QVector<double>{2., 3., 4.}
374 << QVector<QVector<double> >{
375 {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}};
376 }
377
378 void TestDataSeries::testPurgeVector()
379 {
380 testPurge<VectorSeries>();
381 }
382
264 void TestDataSeries::testMinXAxisData_data()
383 void TestDataSeries::testMinXAxisData_data()
265 {
384 {
266 // ////////////// //
385 // ////////////// //
267 // Test structure //
386 // Test structure //
268 // ////////////// //
387 // ////////////// //
269
388
270 // Data series to get min data
389 // Data series to get min data
271 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
390 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
272
391
273 // Min data
392 // Min data
274 QTest::addColumn<double>("min");
393 QTest::addColumn<double>("min");
275
394
276 // Expected results
395 // Expected results
277 QTest::addColumn<bool>(
396 QTest::addColumn<bool>(
278 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
397 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
279 QTest::addColumn<double>(
398 QTest::addColumn<double>(
280 "expectedMin"); // Expected value when method doesn't return end iterator
399 "expectedMin"); // Expected value when method doesn't return end iterator
281
400
282 // ////////// //
401 // ////////// //
283 // Test cases //
402 // Test cases //
284 // ////////// //
403 // ////////// //
285
404
286 QTest::newRow("minData1") << createScalarSeries({1., 2., 3., 4., 5.},
405 QTest::newRow("minData1") << createScalarSeries({1., 2., 3., 4., 5.},
287 {100., 200., 300., 400., 500.})
406 {100., 200., 300., 400., 500.})
288 << 0. << true << 1.;
407 << 0. << true << 1.;
289 QTest::newRow("minData2") << createScalarSeries({1., 2., 3., 4., 5.},
408 QTest::newRow("minData2") << createScalarSeries({1., 2., 3., 4., 5.},
290 {100., 200., 300., 400., 500.})
409 {100., 200., 300., 400., 500.})
291 << 1. << true << 1.;
410 << 1. << true << 1.;
292 QTest::newRow("minData3") << createScalarSeries({1., 2., 3., 4., 5.},
411 QTest::newRow("minData3") << createScalarSeries({1., 2., 3., 4., 5.},
293 {100., 200., 300., 400., 500.})
412 {100., 200., 300., 400., 500.})
294 << 1.1 << true << 2.;
413 << 1.1 << true << 2.;
295 QTest::newRow("minData4") << createScalarSeries({1., 2., 3., 4., 5.},
414 QTest::newRow("minData4") << createScalarSeries({1., 2., 3., 4., 5.},
296 {100., 200., 300., 400., 500.})
415 {100., 200., 300., 400., 500.})
297 << 5. << true << 5.;
416 << 5. << true << 5.;
298 QTest::newRow("minData5") << createScalarSeries({1., 2., 3., 4., 5.},
417 QTest::newRow("minData5") << createScalarSeries({1., 2., 3., 4., 5.},
299 {100., 200., 300., 400., 500.})
418 {100., 200., 300., 400., 500.})
300 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
419 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
301 QTest::newRow("minData6") << createScalarSeries({}, {}) << 1.1 << false
420 QTest::newRow("minData6") << createScalarSeries({}, {}) << 1.1 << false
302 << std::numeric_limits<double>::quiet_NaN();
421 << std::numeric_limits<double>::quiet_NaN();
303 }
422 }
304
423
305 void TestDataSeries::testMinXAxisData()
424 void TestDataSeries::testMinXAxisData()
306 {
425 {
307 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
426 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
308 QFETCH(double, min);
427 QFETCH(double, min);
309
428
310 QFETCH(bool, expectedOK);
429 QFETCH(bool, expectedOK);
311 QFETCH(double, expectedMin);
430 QFETCH(double, expectedMin);
312
431
313 auto it = dataSeries->minXAxisData(min);
432 auto it = dataSeries->minXAxisData(min);
314
433
315 QCOMPARE(expectedOK, it != dataSeries->cend());
434 QCOMPARE(expectedOK, it != dataSeries->cend());
316
435
317 // If the method doesn't return a end iterator, checks with expected value
436 // If the method doesn't return a end iterator, checks with expected value
318 if (expectedOK) {
437 if (expectedOK) {
319 QCOMPARE(expectedMin, it->x());
438 QCOMPARE(expectedMin, it->x());
320 }
439 }
321 }
440 }
322
441
323 void TestDataSeries::testMaxXAxisData_data()
442 void TestDataSeries::testMaxXAxisData_data()
324 {
443 {
325 // ////////////// //
444 // ////////////// //
326 // Test structure //
445 // Test structure //
327 // ////////////// //
446 // ////////////// //
328
447
329 // Data series to get max data
448 // Data series to get max data
330 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
449 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
331
450
332 // Max data
451 // Max data
333 QTest::addColumn<double>("max");
452 QTest::addColumn<double>("max");
334
453
335 // Expected results
454 // Expected results
336 QTest::addColumn<bool>(
455 QTest::addColumn<bool>(
337 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
456 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
338 QTest::addColumn<double>(
457 QTest::addColumn<double>(
339 "expectedMax"); // Expected value when method doesn't return end iterator
458 "expectedMax"); // Expected value when method doesn't return end iterator
340
459
341 // ////////// //
460 // ////////// //
342 // Test cases //
461 // Test cases //
343 // ////////// //
462 // ////////// //
344
463
345 QTest::newRow("maxData1") << createScalarSeries({1., 2., 3., 4., 5.},
464 QTest::newRow("maxData1") << createScalarSeries({1., 2., 3., 4., 5.},
346 {100., 200., 300., 400., 500.})
465 {100., 200., 300., 400., 500.})
347 << 6. << true << 5.;
466 << 6. << true << 5.;
348 QTest::newRow("maxData2") << createScalarSeries({1., 2., 3., 4., 5.},
467 QTest::newRow("maxData2") << createScalarSeries({1., 2., 3., 4., 5.},
349 {100., 200., 300., 400., 500.})
468 {100., 200., 300., 400., 500.})
350 << 5. << true << 5.;
469 << 5. << true << 5.;
351 QTest::newRow("maxData3") << createScalarSeries({1., 2., 3., 4., 5.},
470 QTest::newRow("maxData3") << createScalarSeries({1., 2., 3., 4., 5.},
352 {100., 200., 300., 400., 500.})
471 {100., 200., 300., 400., 500.})
353 << 4.9 << true << 4.;
472 << 4.9 << true << 4.;
354 QTest::newRow("maxData4") << createScalarSeries({1., 2., 3., 4., 5.},
473 QTest::newRow("maxData4") << createScalarSeries({1., 2., 3., 4., 5.},
355 {100., 200., 300., 400., 500.})
474 {100., 200., 300., 400., 500.})
356 << 1.1 << true << 1.;
475 << 1.1 << true << 1.;
357 QTest::newRow("maxData5") << createScalarSeries({1., 2., 3., 4., 5.},
476 QTest::newRow("maxData5") << createScalarSeries({1., 2., 3., 4., 5.},
358 {100., 200., 300., 400., 500.})
477 {100., 200., 300., 400., 500.})
359 << 1. << true << 1.;
478 << 1. << true << 1.;
360 QTest::newRow("maxData6") << createScalarSeries({}, {}) << 1.1 << false
479 QTest::newRow("maxData6") << createScalarSeries({}, {}) << 1.1 << false
361 << std::numeric_limits<double>::quiet_NaN();
480 << std::numeric_limits<double>::quiet_NaN();
362 }
481 }
363
482
364 void TestDataSeries::testMaxXAxisData()
483 void TestDataSeries::testMaxXAxisData()
365 {
484 {
366 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
485 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
367 QFETCH(double, max);
486 QFETCH(double, max);
368
487
369 QFETCH(bool, expectedOK);
488 QFETCH(bool, expectedOK);
370 QFETCH(double, expectedMax);
489 QFETCH(double, expectedMax);
371
490
372 auto it = dataSeries->maxXAxisData(max);
491 auto it = dataSeries->maxXAxisData(max);
373
492
374 QCOMPARE(expectedOK, it != dataSeries->cend());
493 QCOMPARE(expectedOK, it != dataSeries->cend());
375
494
376 // If the method doesn't return a end iterator, checks with expected value
495 // If the method doesn't return a end iterator, checks with expected value
377 if (expectedOK) {
496 if (expectedOK) {
378 QCOMPARE(expectedMax, it->x());
497 QCOMPARE(expectedMax, it->x());
379 }
498 }
380 }
499 }
381
500
382 void TestDataSeries::testXAxisRange_data()
501 void TestDataSeries::testXAxisRange_data()
383 {
502 {
384 // ////////////// //
503 // ////////////// //
385 // Test structure //
504 // Test structure //
386 // ////////////// //
505 // ////////////// //
387
506
388 // Data series to get x-axis range
507 // Data series to get x-axis range
389 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
508 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
390
509
391 // Min/max values
510 // Min/max values
392 QTest::addColumn<double>("min");
511 QTest::addColumn<double>("min");
393 QTest::addColumn<double>("max");
512 QTest::addColumn<double>("max");
394
513
395 // Expected values
514 // Expected values
396 QTest::addColumn<QVector<double> >("expectedXAxisData");
515 QTest::addColumn<QVector<double> >("expectedXAxisData");
397 QTest::addColumn<QVector<double> >("expectedValuesData");
516 QTest::addColumn<QVector<double> >("expectedValuesData");
398
517
399 // ////////// //
518 // ////////// //
400 // Test cases //
519 // Test cases //
401 // ////////// //
520 // ////////// //
402
521
403 QTest::newRow("xAxisRange1") << createScalarSeries({1., 2., 3., 4., 5.},
522 QTest::newRow("xAxisRange1") << createScalarSeries({1., 2., 3., 4., 5.},
404 {100., 200., 300., 400., 500.})
523 {100., 200., 300., 400., 500.})
405 << -1. << 3.2 << QVector<double>{1., 2., 3.}
524 << -1. << 3.2 << QVector<double>{1., 2., 3.}
406 << QVector<double>{100., 200., 300.};
525 << QVector<double>{100., 200., 300.};
407 QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.},
526 QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.},
408 {100., 200., 300., 400., 500.})
527 {100., 200., 300., 400., 500.})
409 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
528 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
410 << QVector<double>{100., 200., 300., 400.};
529 << QVector<double>{100., 200., 300., 400.};
411 QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.},
530 QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.},
412 {100., 200., 300., 400., 500.})
531 {100., 200., 300., 400., 500.})
413 << 1. << 3.9 << QVector<double>{1., 2., 3.}
532 << 1. << 3.9 << QVector<double>{1., 2., 3.}
414 << QVector<double>{100., 200., 300.};
533 << QVector<double>{100., 200., 300.};
415 QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.},
534 QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.},
416 {100., 200., 300., 400., 500.})
535 {100., 200., 300., 400., 500.})
417 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
536 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
418 QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.},
537 QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.},
419 {100., 200., 300., 400., 500.})
538 {100., 200., 300., 400., 500.})
420 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
539 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
421 QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.},
540 QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.},
422 {100., 200., 300., 400., 500.})
541 {100., 200., 300., 400., 500.})
423 << 2.1 << 6. << QVector<double>{3., 4., 5.}
542 << 2.1 << 6. << QVector<double>{3., 4., 5.}
424 << QVector<double>{300., 400., 500.};
543 << QVector<double>{300., 400., 500.};
425 QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.},
544 QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.},
426 {100., 200., 300., 400., 500.})
545 {100., 200., 300., 400., 500.})
427 << 6. << 9. << QVector<double>{} << QVector<double>{};
546 << 6. << 9. << QVector<double>{} << QVector<double>{};
428 QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.},
547 QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.},
429 {100., 200., 300., 400., 500.})
548 {100., 200., 300., 400., 500.})
430 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
549 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
431 }
550 }
432
551
433 void TestDataSeries::testXAxisRange()
552 void TestDataSeries::testXAxisRange()
434 {
553 {
435 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
554 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
436 QFETCH(double, min);
555 QFETCH(double, min);
437 QFETCH(double, max);
556 QFETCH(double, max);
438
557
439 QFETCH(QVector<double>, expectedXAxisData);
558 QFETCH(QVector<double>, expectedXAxisData);
440 QFETCH(QVector<double>, expectedValuesData);
559 QFETCH(QVector<double>, expectedValuesData);
441
560
442 auto bounds = dataSeries->xAxisRange(min, max);
561 auto bounds = dataSeries->xAxisRange(min, max);
443 validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData);
562 validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData);
444 }
563 }
445
564
446 void TestDataSeries::testValuesBoundsScalar_data()
565 void TestDataSeries::testValuesBoundsScalar_data()
447 {
566 {
448 testValuesBoundsStructure<ScalarSeries>();
567 testValuesBoundsStructure<ScalarSeries>();
449
568
450 // ////////// //
569 // ////////// //
451 // Test cases //
570 // Test cases //
452 // ////////// //
571 // ////////// //
453 auto nan = std::numeric_limits<double>::quiet_NaN();
572 auto nan = std::numeric_limits<double>::quiet_NaN();
454
573
455 QTest::newRow("scalarBounds1")
574 QTest::newRow("scalarBounds1")
456 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6.
575 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6.
457 << true << 100. << 500.;
576 << true << 100. << 500.;
458 QTest::newRow("scalarBounds2")
577 QTest::newRow("scalarBounds2")
459 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4.
578 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4.
460 << true << 200. << 400.;
579 << true << 200. << 400.;
461 QTest::newRow("scalarBounds3")
580 QTest::newRow("scalarBounds3")
462 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5
581 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5
463 << false << nan << nan;
582 << false << nan << nan;
464 QTest::newRow("scalarBounds4")
583 QTest::newRow("scalarBounds4")
465 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6.
584 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6.
466 << false << nan << nan;
585 << false << nan << nan;
467 QTest::newRow("scalarBounds5") << createScalarSeries({1.}, {100.}) << 0. << 2. << true << 100.
586 QTest::newRow("scalarBounds5") << createScalarSeries({1.}, {100.}) << 0. << 2. << true << 100.
468 << 100.;
587 << 100.;
469 QTest::newRow("scalarBounds6") << createScalarSeries({}, {}) << 0. << 2. << false << nan << nan;
588 QTest::newRow("scalarBounds6") << createScalarSeries({}, {}) << 0. << 2. << false << nan << nan;
470
589
471 // Tests with NaN values: NaN values are not included in min/max search
590 // Tests with NaN values: NaN values are not included in min/max search
472 QTest::newRow("scalarBounds7")
591 QTest::newRow("scalarBounds7")
473 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, 200., 300., 400., nan}) << 0. << 6.
592 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, 200., 300., 400., nan}) << 0. << 6.
474 << true << 200. << 400.;
593 << true << 200. << 400.;
475 QTest::newRow("scalarBounds8")
594 QTest::newRow("scalarBounds8")
476 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, nan, nan, nan, nan}) << 0. << 6. << true
595 << createScalarSeries({1., 2., 3., 4., 5.}, {nan, nan, nan, nan, nan}) << 0. << 6. << true
477 << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
596 << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
478 }
597 }
479
598
480 void TestDataSeries::testValuesBoundsScalar()
599 void TestDataSeries::testValuesBoundsScalar()
481 {
600 {
482 testValuesBounds<ScalarSeries>();
601 testValuesBounds<ScalarSeries>();
483 }
602 }
484
603
485 void TestDataSeries::testValuesBoundsVector_data()
604 void TestDataSeries::testValuesBoundsVector_data()
486 {
605 {
487 testValuesBoundsStructure<VectorSeries>();
606 testValuesBoundsStructure<VectorSeries>();
488
607
489 // ////////// //
608 // ////////// //
490 // Test cases //
609 // Test cases //
491 // ////////// //
610 // ////////// //
492 auto nan = std::numeric_limits<double>::quiet_NaN();
611 auto nan = std::numeric_limits<double>::quiet_NaN();
493
612
494 QTest::newRow("vectorBounds1")
613 QTest::newRow("vectorBounds1")
495 << createVectorSeries({1., 2., 3., 4., 5.}, {10., 15., 20., 13., 12.},
614 << createVectorSeries({1., 2., 3., 4., 5.}, {10., 15., 20., 13., 12.},
496 {35., 24., 10., 9., 0.3}, {13., 14., 12., 9., 24.})
615 {35., 24., 10., 9., 0.3}, {13., 14., 12., 9., 24.})
497 << 0. << 6. << true << 0.3 << 35.; // min/max in same component
616 << 0. << 6. << true << 0.3 << 35.; // min/max in same component
498 QTest::newRow("vectorBounds2")
617 QTest::newRow("vectorBounds2")
499 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
618 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
500 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
619 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
501 << 0. << 6. << true << 2.3 << 35.; // min/max in same entry
620 << 0. << 6. << true << 2.3 << 35.; // min/max in same entry
502 QTest::newRow("vectorBounds3")
621 QTest::newRow("vectorBounds3")
503 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
622 << createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
504 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
623 {35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
505 << 2. << 3. << true << 10. << 24.;
624 << 2. << 3. << true << 10. << 24.;
506
625
507 // Tests with NaN values: NaN values are not included in min/max search
626 // Tests with NaN values: NaN values are not included in min/max search
508 QTest::newRow("vectorBounds4")
627 QTest::newRow("vectorBounds4")
509 << createVectorSeries({1., 2.}, {nan, nan}, {nan, nan}, {nan, nan}) << 0. << 6. << true
628 << createVectorSeries({1., 2.}, {nan, nan}, {nan, nan}, {nan, nan}) << 0. << 6. << true
510 << nan << nan;
629 << nan << nan;
511 }
630 }
512
631
513 void TestDataSeries::testValuesBoundsVector()
632 void TestDataSeries::testValuesBoundsVector()
514 {
633 {
515 testValuesBounds<VectorSeries>();
634 testValuesBounds<VectorSeries>();
516 }
635 }
517
636
518 QTEST_MAIN(TestDataSeries)
637 QTEST_MAIN(TestDataSeries)
519 #include "TestDataSeries.moc"
638 #include "TestDataSeries.moc"
General Comments 0
You need to be logged in to leave comments. Login now