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