@@ -24,27 +24,47 QString inputFilePath(const QString &inputFileName) | |||
|
24 | 24 | |
|
25 | 25 | template <typename T> |
|
26 | 26 | struct ExpectedResults { |
|
27 | explicit ExpectedResults() = default; | |
|
28 | 27 | |
|
29 | explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData, | |
|
30 | QVector<double> valuesData) | |
|
31 | : ExpectedResults(xAxisUnit, valuesUnit, xAxisData, | |
|
32 | QVector<QVector<double> >{std::move(valuesData)}) | |
|
28 | ExpectedResults &setParsingOK(bool parsingOK) | |
|
33 | 29 | { |
|
30 | m_ParsingOK = parsingOK; | |
|
31 | return *this; | |
|
34 | 32 | } |
|
35 | 33 | |
|
36 | /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles | |
|
37 | explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData, | |
|
38 | QVector<QVector<double> > valuesData) | |
|
39 | : m_ParsingOK{true}, | |
|
40 | m_XAxisUnit{xAxisUnit}, | |
|
41 | m_ValuesUnit{valuesUnit}, | |
|
42 | m_XAxisData{}, | |
|
43 | m_ValuesData{std::move(valuesData)} | |
|
34 | ExpectedResults &setXAxisUnit(Unit xAxisUnit) | |
|
44 | 35 | { |
|
36 | m_XAxisUnit = std::move(xAxisUnit); | |
|
37 | return *this; | |
|
38 | } | |
|
39 | ||
|
40 | ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData) | |
|
41 | { | |
|
42 | m_XAxisData.clear(); | |
|
43 | ||
|
45 | 44 | // Converts QVector<QDateTime> to QVector<double> |
|
46 | 45 | std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), |
|
47 | 46 | [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); |
|
47 | ||
|
48 | return *this; | |
|
49 | } | |
|
50 | ||
|
51 | ExpectedResults &setValuesUnit(Unit valuesUnit) | |
|
52 | { | |
|
53 | m_ValuesUnit = std::move(valuesUnit); | |
|
54 | return *this; | |
|
55 | } | |
|
56 | ||
|
57 | ExpectedResults &setValuesData(QVector<double> valuesData) | |
|
58 | { | |
|
59 | m_ValuesData.clear(); | |
|
60 | m_ValuesData.push_back(std::move(valuesData)); | |
|
61 | return *this; | |
|
62 | } | |
|
63 | ||
|
64 | ExpectedResults &setValuesData(QVector<QVector<double> > valuesData) | |
|
65 | { | |
|
66 | m_ValuesData = std::move(valuesData); | |
|
67 | return *this; | |
|
48 | 68 | } |
|
49 | 69 | |
|
50 | 70 | /** |
@@ -96,10 +116,10 struct ExpectedResults { | |||
|
96 | 116 | bool m_ParsingOK{false}; |
|
97 | 117 | // Expected x-axis unit |
|
98 | 118 | Unit m_XAxisUnit{}; |
|
99 | // Expected values unit | |
|
100 | Unit m_ValuesUnit{}; | |
|
101 | 119 | // Expected x-axis data |
|
102 | 120 | QVector<double> m_XAxisData{}; |
|
121 | // Expected values unit | |
|
122 | Unit m_ValuesUnit{}; | |
|
103 | 123 | // Expected values data |
|
104 | 124 | QVector<QVector<double> > m_ValuesData{}; |
|
105 | 125 | }; |
@@ -168,77 +188,85 void TestAmdaResultParser::testReadScalarTxt_data() | |||
|
168 | 188 | // Valid files |
|
169 | 189 | QTest::newRow("Valid file") |
|
170 | 190 | << QStringLiteral("ValidScalar1.txt") |
|
171 | << ExpectedResults<ScalarSeries>{ | |
|
172 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
173 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 | QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, | |
|
179 | -2.55800, -2.43250, -2.42200}}; | |
|
191 | << ExpectedResults<ScalarSeries>{} | |
|
192 | .setParsingOK(true) | |
|
193 | .setXAxisUnit(Unit{"nT", true}) | |
|
194 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
195 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), | |
|
196 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), | |
|
197 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), | |
|
198 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}) | |
|
199 | .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, | |
|
200 | -2.55800, -2.43250, -2.42200}); | |
|
180 | 201 | |
|
181 | 202 | QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN") |
|
182 | 203 | << QStringLiteral("WrongValue.txt") |
|
183 | << ExpectedResults<ScalarSeries>{ | |
|
184 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
185 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
186 |
|
|
|
187 | QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}}; | |
|
204 | << ExpectedResults<ScalarSeries>{} | |
|
205 | .setParsingOK(true) | |
|
206 | .setXAxisUnit(Unit{"nT", true}) | |
|
207 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
208 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
209 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); | |
|
188 | 210 | |
|
189 | 211 | QTest::newRow("Valid file that contains NaN values") |
|
190 | 212 | << QStringLiteral("NaNValue.txt") |
|
191 | << ExpectedResults<ScalarSeries>{ | |
|
192 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
193 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
194 |
|
|
|
195 | QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}}; | |
|
213 | << ExpectedResults<ScalarSeries>{} | |
|
214 | .setParsingOK(true) | |
|
215 | .setXAxisUnit(Unit{("nT"), true}) | |
|
216 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
217 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
218 | .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}); | |
|
196 | 219 | |
|
197 | 220 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) |
|
198 |
QTest::newRow("No unit file") |
|
|
199 | << ExpectedResults<ScalarSeries>{Unit{QStringLiteral(""), true}, | |
|
200 | Unit{}, QVector<QDateTime>{}, | |
|
201 | QVector<double>{}}; | |
|
221 | QTest::newRow("No unit file") | |
|
222 | << QStringLiteral("NoUnit.txt") | |
|
223 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true}); | |
|
224 | ||
|
202 | 225 | QTest::newRow("Wrong unit file") |
|
203 | 226 | << QStringLiteral("WrongUnit.txt") |
|
204 |
<< ExpectedResults<ScalarSeries>{ |
|
|
205 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), | |
|
206 | dateTime(2013, 9, 23, 9, 1, 30), | |
|
207 | dateTime(2013, 9, 23, 9, 2, 30)}, | |
|
208 | QVector<double>{-2.83950, -2.71850, -2.52150}}; | |
|
227 | << ExpectedResults<ScalarSeries>{} | |
|
228 | .setParsingOK(true) | |
|
229 | .setXAxisUnit(Unit{"", true}) | |
|
230 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
|
231 | dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
232 | .setValuesData({-2.83950, -2.71850, -2.52150}); | |
|
209 | 233 | |
|
210 | 234 | QTest::newRow("Wrong results file (date of first line is invalid") |
|
211 | 235 | << QStringLiteral("WrongDate.txt") |
|
212 | << ExpectedResults<ScalarSeries>{ | |
|
213 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
214 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
|
215 | QVector<double>{-2.71850, -2.52150}}; | |
|
236 | << ExpectedResults<ScalarSeries>{} | |
|
237 | .setParsingOK(true) | |
|
238 | .setXAxisUnit(Unit{"nT", true}) | |
|
239 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
240 | .setValuesData({-2.71850, -2.52150}); | |
|
216 | 241 | |
|
217 | 242 | QTest::newRow("Wrong results file (too many values for first line") |
|
218 | 243 | << QStringLiteral("TooManyValues.txt") |
|
219 | << ExpectedResults<ScalarSeries>{ | |
|
220 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
221 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
|
222 | QVector<double>{-2.71850, -2.52150}}; | |
|
244 | << ExpectedResults<ScalarSeries>{} | |
|
245 | .setParsingOK(true) | |
|
246 | .setXAxisUnit(Unit{"nT", true}) | |
|
247 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
248 | .setValuesData({-2.71850, -2.52150}); | |
|
223 | 249 | |
|
224 | 250 | QTest::newRow("Wrong results file (x of first line is NaN") |
|
225 | 251 | << QStringLiteral("NaNX.txt") |
|
226 | << ExpectedResults<ScalarSeries>{ | |
|
227 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
228 | QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, | |
|
229 | QVector<double>{-2.71850, -2.52150}}; | |
|
252 | << ExpectedResults<ScalarSeries>{} | |
|
253 | .setParsingOK(true) | |
|
254 | .setXAxisUnit(Unit{"nT", true}) | |
|
255 | .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) | |
|
256 | .setValuesData({-2.71850, -2.52150}); | |
|
230 | 257 | |
|
231 | 258 | QTest::newRow("Invalid file type (vector)") |
|
232 | 259 | << QStringLiteral("ValidVector1.txt") |
|
233 |
<< ExpectedResults<ScalarSeries>{Unit{ |
|
|
234 | QVector<QDateTime>{}, QVector<double>{}}; | |
|
260 | << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true}); | |
|
235 | 261 | |
|
236 | 262 | // Invalid files |
|
237 |
QTest::newRow("Invalid file (unexisting file)") |
|
|
238 | << ExpectedResults<ScalarSeries>{}; | |
|
263 | QTest::newRow("Invalid file (unexisting file)") | |
|
264 | << QStringLiteral("UnexistingFile.txt") | |
|
265 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); | |
|
239 | 266 | |
|
240 |
QTest::newRow("Invalid file (file not found on server)") |
|
|
241 | << ExpectedResults<ScalarSeries>{}; | |
|
267 | QTest::newRow("Invalid file (file not found on server)") | |
|
268 | << QStringLiteral("FileNotFound.txt") | |
|
269 | << ExpectedResults<ScalarSeries>{}.setParsingOK(false); | |
|
242 | 270 | } |
|
243 | 271 | |
|
244 | 272 | void TestAmdaResultParser::testReadScalarTxt() |
@@ -257,24 +285,27 void TestAmdaResultParser::testReadVectorTxt_data() | |||
|
257 | 285 | // Valid files |
|
258 | 286 | QTest::newRow("Valid file") |
|
259 | 287 | << QStringLiteral("ValidVector1.txt") |
|
260 | << ExpectedResults<VectorSeries>{ | |
|
261 | Unit{QStringLiteral("nT"), true}, Unit{}, | |
|
262 | QVector<QDateTime>{dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), | |
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
|
267 | QVector<QVector<double> >{ | |
|
268 | {-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, | |
|
269 | {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, | |
|
270 | {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}}; | |
|
288 | << ExpectedResults<VectorSeries>{} | |
|
289 | .setParsingOK(true) | |
|
290 | .setXAxisUnit(Unit{"nT", true}) | |
|
291 | .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), | |
|
292 | dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), | |
|
293 | dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), | |
|
294 | dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), | |
|
295 | dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}) | |
|
296 | .setValuesData( | |
|
297 | {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, | |
|
298 | {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, | |
|
299 | {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}); | |
|
271 | 300 | |
|
272 | 301 | // Valid files but with some invalid lines (wrong unit, wrong values, etc.) |
|
273 | 302 | QTest::newRow("Invalid file type (scalar)") |
|
274 | 303 | << QStringLiteral("ValidScalar1.txt") |
|
275 |
<< ExpectedResults<VectorSeries>{ |
|
|
276 | QVector<QDateTime>{}, | |
|
277 | QVector<QVector<double> >{{}, {}, {}}}; | |
|
304 | << ExpectedResults<VectorSeries>{} | |
|
305 | .setParsingOK(true) | |
|
306 | .setXAxisUnit(Unit{"nT", true}) | |
|
307 | .setXAxisData({}) | |
|
308 | .setValuesData(QVector<QVector<double> >{{}, {}, {}}); | |
|
278 | 309 | } |
|
279 | 310 | |
|
280 | 311 | void TestAmdaResultParser::testReadVectorTxt() |
General Comments 0
You need to be logged in to leave comments.
Login now