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