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