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