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