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