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