##// END OF EJS Templates
Unit tests (2): Refactoring...
Alexandre Leroux -
r871:26490bf7ccac
parent child
Show More
@@ -0,0 +1,24
1 #include "DataSeriesUtils.h"
2
3 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData,
4 const DataContainer &valuesData)
5 {
6 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
7 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
8 QVERIFY(std::equal(
9 first, last, valuesData.cbegin(), valuesData.cend(),
10 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
11 }
12
13 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData, const std::vector<DataContainer> &valuesData)
14 {
15 QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
16 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
17 for (auto i = 0; i < valuesData.size(); ++i) {
18 auto componentData = valuesData.at(i);
19
20 QVERIFY(std::equal(
21 first, last, componentData.cbegin(), componentData.cend(),
22 [i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; }));
23 }
24 }
@@ -0,0 +1,373
1 /**
2 * The DataSeriesUtils file contains a set of utility methods that can be used to test the operations on a DataSeries.
3 *
4 * Most of these methods are template methods to adapt to any series (scalars, vectors, spectrograms...)
5 *
6 * @sa DataSeries
7 */
8 #ifndef SCIQLOP_DATASERIESUTILS_H
9 #define SCIQLOP_DATASERIESUTILS_H
10
11 #include <Data/DataSeriesIterator.h>
12 #include <Data/ScalarSeries.h>
13 #include <Data/SpectrogramSeries.h>
14 #include <Data/VectorSeries.h>
15
16 #include <memory>
17 #include <QtTest>
18
19 /// Underlying data in ArrayData
20 using DataContainer = std::vector<double>;
21
22 Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
23 Q_DECLARE_METATYPE(std::shared_ptr<SpectrogramSeries>)
24 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
25
26 /**
27 * Checks that the range of a 1-dim data series contains the expected x-axis data and values data
28 * @param first the iterator on the beginning of the range to check
29 * @param last the iterator on the end of the range to check
30 * @param xData expected x-axis data for the range
31 * @param valuesData expected values data for the range
32 */
33 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData,
34 const DataContainer &valuesData);
35
36 /**
37 * Checks that the range of a 2-dim data series contains the expected x-axis data and values data
38 * @param first the iterator on the beginning of the range to check
39 * @param last the iterator on the end of the range to check
40 * @param xData expected x-axis data for the range
41 * @param valuesData expected values data for the range
42 */
43 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData,
44 const std::vector<DataContainer> &valuesData);
45
46 /**
47 * Sets the structure of unit tests concerning merge of two data series
48 * @tparam DataSeriesType the type of data series to merge
49 * @tparam ExpectedValuesType the type of values expected after merge
50 * @sa testMerge_t()
51 */
52 template <typename DataSeriesType, typename ExpectedValuesType>
53 void testMerge_struct() {
54 // Data series to merge
55 QTest::addColumn<std::shared_ptr<DataSeriesType> >("dataSeries");
56 QTest::addColumn<std::shared_ptr<DataSeriesType> >("dataSeries2");
57
58 // Expected values in the first data series after merge
59 QTest::addColumn<DataContainer>("expectedXAxisData");
60 QTest::addColumn<ExpectedValuesType>("expectedValuesData");
61 }
62
63 /**
64 * Unit test concerning merge of two data series
65 * @sa testMerge_struct()
66 */
67 template <typename DataSeriesType, typename ExpectedValuesType>
68 void testMerge_t(){
69 // Merges series
70 QFETCH(std::shared_ptr<DataSeriesType>, dataSeries);
71 QFETCH(std::shared_ptr<DataSeriesType>, dataSeries2);
72
73 dataSeries->merge(dataSeries2.get());
74
75 // Validates results : we check that the merge is valid
76 QFETCH(DataContainer, expectedXAxisData);
77 QFETCH(ExpectedValuesType, expectedValuesData);
78
79 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
80 }
81
82 /**
83 * Sets the structure of unit tests concerning merge of two data series that are of a different type
84 * @tparam SourceType the type of data series with which to make the merge
85 * @tparam DestType the type of data series in which to make the merge
86 * @sa testMergeDifferentTypes_t()
87 */
88 template <typename SourceType, typename DestType>
89 void testMergeDifferentTypes_struct()
90 {
91 // Data series to merge
92 QTest::addColumn<std::shared_ptr<DestType> >("dest");
93 QTest::addColumn<std::shared_ptr<SourceType> >("source");
94
95 // Expected values in the dest data series after merge
96 QTest::addColumn<DataContainer>("expectedXAxisData");
97 QTest::addColumn<DataContainer>("expectedValuesData");
98 }
99
100 /**
101 * Unit test concerning merge of two data series that are of a different type
102 * @sa testMergeDifferentTypes_struct()
103 */
104 template <typename SourceType, typename DestType>
105 void testMergeDifferentTypes_t()
106 {
107 // Merges series
108 QFETCH(std::shared_ptr<SourceType>, source);
109 QFETCH(std::shared_ptr<DestType>, dest);
110
111 dest->merge(source.get());
112
113 // Validates results : we check that the merge is valid and the data series is sorted on its
114 // x-axis data
115 QFETCH(DataContainer, expectedXAxisData);
116 QFETCH(DataContainer, expectedValuesData);
117
118 validateRange(dest->cbegin(), dest->cend(), expectedXAxisData, expectedValuesData);
119 }
120
121 /**
122 * Sets the structure of unit tests concerning getting the min x-axis data of a data series
123 * @tparam T the type of data series on which to make the operation
124 * @sa testMinXAxisData_t()
125 */
126 template <typename T>
127 void testMinXAxisData_struct(){
128 // Data series to get min data
129 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
130
131 // Min data
132 QTest::addColumn<double>("min");
133
134 // Expected results
135 QTest::addColumn<bool>(
136 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
137 QTest::addColumn<double>(
138 "expectedMin"); // Expected value when method doesn't return end iterator
139 }
140
141 /**
142 * Unit test concerning getting the min x-axis data of a data series
143 * @sa testMinXAxisData_struct()
144 */
145 template <typename T>
146 void testMinXAxisData_t()
147 {
148 QFETCH(std::shared_ptr<T>, dataSeries);
149 QFETCH(double, min);
150
151 QFETCH(bool, expectedOK);
152 QFETCH(double, expectedMin);
153
154 auto it = dataSeries->minXAxisData(min);
155
156 QCOMPARE(expectedOK, it != dataSeries->cend());
157
158 // If the method doesn't return a end iterator, checks with expected value
159 if (expectedOK) {
160 QCOMPARE(expectedMin, it->x());
161 }
162 }
163
164 /**
165 * Sets the structure of unit tests concerning getting the max x-axis data of a data series
166 * @tparam T the type of data series on which to make the operation
167 * @sa testMaxXAxisData_t()
168 */
169 template <typename T>
170 void testMaxXAxisData_struct(){
171 // Data series to get max data
172 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
173
174 // Max data
175 QTest::addColumn<double>("max");
176
177 // Expected results
178 QTest::addColumn<bool>(
179 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
180 QTest::addColumn<double>(
181 "expectedMax"); // Expected value when method doesn't return end iterator
182
183 }
184
185 /**
186 * Unit test concerning getting the max x-axis data of a data series
187 * @sa testMaxXAxisData_struct()
188 */
189 template <typename T>
190 void testMaxXAxisData_t()
191 {
192 QFETCH(std::shared_ptr<T>, dataSeries);
193 QFETCH(double, max);
194
195 QFETCH(bool, expectedOK);
196 QFETCH(double, expectedMax);
197
198 auto it = dataSeries->maxXAxisData(max);
199
200 QCOMPARE(expectedOK, it != dataSeries->cend());
201
202 // If the method doesn't return a end iterator, checks with expected value
203 if (expectedOK) {
204 QCOMPARE(expectedMax, it->x());
205 }
206 }
207
208 /**
209 * Sets the structure of unit tests concerning getting the purge of a data series
210 * @tparam T the type of data series on which to make the operation
211 * @sa testMinXAxisData_t()
212 */
213 template <typename T>
214 void testPurge_struct()
215 {
216 // Data series to purge
217 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
218 QTest::addColumn<double>("min");
219 QTest::addColumn<double>("max");
220
221 // Expected values after purge
222 QTest::addColumn<DataContainer>("expectedXAxisData");
223 QTest::addColumn<std::vector<DataContainer> >("expectedValuesData");
224 }
225
226 /**
227 * Unit test concerning getting the purge of a data series
228 * @sa testPurge_struct()
229 */
230 template <typename T>
231 void testPurge_t(){
232 QFETCH(std::shared_ptr<T>, dataSeries);
233 QFETCH(double, min);
234 QFETCH(double, max);
235
236 dataSeries->purge(min, max);
237
238 // Validates results
239 QFETCH(DataContainer, expectedXAxisData);
240 QFETCH(std::vector<DataContainer>, expectedValuesData);
241
242 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData,
243 expectedValuesData);
244 }
245
246 /**
247 * Sets the structure of unit tests concerning getting subdata of a data series
248 * @tparam DataSeriesType the type of data series on which to make the operation
249 * @tparam ExpectedValuesType the type of values expected after the operation
250 * @sa testSubDataSeries_t()
251 */
252 template <typename DataSeriesType, typename ExpectedValuesType>
253 void testSubDataSeries_struct() {
254 // Data series from which extract the subdata series
255 QTest::addColumn<std::shared_ptr<DataSeriesType> >("dataSeries");
256 // Range to extract
257 QTest::addColumn<SqpRange>("range");
258
259 // Expected values for the subdata series
260 QTest::addColumn<DataContainer>("expectedXAxisData");
261 QTest::addColumn<ExpectedValuesType>("expectedValuesData");
262 }
263
264 /**
265 * Unit test concerning getting subdata of a data series
266 * @sa testSubDataSeries_struct()
267 */
268 template <typename DataSeriesType, typename ExpectedValuesType>
269 void testSubDataSeries_t(){
270 QFETCH(std::shared_ptr<DataSeriesType>, dataSeries);
271 QFETCH(SqpRange, range);
272
273 // Makes the operation
274 auto subDataSeries = std::dynamic_pointer_cast<DataSeriesType>(dataSeries->subDataSeries(range));
275 QVERIFY(subDataSeries != nullptr);
276
277 // Validates results
278 QFETCH(DataContainer, expectedXAxisData);
279 QFETCH(ExpectedValuesType, expectedValuesData);
280
281 validateRange(subDataSeries->cbegin(), subDataSeries->cend(), expectedXAxisData, expectedValuesData);
282 }
283
284 /**
285 * Sets the structure of unit tests concerning getting the range of a data series
286 * @tparam T the type of data series on which to make the operation
287 * @sa testXAxisRange_t()
288 */
289 template <typename T>
290 void testXAxisRange_struct(){
291 // Data series to get x-axis range
292 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
293
294 // Min/max values
295 QTest::addColumn<double>("min");
296 QTest::addColumn<double>("max");
297
298 // Expected values
299 QTest::addColumn<DataContainer>("expectedXAxisData");
300 QTest::addColumn<DataContainer>("expectedValuesData");
301 }
302
303 /**
304 * Unit test concerning getting the range of a data series
305 * @sa testXAxisRange_struct()
306 */
307 template <typename T>
308 void testXAxisRange_t(){
309 QFETCH(std::shared_ptr<T>, dataSeries);
310 QFETCH(double, min);
311 QFETCH(double, max);
312
313 QFETCH(DataContainer, expectedXAxisData);
314 QFETCH(DataContainer, expectedValuesData);
315
316 auto bounds = dataSeries->xAxisRange(min, max);
317 validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData);
318 }
319
320 /**
321 * Sets the structure of unit tests concerning getting values bounds of a data series
322 * @tparam T the type of data series on which to make the operation
323 * @sa testValuesBounds_t()
324 */
325 template <typename T>
326 void testValuesBounds_struct()
327 {
328 // Data series to get values bounds
329 QTest::addColumn<std::shared_ptr<T> >("dataSeries");
330
331 // x-axis range
332 QTest::addColumn<double>("minXAxis");
333 QTest::addColumn<double>("maxXAxis");
334
335 // Expected results
336 QTest::addColumn<bool>(
337 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
338 QTest::addColumn<double>("expectedMinValue");
339 QTest::addColumn<double>("expectedMaxValue");
340 }
341
342 /**
343 * Unit test concerning getting values bounds of a data series
344 * @sa testValuesBounds_struct()
345 */
346 template <typename T>
347 void testValuesBounds_t()
348 {
349 QFETCH(std::shared_ptr<T>, dataSeries);
350 QFETCH(double, minXAxis);
351 QFETCH(double, maxXAxis);
352
353 QFETCH(bool, expectedOK);
354 QFETCH(double, expectedMinValue);
355 QFETCH(double, expectedMaxValue);
356
357 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
358 auto end = dataSeries->cend();
359
360 // Checks iterators with expected result
361 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
362
363 if (expectedOK) {
364 auto compare = [](const auto &v1, const auto &v2) {
365 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
366 };
367
368 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
369 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
370 }
371 }
372
373 #endif // SCIQLOP_DATASERIESUTILS_H
@@ -0,0 +1,426
1 #include "Data/ScalarSeries.h"
2
3 #include "DataSeriesBuilders.h"
4 #include "DataSeriesUtils.h"
5
6 #include <QObject>
7 #include <QtTest>
8
9 /**
10 * @brief The TestScalarSeries class defines unit tests on scalar series.
11 *
12 * Most of these unit tests use generic tests defined for DataSeries (@sa DataSeriesUtils)
13 */
14 class TestScalarSeries : public QObject {
15 Q_OBJECT
16 private slots:
17 /// Tests construction of a scalar series
18 void testCtor_data();
19 void testCtor();
20
21 /// Tests merge of two scalar series
22 void testMerge_data();
23 void testMerge();
24
25 /// Tests merge of a vector series in a scalar series
26 void testMergeWithVector_data();
27 void testMergeWithVector();
28
29 /// Tests get min x-axis data of a scalar series
30 void testMinXAxisData_data();
31 void testMinXAxisData();
32
33 /// Tests get max x-axis data of a scalar series
34 void testMaxXAxisData_data();
35 void testMaxXAxisData();
36
37 /// Tests purge of a scalar series
38 void testPurge_data();
39 void testPurge();
40
41 /// Tests get x-axis range of a scalar series
42 void testXAxisRange_data();
43 void testXAxisRange();
44
45 /// Tests get values bounds of a scalar series
46 void testValuesBounds_data();
47 void testValuesBounds();
48 };
49
50 void TestScalarSeries::testCtor_data()
51 {
52 // x-axis data
53 QTest::addColumn<DataContainer>("xAxisData");
54 // values data
55 QTest::addColumn<DataContainer>("valuesData");
56
57 // construction expected to be valid
58 QTest::addColumn<bool>("expectOK");
59 // expected x-axis data (when construction is valid)
60 QTest::addColumn<DataContainer>("expectedXAxisData");
61 // expected values data (when construction is valid)
62 QTest::addColumn<DataContainer>("expectedValuesData");
63
64 QTest::newRow("invalidData (different sizes of vectors)")
65 << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300.} << false
66 << DataContainer{} << DataContainer{};
67
68 QTest::newRow("sortedData") << DataContainer{1., 2., 3., 4., 5.}
69 << DataContainer{100., 200., 300., 400., 500.} << true
70 << DataContainer{1., 2., 3., 4., 5.}
71 << DataContainer{100., 200., 300., 400., 500.};
72
73 QTest::newRow("unsortedData") << DataContainer{5., 4., 3., 2., 1.}
74 << DataContainer{100., 200., 300., 400., 500.} << true
75 << DataContainer{1., 2., 3., 4., 5.}
76 << DataContainer{500., 400., 300., 200., 100.};
77
78 QTest::newRow("unsortedData2")
79 << DataContainer{1., 4., 3., 5., 2.} << DataContainer{100., 200., 300., 400., 500.} << true
80 << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 500., 300., 200., 400.};
81 }
82
83 void TestScalarSeries::testCtor()
84 {
85 // Creates series
86 QFETCH(DataContainer, xAxisData);
87 QFETCH(DataContainer, valuesData);
88 QFETCH(bool, expectOK);
89
90 if (expectOK) {
91 auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
92 Unit{}, Unit{});
93
94 // Validates results : we check that the data series is sorted on its x-axis data
95 QFETCH(DataContainer, expectedXAxisData);
96 QFETCH(DataContainer, expectedValuesData);
97
98 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData);
99 }
100 else {
101 QVERIFY_EXCEPTION_THROWN(std::make_shared<ScalarSeries>(
102 std::move(xAxisData), std::move(valuesData), Unit{}, Unit{}),
103 std::invalid_argument);
104 }
105 }
106
107 void TestScalarSeries::testMerge_data()
108 {
109 testMerge_struct<ScalarSeries, DataContainer>();
110
111 QTest::newRow("sortedMerge") << ScalarBuilder{}
112 .setX({1., 2., 3., 4., 5.})
113 .setValues({100., 200., 300., 400., 500.})
114 .build()
115 << ScalarBuilder{}
116 .setX({6., 7., 8., 9., 10.})
117 .setValues({600., 700., 800., 900., 1000.})
118 .build()
119 << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
120 << DataContainer{100., 200., 300., 400., 500.,
121 600., 700., 800., 900., 1000.};
122
123 QTest::newRow("unsortedMerge")
124 << ScalarBuilder{}
125 .setX({6., 7., 8., 9., 10.})
126 .setValues({600., 700., 800., 900., 1000.})
127 .build()
128 << ScalarBuilder{}
129 .setX({1., 2., 3., 4., 5.})
130 .setValues({100., 200., 300., 400., 500.})
131 .build()
132 << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
133 << DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
134
135 QTest::newRow("unsortedMerge2 (merge not made because source is in the bounds of dest)")
136 << ScalarBuilder{}
137 .setX({1., 2., 8., 9., 10})
138 .setValues({100., 200., 800., 900., 1000.})
139 .build()
140 << ScalarBuilder{}
141 .setX({3., 4., 5., 6., 7.})
142 .setValues({300., 400., 500., 600., 700.})
143 .build()
144 << DataContainer{1., 2., 8., 9., 10.} << DataContainer{100., 200., 800., 900., 1000.};
145
146 QTest::newRow("unsortedMerge3")
147 << ScalarBuilder{}
148 .setX({3., 4., 5., 7., 8})
149 .setValues({300., 400., 500., 700., 800.})
150 .build()
151 << ScalarBuilder{}
152 .setX({1., 2., 3., 7., 10.})
153 .setValues({100., 200., 333., 777., 1000.})
154 .build()
155 << DataContainer{1., 2., 3., 4., 5., 7., 8., 10.}
156 << DataContainer{100., 200., 300., 400., 500., 700., 800., 1000.};
157
158 QTest::newRow("emptySource") << ScalarBuilder{}
159 .setX({3., 4., 5., 7., 8})
160 .setValues({300., 400., 500., 700., 800.})
161 .build()
162 << ScalarBuilder{}.setX({}).setValues({}).build()
163 << DataContainer{3., 4., 5., 7., 8.}
164 << DataContainer{300., 400., 500., 700., 800.};
165 }
166
167 void TestScalarSeries::testMerge()
168 {
169 testMerge_t<ScalarSeries, DataContainer>();
170 }
171
172 void TestScalarSeries::testMergeWithVector_data()
173 {
174 testMergeDifferentTypes_struct<VectorSeries, ScalarSeries>();
175
176 QTest::newRow("mergeVectorInScalar")
177 << ScalarBuilder{}
178 .setX({1., 2., 3., 4., 5.})
179 .setValues({100., 200., 300., 400., 500.})
180 .build()
181 << VectorBuilder{}
182 .setX({6., 7., 8., 9., 10.})
183 .setXValues({600., 700., 800., 900., 1000.})
184 .setYValues({610., 710., 810., 910., 1010.})
185 .setZValues({620., 720., 820., 920., 1020.})
186 .build()
187 << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300., 400., 500.};
188 }
189
190 void TestScalarSeries::testMergeWithVector()
191 {
192 testMergeDifferentTypes_t<VectorSeries, ScalarSeries>();
193 }
194
195 void TestScalarSeries::testMinXAxisData_data()
196 {
197 testMinXAxisData_struct<ScalarSeries>();
198
199 QTest::newRow("minData1") << ScalarBuilder{}
200 .setX({1., 2., 3., 4., 5.})
201 .setValues({100., 200., 300., 400., 500.})
202 .build()
203 << 0. << true << 1.;
204 QTest::newRow("minData2") << ScalarBuilder{}
205 .setX({1., 2., 3., 4., 5.})
206 .setValues({100., 200., 300., 400., 500.})
207 .build()
208 << 1. << true << 1.;
209 QTest::newRow("minData3") << ScalarBuilder{}
210 .setX({1., 2., 3., 4., 5.})
211 .setValues({100., 200., 300., 400., 500.})
212 .build()
213 << 1.1 << true << 2.;
214 QTest::newRow("minData4") << ScalarBuilder{}
215 .setX({1., 2., 3., 4., 5.})
216 .setValues({100., 200., 300., 400., 500.})
217 .build()
218 << 5. << true << 5.;
219 QTest::newRow("minData5") << ScalarBuilder{}
220 .setX({1., 2., 3., 4., 5.})
221 .setValues({100., 200., 300., 400., 500.})
222 .build()
223 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
224 QTest::newRow("minData6") << ScalarBuilder{}.setX({}).setValues({}).build() << 1.1 << false
225 << std::numeric_limits<double>::quiet_NaN();
226 }
227
228 void TestScalarSeries::testMinXAxisData()
229 {
230 testMinXAxisData_t<ScalarSeries>();
231 }
232
233 void TestScalarSeries::testMaxXAxisData_data()
234 {
235 testMaxXAxisData_struct<ScalarSeries>();
236
237 QTest::newRow("maxData1") << ScalarBuilder{}
238 .setX({1., 2., 3., 4., 5.})
239 .setValues({100., 200., 300., 400., 500.})
240 .build()
241 << 6. << true << 5.;
242 QTest::newRow("maxData2") << ScalarBuilder{}
243 .setX({1., 2., 3., 4., 5.})
244 .setValues({100., 200., 300., 400., 500.})
245 .build()
246 << 5. << true << 5.;
247 QTest::newRow("maxData3") << ScalarBuilder{}
248 .setX({1., 2., 3., 4., 5.})
249 .setValues({100., 200., 300., 400., 500.})
250 .build()
251 << 4.9 << true << 4.;
252 QTest::newRow("maxData4") << ScalarBuilder{}
253 .setX({1., 2., 3., 4., 5.})
254 .setValues({100., 200., 300., 400., 500.})
255 .build()
256 << 1.1 << true << 1.;
257 QTest::newRow("maxData5") << ScalarBuilder{}
258 .setX({1., 2., 3., 4., 5.})
259 .setValues({100., 200., 300., 400., 500.})
260 .build()
261 << 1. << true << 1.;
262 QTest::newRow("maxData6") << ScalarBuilder{}.setX({}).setValues({}).build() << 1.1 << false
263 << std::numeric_limits<double>::quiet_NaN();
264 }
265
266 void TestScalarSeries::testMaxXAxisData()
267 {
268 testMaxXAxisData_t<ScalarSeries>();
269 }
270
271 void TestScalarSeries::testPurge_data()
272 {
273 testPurge_struct<ScalarSeries>();
274
275 QTest::newRow("purgeScalar") << ScalarBuilder{}
276 .setX({1., 2., 3., 4., 5.})
277 .setValues({100., 200., 300., 400., 500.})
278 .build()
279 << 2. << 4. << DataContainer{2., 3., 4.}
280 << std::vector<DataContainer>{{200., 300., 400.}};
281 QTest::newRow("purgeScalar1 (min/max swap)")
282 << ScalarBuilder{}
283 .setX({1., 2., 3., 4., 5.})
284 .setValues({100., 200., 300., 400., 500.})
285 .build()
286 << 4. << 2. << DataContainer{2., 3., 4.} << std::vector<DataContainer>{{200., 300., 400.}};
287 QTest::newRow("purgeScalar2") << ScalarBuilder{}
288 .setX({1., 2., 3., 4., 5.})
289 .setValues({100., 200., 300., 400., 500.})
290 .build()
291 << 0. << 2.5 << DataContainer{1., 2.}
292 << std::vector<DataContainer>{{100., 200.}};
293 QTest::newRow("purgeScalar3") << ScalarBuilder{}
294 .setX({1., 2., 3., 4., 5.})
295 .setValues({100., 200., 300., 400., 500.})
296 .build()
297 << 3.5 << 7. << DataContainer{4., 5.}
298 << std::vector<DataContainer>{{400., 500.}};
299 QTest::newRow("purgeScalar4") << ScalarBuilder{}
300 .setX({1., 2., 3., 4., 5.})
301 .setValues({100., 200., 300., 400., 500.})
302 .build()
303 << 0. << 7. << DataContainer{1., 2., 3., 4., 5.}
304 << std::vector<DataContainer>{{100., 200., 300., 400., 500.}};
305 QTest::newRow("purgeScalar5") << ScalarBuilder{}
306 .setX({1., 2., 3., 4., 5.})
307 .setValues({100., 200., 300., 400., 500.})
308 .build()
309 << 5.5 << 7. << DataContainer{} << std::vector<DataContainer>{{}};
310 }
311
312 void TestScalarSeries::testPurge()
313 {
314 testPurge_t<ScalarSeries>();
315 }
316
317 void TestScalarSeries::testXAxisRange_data()
318 {
319 testXAxisRange_struct<ScalarSeries>();
320
321 QTest::newRow("xAxisRange") << ScalarBuilder{}
322 .setX({1., 2., 3., 4., 5.})
323 .setValues({100., 200., 300., 400., 500.})
324 .build()
325 << -1. << 3.2 << DataContainer{1., 2., 3.}
326 << DataContainer{100., 200., 300.};
327 QTest::newRow("xAxisRange1 (min/max swap)")
328 << ScalarBuilder{}
329 .setX({1., 2., 3., 4., 5.})
330 .setValues({100., 200., 300., 400., 500.})
331 .build()
332 << 3.2 << -1. << DataContainer{1., 2., 3.} << DataContainer{100., 200., 300.};
333 QTest::newRow("xAxisRange2") << ScalarBuilder{}
334 .setX({1., 2., 3., 4., 5.})
335 .setValues({100., 200., 300., 400., 500.})
336 .build()
337 << 1. << 4. << DataContainer{1., 2., 3., 4.}
338 << DataContainer{100., 200., 300., 400.};
339 QTest::newRow("xAxisRange3") << ScalarBuilder{}
340 .setX({1., 2., 3., 4., 5.})
341 .setValues({100., 200., 300., 400., 500.})
342 .build()
343 << 1. << 3.9 << DataContainer{1., 2., 3.}
344 << DataContainer{100., 200., 300.};
345 QTest::newRow("xAxisRange4") << ScalarBuilder{}
346 .setX({1., 2., 3., 4., 5.})
347 .setValues({100., 200., 300., 400., 500.})
348 .build()
349 << 0. << 0.9 << DataContainer{} << DataContainer{};
350 QTest::newRow("xAxisRange5") << ScalarBuilder{}
351 .setX({1., 2., 3., 4., 5.})
352 .setValues({100., 200., 300., 400., 500.})
353 .build()
354 << 0. << 1. << DataContainer{1.} << DataContainer{100.};
355 QTest::newRow("xAxisRange6") << ScalarBuilder{}
356 .setX({1., 2., 3., 4., 5.})
357 .setValues({100., 200., 300., 400., 500.})
358 .build()
359 << 2.1 << 6. << DataContainer{3., 4., 5.}
360 << DataContainer{300., 400., 500.};
361 QTest::newRow("xAxisRange7") << ScalarBuilder{}
362 .setX({1., 2., 3., 4., 5.})
363 .setValues({100., 200., 300., 400., 500.})
364 .build()
365 << 6. << 9. << DataContainer{} << DataContainer{};
366 QTest::newRow("xAxisRange8") << ScalarBuilder{}
367 .setX({1., 2., 3., 4., 5.})
368 .setValues({100., 200., 300., 400., 500.})
369 .build()
370 << 5. << 9. << DataContainer{5.} << DataContainer{500.};
371 }
372
373 void TestScalarSeries::testXAxisRange()
374 {
375 testXAxisRange_t<ScalarSeries>();
376 }
377
378 void TestScalarSeries::testValuesBounds_data()
379 {
380 testValuesBounds_struct<ScalarSeries>();
381
382 auto nan = std::numeric_limits<double>::quiet_NaN();
383
384 QTest::newRow("scalarBounds1") << ScalarBuilder{}
385 .setX({1., 2., 3., 4., 5.})
386 .setValues({100., 200., 300., 400., 500.})
387 .build()
388 << 0. << 6. << true << 100. << 500.;
389 QTest::newRow("scalarBounds2") << ScalarBuilder{}
390 .setX({1., 2., 3., 4., 5.})
391 .setValues({100., 200., 300., 400., 500.})
392 .build()
393 << 2. << 4. << true << 200. << 400.;
394 QTest::newRow("scalarBounds3") << ScalarBuilder{}
395 .setX({1., 2., 3., 4., 5.})
396 .setValues({100., 200., 300., 400., 500.})
397 .build()
398 << 0. << 0.5 << false << nan << nan;
399 QTest::newRow("scalarBounds4") << ScalarBuilder{}
400 .setX({1., 2., 3., 4., 5.})
401 .setValues({100., 200., 300., 400., 500.})
402 .build()
403 << 5.1 << 6. << false << nan << nan;
404 QTest::newRow("scalarBounds5")
405 << ScalarBuilder{}.setX({1.}).setValues({100.}).build() << 0. << 2. << true << 100. << 100.;
406 QTest::newRow("scalarBounds6")
407 << ScalarBuilder{}.setX({}).setValues({}).build() << 0. << 2. << false << nan << nan;
408
409 // Tests with NaN values: NaN values are not included in min/max search
410 QTest::newRow("scalarBounds7") << ScalarBuilder{}
411 .setX({1., 2., 3., 4., 5.})
412 .setValues({nan, 200., 300., 400., nan})
413 .build()
414 << 0. << 6. << true << 200. << 400.;
415 QTest::newRow("scalarBounds8")
416 << ScalarBuilder{}.setX({1., 2., 3., 4., 5.}).setValues({nan, nan, nan, nan, nan}).build()
417 << 0. << 6. << true << nan << nan;
418 }
419
420 void TestScalarSeries::testValuesBounds()
421 {
422 testValuesBounds_t<ScalarSeries>();
423 }
424
425 QTEST_MAIN(TestScalarSeries)
426 #include "TestScalarSeries.moc"
@@ -0,0 +1,90
1 #include "Data/VectorSeries.h"
2
3 #include "DataSeriesBuilders.h"
4 #include "DataSeriesUtils.h"
5
6 #include <QObject>
7 #include <QtTest>
8
9 /**
10 * @brief The TestVectorSeries class defines unit tests on vector series.
11 *
12 * Most of these unit tests use generic tests defined for DataSeries (@sa DataSeriesUtils)
13 */
14 class TestVectorSeries : public QObject {
15 Q_OBJECT
16 private slots:
17 /// Tests purge of a vector series
18 void testPurge_data();
19 void testPurge();
20
21 /// Tests get values bounds of a vector series
22 void testValuesBounds_data();
23 void testValuesBounds();
24 };
25
26 void TestVectorSeries::testPurge_data()
27 {
28 testPurge_struct<VectorSeries>();
29
30 QTest::newRow("purgeVector") << VectorBuilder{}
31 .setX({1., 2., 3., 4., 5.})
32 .setXValues({6., 7., 8., 9., 10.})
33 .setYValues({11., 12., 13., 14., 15.})
34 .setZValues({16., 17., 18., 19., 20.})
35 .build()
36 << 2. << 4. << DataContainer{2., 3., 4.}
37 << std::vector<DataContainer>{
38 {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}};
39 }
40
41 void TestVectorSeries::testPurge()
42 {
43 testPurge_t<VectorSeries>();
44 }
45
46 void TestVectorSeries::testValuesBounds_data()
47 {
48 testValuesBounds_struct<VectorSeries>();
49
50 auto nan = std::numeric_limits<double>::quiet_NaN();
51
52 QTest::newRow("vectorBounds1") << VectorBuilder{}
53 .setX({1., 2., 3., 4., 5.})
54 .setXValues({10., 15., 20., 13., 12.})
55 .setYValues({35., 24., 10., 9., 0.3})
56 .setZValues({13., 14., 12., 9., 24.})
57 .build()
58 << 0. << 6. << true << 0.3 << 35.; // min/max in same component
59 QTest::newRow("vectorBounds2") << VectorBuilder{}
60 .setX({1., 2., 3., 4., 5.})
61 .setXValues({2.3, 15., 20., 13., 12.})
62 .setYValues({35., 24., 10., 9., 4.})
63 .setZValues({13., 14., 12., 9., 24.})
64 .build()
65 << 0. << 6. << true << 2.3 << 35.; // min/max in same entry
66 QTest::newRow("vectorBounds3") << VectorBuilder{}
67 .setX({1., 2., 3., 4., 5.})
68 .setXValues({2.3, 15., 20., 13., 12.})
69 .setYValues({35., 24., 10., 9., 4.})
70 .setZValues({13., 14., 12., 9., 24.})
71 .build()
72 << 2. << 3. << true << 10. << 24.;
73
74 // Tests with NaN values: NaN values are not included in min/max search
75 QTest::newRow("vectorBounds4") << VectorBuilder{}
76 .setX({1., 2.})
77 .setXValues({nan, nan})
78 .setYValues({nan, nan})
79 .setZValues({nan, nan})
80 .build()
81 << 0. << 6. << true << nan << nan;
82 }
83
84 void TestVectorSeries::testValuesBounds()
85 {
86 testValuesBounds_t<VectorSeries>();
87 }
88
89 QTEST_MAIN(TestVectorSeries)
90 #include "TestVectorSeries.moc"
@@ -2,7 +2,8
2
2
3 tests = [
3 tests = [
4 [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'],
4 [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'],
5 [['Data/TestDataSeries.cpp'],'test_data','DataSeries test'],
5 [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'],
6 [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'],
6 [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'],
7 [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'],
7 [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'],
8 [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'],
8 [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'],
9 [['Data/TestTwoDimArrayData.cpp'],'test_2d','Two Dim Array test'],
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (707 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now