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