@@ -12,8 +12,10 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>) | |||
|
12 | 12 | |
|
13 | 13 | namespace { |
|
14 | 14 | |
|
15 | void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData, | |
|
16 | const QVector<double> &valuesData) | |
|
15 | using DataContainer = std::vector<double>; | |
|
16 | ||
|
17 | void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData, | |
|
18 | const DataContainer &valuesData) | |
|
17 | 19 | { |
|
18 | 20 | QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), |
|
19 | 21 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); |
@@ -22,8 +24,8 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVec | |||
|
22 | 24 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); |
|
23 | 25 | } |
|
24 | 26 | |
|
25 |
void validateRange(DataSeriesIterator first, DataSeriesIterator last, const |
|
|
26 |
const |
|
|
27 | void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData, | |
|
28 | const std::vector<DataContainer> &valuesData) | |
|
27 | 29 | { |
|
28 | 30 | QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), |
|
29 | 31 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); |
@@ -102,8 +104,8 private: | |||
|
102 | 104 | QTest::addColumn<double>("max"); |
|
103 | 105 | |
|
104 | 106 | // Expected values after purge |
|
105 |
QTest::addColumn< |
|
|
106 |
QTest::addColumn< |
|
|
107 | QTest::addColumn<DataContainer>("expectedXAxisData"); | |
|
108 | QTest::addColumn<std::vector<DataContainer> >("expectedValuesData"); | |
|
107 | 109 | } |
|
108 | 110 | |
|
109 | 111 | template <typename T> |
@@ -116,8 +118,8 private: | |||
|
116 | 118 | dataSeries->purge(min, max); |
|
117 | 119 | |
|
118 | 120 | // Validates results |
|
119 |
QFETCH( |
|
|
120 |
QFETCH( |
|
|
121 | QFETCH(DataContainer, expectedXAxisData); | |
|
122 | QFETCH(std::vector<DataContainer>, expectedValuesData); | |
|
121 | 123 | |
|
122 | 124 | validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, |
|
123 | 125 | expectedValuesData); |
@@ -196,67 +198,65 void TestDataSeries::testCtor_data() | |||
|
196 | 198 | // ////////////// // |
|
197 | 199 | |
|
198 | 200 | // x-axis data |
|
199 |
QTest::addColumn< |
|
|
201 | QTest::addColumn<DataContainer>("xAxisData"); | |
|
200 | 202 | // values data |
|
201 |
QTest::addColumn< |
|
|
203 | QTest::addColumn<DataContainer>("valuesData"); | |
|
202 | 204 | |
|
203 | 205 | // expected x-axis data |
|
204 |
QTest::addColumn< |
|
|
206 | QTest::addColumn<DataContainer>("expectedXAxisData"); | |
|
205 | 207 | // expected values data |
|
206 |
QTest::addColumn< |
|
|
208 | QTest::addColumn<DataContainer>("expectedValuesData"); | |
|
207 | 209 | |
|
208 | 210 | // ////////// // |
|
209 | 211 | // Test cases // |
|
210 | 212 | // ////////// // |
|
211 | 213 | |
|
212 | 214 | QTest::newRow("invalidData (different sizes of vectors)") |
|
213 |
<< |
|
|
214 | << QVector<double>{} << QVector<double>{}; | |
|
215 | << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300.} << DataContainer{} | |
|
216 | << DataContainer{}; | |
|
215 | 217 | |
|
216 |
QTest::newRow("sortedData") << |
|
|
217 |
<< |
|
|
218 |
<< |
|
|
219 |
<< |
|
|
218 | QTest::newRow("sortedData") << DataContainer{1., 2., 3., 4., 5.} | |
|
219 | << DataContainer{100., 200., 300., 400., 500.} | |
|
220 | << DataContainer{1., 2., 3., 4., 5.} | |
|
221 | << DataContainer{100., 200., 300., 400., 500.}; | |
|
220 | 222 | |
|
221 |
QTest::newRow("unsortedData") << |
|
|
222 |
<< |
|
|
223 |
<< |
|
|
224 |
<< |
|
|
223 | QTest::newRow("unsortedData") << DataContainer{5., 4., 3., 2., 1.} | |
|
224 | << DataContainer{100., 200., 300., 400., 500.} | |
|
225 | << DataContainer{1., 2., 3., 4., 5.} | |
|
226 | << DataContainer{500., 400., 300., 200., 100.}; | |
|
225 | 227 | |
|
226 | 228 | QTest::newRow("unsortedData2") |
|
227 |
<< |
|
|
228 |
<< |
|
|
229 | << DataContainer{1., 4., 3., 5., 2.} << DataContainer{100., 200., 300., 400., 500.} | |
|
230 | << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 500., 300., 200., 400.}; | |
|
229 | 231 | } |
|
230 | 232 | |
|
231 | 233 | void TestDataSeries::testCtor() |
|
232 | 234 | { |
|
233 | 235 | // Creates series |
|
234 |
QFETCH( |
|
|
235 |
QFETCH( |
|
|
236 | QFETCH(DataContainer, xAxisData); | |
|
237 | QFETCH(DataContainer, valuesData); | |
|
236 | 238 | |
|
237 | 239 | auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), |
|
238 | 240 | Unit{}, Unit{}); |
|
239 | 241 | |
|
240 | 242 | // Validates results : we check that the data series is sorted on its x-axis data |
|
241 |
QFETCH( |
|
|
242 |
QFETCH( |
|
|
243 | QFETCH(DataContainer, expectedXAxisData); | |
|
244 | QFETCH(DataContainer, expectedValuesData); | |
|
243 | 245 | |
|
244 | 246 | validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData); |
|
245 | 247 | } |
|
246 | 248 | |
|
247 | 249 | namespace { |
|
248 | 250 | |
|
249 |
std::shared_ptr<ScalarSeries> createScalarSeries( |
|
|
250 | QVector<double> valuesData) | |
|
251 | std::shared_ptr<ScalarSeries> createScalarSeries(DataContainer xAxisData, DataContainer valuesData) | |
|
251 | 252 | { |
|
252 | 253 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, |
|
253 | 254 | Unit{}); |
|
254 | 255 | } |
|
255 | 256 | |
|
256 |
std::shared_ptr<VectorSeries> createVectorSeries( |
|
|
257 |
|
|
|
258 |
|
|
|
259 | QVector<double> zValuesData) | |
|
257 | std::shared_ptr<VectorSeries> createVectorSeries(DataContainer xAxisData, DataContainer xValuesData, | |
|
258 | DataContainer yValuesData, | |
|
259 | DataContainer zValuesData) | |
|
260 | 260 | { |
|
261 | 261 | return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(xValuesData), |
|
262 | 262 | std::move(yValuesData), std::move(zValuesData), Unit{}, |
@@ -276,8 +276,8 void TestDataSeries::testMerge_data() | |||
|
276 | 276 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2"); |
|
277 | 277 | |
|
278 | 278 | // Expected values in the first data series after merge |
|
279 |
QTest::addColumn< |
|
|
280 |
QTest::addColumn< |
|
|
279 | QTest::addColumn<DataContainer>("expectedXAxisData"); | |
|
280 | QTest::addColumn<DataContainer>("expectedValuesData"); | |
|
281 | 281 | |
|
282 | 282 | // ////////// // |
|
283 | 283 | // Test cases // |
@@ -286,26 +286,25 void TestDataSeries::testMerge_data() | |||
|
286 | 286 | QTest::newRow("sortedMerge") |
|
287 | 287 | << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
288 | 288 | << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) |
|
289 |
<< |
|
|
290 |
<< |
|
|
289 | << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
|
290 | << DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; | |
|
291 | 291 | |
|
292 | 292 | QTest::newRow("unsortedMerge") |
|
293 | 293 | << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) |
|
294 | 294 | << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
295 |
<< |
|
|
296 |
<< |
|
|
295 | << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
|
296 | << DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; | |
|
297 | 297 | |
|
298 | QTest::newRow("unsortedMerge2") | |
|
299 |
<< createScalarSeries({1., 2., 8., 9., 10}, {100., 200., |
|
|
300 |
<< createScalarSeries({3., 4., 5., 6., 7.}, {600., 700. |
|
|
301 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
|
302 | << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.}; | |
|
298 | QTest::newRow("unsortedMerge2 (merge not made because source is in the bounds of dest)") | |
|
299 | << createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 800., 900., 1000.}) | |
|
300 | << createScalarSeries({3., 4., 5., 6., 7.}, {300., 400., 500., 600., 700.}) | |
|
301 | << DataContainer{1., 2., 8., 9., 10.} << DataContainer{100., 200., 800., 900., 1000.}; | |
|
303 | 302 | |
|
304 | 303 | QTest::newRow("unsortedMerge3") |
|
305 |
<< createScalarSeries({3., |
|
|
306 |
<< createScalarSeries({ |
|
|
307 |
<< |
|
|
308 | << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.}; | |
|
304 | << createScalarSeries({3., 4., 5., 7., 8}, {300., 400., 500., 700., 800.}) | |
|
305 | << createScalarSeries({1., 2., 3., 7., 10.}, {100., 200., 333., 777., 1000.}) | |
|
306 | << DataContainer{1., 2., 3., 4., 5., 7., 8., 10.} | |
|
307 | << DataContainer{100., 200., 300., 400., 500., 700., 800., 1000.}; | |
|
309 | 308 | } |
|
310 | 309 | |
|
311 | 310 | void TestDataSeries::testMerge() |
@@ -318,8 +317,8 void TestDataSeries::testMerge() | |||
|
318 | 317 | |
|
319 | 318 | // Validates results : we check that the merge is valid and the data series is sorted on its |
|
320 | 319 | // x-axis data |
|
321 |
QFETCH( |
|
|
322 |
QFETCH( |
|
|
320 | QFETCH(DataContainer, expectedXAxisData); | |
|
321 | QFETCH(DataContainer, expectedValuesData); | |
|
323 | 322 | |
|
324 | 323 | validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData); |
|
325 | 324 | } |
@@ -334,24 +333,23 void TestDataSeries::testPurgeScalar_data() | |||
|
334 | 333 | |
|
335 | 334 | QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
336 | 335 | {100., 200., 300., 400., 500.}) |
|
337 |
<< 2. << 4. << |
|
|
338 |
<< |
|
|
336 | << 2. << 4. << DataContainer{2., 3., 4.} | |
|
337 | << std::vector<DataContainer>{{200., 300., 400.}}; | |
|
339 | 338 | QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
340 | 339 | {100., 200., 300., 400., 500.}) |
|
341 |
<< 0. << 2.5 << |
|
|
342 |
<< |
|
|
340 | << 0. << 2.5 << DataContainer{1., 2.} | |
|
341 | << std::vector<DataContainer>{{100., 200.}}; | |
|
343 | 342 | QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
344 | 343 | {100., 200., 300., 400., 500.}) |
|
345 |
<< 3.5 << 7. << |
|
|
346 |
<< |
|
|
344 | << 3.5 << 7. << DataContainer{4., 5.} | |
|
345 | << std::vector<DataContainer>{{400., 500.}}; | |
|
347 | 346 | QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
348 | 347 | {100., 200., 300., 400., 500.}) |
|
349 |
<< 0. << 7. << |
|
|
350 |
<< |
|
|
348 | << 0. << 7. << DataContainer{1., 2., 3., 4., 5.} | |
|
349 | << std::vector<DataContainer>{{100., 200., 300., 400., 500.}}; | |
|
351 | 350 | QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
352 | 351 | {100., 200., 300., 400., 500.}) |
|
353 |
<< 5.5 << 7. << |
|
|
354 | << QVector<QVector<double> >{{}}; | |
|
352 | << 5.5 << 7. << DataContainer{} << std::vector<DataContainer>{{}}; | |
|
355 | 353 | } |
|
356 | 354 | |
|
357 | 355 | void TestDataSeries::testPurgeScalar() |
@@ -370,8 +368,8 void TestDataSeries::testPurgeVector_data() | |||
|
370 | 368 | QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, |
|
371 | 369 | {11., 12., 13., 14., 15.}, |
|
372 | 370 | {16., 17., 18., 19., 20.}) |
|
373 |
<< 2. << 4. << |
|
|
374 |
<< |
|
|
371 | << 2. << 4. << DataContainer{2., 3., 4.} | |
|
372 | << std::vector<DataContainer>{ | |
|
375 | 373 | {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}}; |
|
376 | 374 | } |
|
377 | 375 | |
@@ -512,8 +510,8 void TestDataSeries::testXAxisRange_data() | |||
|
512 | 510 | QTest::addColumn<double>("max"); |
|
513 | 511 | |
|
514 | 512 | // Expected values |
|
515 |
QTest::addColumn< |
|
|
516 |
QTest::addColumn< |
|
|
513 | QTest::addColumn<DataContainer>("expectedXAxisData"); | |
|
514 | QTest::addColumn<DataContainer>("expectedValuesData"); | |
|
517 | 515 | |
|
518 | 516 | // ////////// // |
|
519 | 517 | // Test cases // |
@@ -521,32 +519,32 void TestDataSeries::testXAxisRange_data() | |||
|
521 | 519 | |
|
522 | 520 | QTest::newRow("xAxisRange1") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
523 | 521 | {100., 200., 300., 400., 500.}) |
|
524 |
<< -1. << 3.2 << |
|
|
525 |
<< |
|
|
522 | << -1. << 3.2 << DataContainer{1., 2., 3.} | |
|
523 | << DataContainer{100., 200., 300.}; | |
|
526 | 524 | QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
527 | 525 | {100., 200., 300., 400., 500.}) |
|
528 |
<< 1. << 4. << |
|
|
529 |
<< |
|
|
526 | << 1. << 4. << DataContainer{1., 2., 3., 4.} | |
|
527 | << DataContainer{100., 200., 300., 400.}; | |
|
530 | 528 | QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
531 | 529 | {100., 200., 300., 400., 500.}) |
|
532 |
<< 1. << 3.9 << |
|
|
533 |
<< |
|
|
530 | << 1. << 3.9 << DataContainer{1., 2., 3.} | |
|
531 | << DataContainer{100., 200., 300.}; | |
|
534 | 532 | QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
535 | 533 | {100., 200., 300., 400., 500.}) |
|
536 |
<< 0. << 0.9 << |
|
|
534 | << 0. << 0.9 << DataContainer{} << DataContainer{}; | |
|
537 | 535 | QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
538 | 536 | {100., 200., 300., 400., 500.}) |
|
539 |
<< 0. << 1. << |
|
|
537 | << 0. << 1. << DataContainer{1.} << DataContainer{100.}; | |
|
540 | 538 | QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
541 | 539 | {100., 200., 300., 400., 500.}) |
|
542 |
<< 2.1 << 6. << |
|
|
543 |
<< |
|
|
540 | << 2.1 << 6. << DataContainer{3., 4., 5.} | |
|
541 | << DataContainer{300., 400., 500.}; | |
|
544 | 542 | QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
545 | 543 | {100., 200., 300., 400., 500.}) |
|
546 |
<< 6. << 9. << |
|
|
544 | << 6. << 9. << DataContainer{} << DataContainer{}; | |
|
547 | 545 | QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.}, |
|
548 | 546 | {100., 200., 300., 400., 500.}) |
|
549 |
<< 5. << 9. << |
|
|
547 | << 5. << 9. << DataContainer{5.} << DataContainer{500.}; | |
|
550 | 548 | } |
|
551 | 549 | |
|
552 | 550 | void TestDataSeries::testXAxisRange() |
@@ -555,8 +553,8 void TestDataSeries::testXAxisRange() | |||
|
555 | 553 | QFETCH(double, min); |
|
556 | 554 | QFETCH(double, max); |
|
557 | 555 | |
|
558 |
QFETCH( |
|
|
559 |
QFETCH( |
|
|
556 | QFETCH(DataContainer, expectedXAxisData); | |
|
557 | QFETCH(DataContainer, expectedValuesData); | |
|
560 | 558 | |
|
561 | 559 | auto bounds = dataSeries->xAxisRange(min, max); |
|
562 | 560 | validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData); |
@@ -4,7 +4,9 | |||
|
4 | 4 | |
|
5 | 5 | namespace { |
|
6 | 6 | |
|
7 | void verifyArrayData(const ArrayData<1> &arrayData, const QVector<double> &expectedData) | |
|
7 | using DataContainer = std::vector<double>; | |
|
8 | ||
|
9 | void verifyArrayData(const ArrayData<1> &arrayData, const DataContainer &expectedData) | |
|
8 | 10 | { |
|
9 | 11 | QVERIFY(std::equal( |
|
10 | 12 | arrayData.cbegin(), arrayData.cend(), expectedData.cbegin(), expectedData.cend(), |
@@ -44,18 +46,18 private slots: | |||
|
44 | 46 | void TestOneDimArrayData::testData_data() |
|
45 | 47 | { |
|
46 | 48 | // Test structure |
|
47 |
QTest::addColumn< |
|
|
48 |
QTest::addColumn< |
|
|
49 | QTest::addColumn<DataContainer>("inputData"); // array's data input | |
|
50 | QTest::addColumn<DataContainer>("expectedData"); // expected data | |
|
49 | 51 | |
|
50 | 52 | // Test cases |
|
51 |
QTest::newRow("data1") << |
|
|
52 |
<< |
|
|
53 | QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} | |
|
54 | << DataContainer{1., 2., 3., 4., 5.}; | |
|
53 | 55 | } |
|
54 | 56 | |
|
55 | 57 | void TestOneDimArrayData::testData() |
|
56 | 58 | { |
|
57 |
QFETCH( |
|
|
58 |
QFETCH( |
|
|
59 | QFETCH(DataContainer, inputData); | |
|
60 | QFETCH(DataContainer, expectedData); | |
|
59 | 61 | |
|
60 | 62 | ArrayData<1> arrayData{inputData}; |
|
61 | 63 | verifyArrayData(arrayData, expectedData); |
@@ -64,26 +66,24 void TestOneDimArrayData::testData() | |||
|
64 | 66 | void TestOneDimArrayData::testAdd_data() |
|
65 | 67 | { |
|
66 | 68 | // Test structure |
|
67 |
QTest::addColumn< |
|
|
68 |
QTest::addColumn< |
|
|
69 | QTest::addColumn<DataContainer>("inputData"); // array's data input | |
|
70 | QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with | |
|
69 | 71 |
QTest::addColumn<bool>("prepend"); |
|
70 |
QTest::addColumn< |
|
|
72 | QTest::addColumn<DataContainer>("expectedData"); // expected data after merge | |
|
71 | 73 | |
|
72 | 74 | // Test cases |
|
73 |
QTest::newRow("appendMerge") << |
|
|
74 |
<< |
|
|
75 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.}; | |
|
76 | QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.} | |
|
77 | << QVector<double>{6., 7., 8.} << true | |
|
78 | << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.}; | |
|
75 | QTest::newRow("appendMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.} | |
|
76 | << false << DataContainer{1., 2., 3., 4., 5., 6., 7., 8.}; | |
|
77 | QTest::newRow("prependMerge") << DataContainer{1., 2., 3., 4., 5.} << DataContainer{6., 7., 8.} | |
|
78 | << true << DataContainer{6., 7., 8., 1., 2., 3., 4., 5.}; | |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | void TestOneDimArrayData::testAdd() |
|
82 | 82 | { |
|
83 |
QFETCH( |
|
|
84 |
QFETCH( |
|
|
83 | QFETCH(DataContainer, inputData); | |
|
84 | QFETCH(DataContainer, otherData); | |
|
85 | 85 | QFETCH(bool, prepend); |
|
86 |
QFETCH( |
|
|
86 | QFETCH(DataContainer, expectedData); | |
|
87 | 87 | |
|
88 | 88 | ArrayData<1> arrayData{inputData}; |
|
89 | 89 | ArrayData<1> other{otherData}; |
@@ -95,18 +95,18 void TestOneDimArrayData::testAdd() | |||
|
95 | 95 | void TestOneDimArrayData::testAt_data() |
|
96 | 96 | { |
|
97 | 97 | // Test structure |
|
98 |
QTest::addColumn< |
|
|
98 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |
|
99 | 99 |
QTest::addColumn<int>("index"); |
|
100 | 100 |
QTest::addColumn<double>("expectedData"); |
|
101 | 101 | |
|
102 | 102 | // Test cases |
|
103 |
QTest::newRow("data1") << |
|
|
104 |
QTest::newRow("data2") << |
|
|
103 | QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 0 << 1.; | |
|
104 | QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << 3 << 4.; | |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | void TestOneDimArrayData::testAt() |
|
108 | 108 | { |
|
109 |
QFETCH( |
|
|
109 | QFETCH(DataContainer, inputData); | |
|
110 | 110 | QFETCH(int, index); |
|
111 | 111 | QFETCH(double, expectedData); |
|
112 | 112 | |
@@ -117,34 +117,34 void TestOneDimArrayData::testAt() | |||
|
117 | 117 | void TestOneDimArrayData::testClear_data() |
|
118 | 118 | { |
|
119 | 119 | // Test structure |
|
120 |
QTest::addColumn< |
|
|
120 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |
|
121 | 121 | |
|
122 | 122 | // Test cases |
|
123 |
QTest::newRow("data1") << |
|
|
123 | QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.}; | |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void TestOneDimArrayData::testClear() |
|
127 | 127 | { |
|
128 |
QFETCH( |
|
|
128 | QFETCH(DataContainer, inputData); | |
|
129 | 129 | |
|
130 | 130 | ArrayData<1> arrayData{inputData}; |
|
131 | 131 | arrayData.clear(); |
|
132 |
verifyArrayData(arrayData, |
|
|
132 | verifyArrayData(arrayData, DataContainer{}); | |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | void TestOneDimArrayData::testSize_data() |
|
136 | 136 | { |
|
137 | 137 | // Test structure |
|
138 |
QTest::addColumn< |
|
|
138 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |
|
139 | 139 |
QTest::addColumn<int>("expectedSize"); |
|
140 | 140 | |
|
141 | 141 | // Test cases |
|
142 |
QTest::newRow("data1") << |
|
|
142 | QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << 5; | |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | void TestOneDimArrayData::testSize() |
|
146 | 146 | { |
|
147 |
QFETCH( |
|
|
147 | QFETCH(DataContainer, inputData); | |
|
148 | 148 | QFETCH(int, expectedSize); |
|
149 | 149 | |
|
150 | 150 | ArrayData<1> arrayData{inputData}; |
@@ -154,22 +154,22 void TestOneDimArrayData::testSize() | |||
|
154 | 154 | void TestOneDimArrayData::testSort_data() |
|
155 | 155 | { |
|
156 | 156 | // Test structure |
|
157 |
QTest::addColumn< |
|
|
157 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |
|
158 | 158 | QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data |
|
159 |
QTest::addColumn< |
|
|
159 | QTest::addColumn<DataContainer>("expectedData"); // expected data after sorting | |
|
160 | 160 | |
|
161 | 161 | // Test cases |
|
162 |
QTest::newRow("data1") << |
|
|
163 |
<< |
|
|
164 |
QTest::newRow("data2") << |
|
|
165 |
<< |
|
|
162 | QTest::newRow("data1") << DataContainer{1., 2., 3., 4., 5.} << std::vector<int>{0, 2, 3, 1, 4} | |
|
163 | << DataContainer{1., 3., 4., 2., 5.}; | |
|
164 | QTest::newRow("data2") << DataContainer{1., 2., 3., 4., 5.} << std::vector<int>{4, 1, 2, 3, 0} | |
|
165 | << DataContainer{5., 2., 3., 4., 1.}; | |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void TestOneDimArrayData::testSort() |
|
169 | 169 | { |
|
170 |
QFETCH( |
|
|
170 | QFETCH(DataContainer, inputData); | |
|
171 | 171 | QFETCH(std::vector<int>, sortPermutation); |
|
172 |
QFETCH( |
|
|
172 | QFETCH(DataContainer, expectedData); | |
|
173 | 173 | |
|
174 | 174 | ArrayData<1> arrayData{inputData}; |
|
175 | 175 | auto sortedArrayData = arrayData.sort(sortPermutation); |
@@ -2,31 +2,32 | |||
|
2 | 2 | #include <QObject> |
|
3 | 3 | #include <QtTest> |
|
4 | 4 | |
|
5 |
using Container = |
|
|
6 | using InputData = QPair<QVector<double>, int>; | |
|
5 | using DataContainer = std::vector<double>; | |
|
6 | using Container = std::vector<DataContainer>; | |
|
7 | using InputData = QPair<DataContainer, int>; | |
|
7 | 8 | |
|
8 | 9 | namespace { |
|
9 | 10 | |
|
10 | 11 | InputData flatten(const Container &container) |
|
11 | 12 | { |
|
12 |
if (container. |
|
|
13 | if (container.empty()) { | |
|
13 | 14 | return {}; |
|
14 | 15 | } |
|
15 | 16 | |
|
16 | 17 | // We assume here that each component of the container have the same size |
|
17 | 18 | auto containerSize = container.size(); |
|
18 |
auto componentSize = container.f |
|
|
19 | auto componentSize = container.front().size(); | |
|
19 | 20 | |
|
20 |
auto result = |
|
|
21 | auto result = DataContainer{}; | |
|
21 | 22 | result.reserve(componentSize * containerSize); |
|
22 | 23 | |
|
23 | 24 | for (auto i = 0; i < componentSize; ++i) { |
|
24 | 25 | for (auto j = 0; j < containerSize; ++j) { |
|
25 |
result. |
|
|
26 | result.push_back(container.at(j).at(i)); | |
|
26 | 27 | } |
|
27 | 28 | } |
|
28 | 29 | |
|
29 | return {result, containerSize}; | |
|
30 | return {result, static_cast<int>(containerSize)}; | |
|
30 | 31 | } |
|
31 | 32 | |
|
32 | 33 | void verifyArrayData(const ArrayData<2> &arrayData, const Container &expectedData) |
@@ -175,7 +176,7 void TestTwoDimArrayData::testClear() | |||
|
175 | 176 | ArrayData<2> arrayData{inputData.first, inputData.second}; |
|
176 | 177 | arrayData.clear(); |
|
177 | 178 | |
|
178 |
auto emptyData = Container(inputData.second, |
|
|
179 | auto emptyData = Container(inputData.second, DataContainer{}); | |
|
179 | 180 | verifyArrayData(arrayData, emptyData); |
|
180 | 181 | } |
|
181 | 182 |
General Comments 0
You need to be logged in to leave comments.
Login now