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