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