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