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