@@ -1,286 +1,317 | |||||
1 | #include "AmdaResultParser.h" |
|
1 | #include "AmdaResultParser.h" | |
2 |
|
2 | |||
3 | #include <Data/ScalarSeries.h> |
|
3 | #include <Data/ScalarSeries.h> | |
4 | #include <Data/VectorSeries.h> |
|
4 | #include <Data/VectorSeries.h> | |
5 |
|
5 | |||
6 | #include <QObject> |
|
6 | #include <QObject> | |
7 | #include <QtTest> |
|
7 | #include <QtTest> | |
8 |
|
8 | |||
9 | namespace { |
|
9 | namespace { | |
10 |
|
10 | |||
11 | /// Path for the tests |
|
11 | /// Path for the tests | |
12 | const auto TESTS_RESOURCES_PATH |
|
12 | const auto TESTS_RESOURCES_PATH | |
13 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); |
|
13 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath(); | |
14 |
|
14 | |||
15 | QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds) |
|
15 | QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds) | |
16 | { |
|
16 | { | |
17 | return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}; |
|
17 | return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}; | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | QString inputFilePath(const QString &inputFileName) |
|
20 | QString inputFilePath(const QString &inputFileName) | |
21 | { |
|
21 | { | |
22 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); |
|
22 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); | |
23 | } |
|
23 | } | |
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 | /** | |
51 | * Validates a DataSeries compared to the expected results |
|
71 | * Validates a DataSeries compared to the expected results | |
52 | * @param results the DataSeries to validate |
|
72 | * @param results the DataSeries to validate | |
53 | */ |
|
73 | */ | |
54 | void validate(std::shared_ptr<IDataSeries> results) |
|
74 | void validate(std::shared_ptr<IDataSeries> results) | |
55 | { |
|
75 | { | |
56 | if (m_ParsingOK) { |
|
76 | if (m_ParsingOK) { | |
57 | auto dataSeries = dynamic_cast<T *>(results.get()); |
|
77 | auto dataSeries = dynamic_cast<T *>(results.get()); | |
58 | if (dataSeries == nullptr) { |
|
78 | if (dataSeries == nullptr) { | |
59 |
|
79 | |||
60 | // No unit detected, parsink ok but data is nullptr |
|
80 | // No unit detected, parsink ok but data is nullptr | |
61 | // TODO, improve the test to verify that the data is null |
|
81 | // TODO, improve the test to verify that the data is null | |
62 | return; |
|
82 | return; | |
63 | } |
|
83 | } | |
64 |
|
84 | |||
65 | // Checks units |
|
85 | // Checks units | |
66 | QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit); |
|
86 | QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit); | |
67 | QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit); |
|
87 | QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit); | |
68 |
|
88 | |||
69 | auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) { |
|
89 | auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) { | |
70 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(), |
|
90 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(), | |
71 | expectedData.cend(), |
|
91 | expectedData.cend(), | |
72 | [&equalFun](const auto &dataSeriesIt, const auto &expectedX) { |
|
92 | [&equalFun](const auto &dataSeriesIt, const auto &expectedX) { | |
73 | return equalFun(dataSeriesIt, expectedX); |
|
93 | return equalFun(dataSeriesIt, expectedX); | |
74 | })); |
|
94 | })); | |
75 | }; |
|
95 | }; | |
76 |
|
96 | |||
77 | // Checks x-axis data |
|
97 | // Checks x-axis data | |
78 | verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) { |
|
98 | verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) { | |
79 | return seriesIt.x() == value; |
|
99 | return seriesIt.x() == value; | |
80 | }); |
|
100 | }); | |
81 |
|
101 | |||
82 | // Checks values data of each component |
|
102 | // Checks values data of each component | |
83 | for (auto i = 0; i < m_ValuesData.size(); ++i) { |
|
103 | for (auto i = 0; i < m_ValuesData.size(); ++i) { | |
84 | verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) { |
|
104 | verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) { | |
85 | auto itValue = seriesIt.value(i); |
|
105 | auto itValue = seriesIt.value(i); | |
86 | return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; |
|
106 | return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; | |
87 | }); |
|
107 | }); | |
88 | } |
|
108 | } | |
89 | } |
|
109 | } | |
90 | else { |
|
110 | else { | |
91 | QVERIFY(results == nullptr); |
|
111 | QVERIFY(results == nullptr); | |
92 | } |
|
112 | } | |
93 | } |
|
113 | } | |
94 |
|
114 | |||
95 | // Parsing was successfully completed |
|
115 | // Parsing was successfully completed | |
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 | }; | |
106 |
|
126 | |||
107 | } // namespace |
|
127 | } // namespace | |
108 |
|
128 | |||
109 | Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>) |
|
129 | Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>) | |
110 | Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>) |
|
130 | Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>) | |
111 |
|
131 | |||
112 | class TestAmdaResultParser : public QObject { |
|
132 | class TestAmdaResultParser : public QObject { | |
113 | Q_OBJECT |
|
133 | Q_OBJECT | |
114 | private: |
|
134 | private: | |
115 | template <typename T> |
|
135 | template <typename T> | |
116 | void testReadDataStructure() |
|
136 | void testReadDataStructure() | |
117 | { |
|
137 | { | |
118 | // ////////////// // |
|
138 | // ////////////// // | |
119 | // Test structure // |
|
139 | // Test structure // | |
120 | // ////////////// // |
|
140 | // ////////////// // | |
121 |
|
141 | |||
122 | // Name of TXT file to read |
|
142 | // Name of TXT file to read | |
123 | QTest::addColumn<QString>("inputFileName"); |
|
143 | QTest::addColumn<QString>("inputFileName"); | |
124 | // Expected results |
|
144 | // Expected results | |
125 | QTest::addColumn<ExpectedResults<T> >("expectedResults"); |
|
145 | QTest::addColumn<ExpectedResults<T> >("expectedResults"); | |
126 | } |
|
146 | } | |
127 |
|
147 | |||
128 | template <typename T> |
|
148 | template <typename T> | |
129 | void testRead(AmdaResultParser::ValueType valueType) |
|
149 | void testRead(AmdaResultParser::ValueType valueType) | |
130 | { |
|
150 | { | |
131 | QFETCH(QString, inputFileName); |
|
151 | QFETCH(QString, inputFileName); | |
132 | QFETCH(ExpectedResults<T>, expectedResults); |
|
152 | QFETCH(ExpectedResults<T>, expectedResults); | |
133 |
|
153 | |||
134 | // Parses file |
|
154 | // Parses file | |
135 | auto filePath = inputFilePath(inputFileName); |
|
155 | auto filePath = inputFilePath(inputFileName); | |
136 | auto results = AmdaResultParser::readTxt(filePath, valueType); |
|
156 | auto results = AmdaResultParser::readTxt(filePath, valueType); | |
137 |
|
157 | |||
138 | // ///////////////// // |
|
158 | // ///////////////// // | |
139 | // Validates results // |
|
159 | // Validates results // | |
140 | // ///////////////// // |
|
160 | // ///////////////// // | |
141 | expectedResults.validate(results); |
|
161 | expectedResults.validate(results); | |
142 | } |
|
162 | } | |
143 |
|
163 | |||
144 | private slots: |
|
164 | private slots: | |
145 | /// Input test data |
|
165 | /// Input test data | |
146 | /// @sa testReadScalarTxt() |
|
166 | /// @sa testReadScalarTxt() | |
147 | void testReadScalarTxt_data(); |
|
167 | void testReadScalarTxt_data(); | |
148 |
|
168 | |||
149 | /// Tests parsing scalar series of a TXT file |
|
169 | /// Tests parsing scalar series of a TXT file | |
150 | void testReadScalarTxt(); |
|
170 | void testReadScalarTxt(); | |
151 |
|
171 | |||
152 | /// Input test data |
|
172 | /// Input test data | |
153 | /// @sa testReadVectorTxt() |
|
173 | /// @sa testReadVectorTxt() | |
154 | void testReadVectorTxt_data(); |
|
174 | void testReadVectorTxt_data(); | |
155 |
|
175 | |||
156 | /// Tests parsing vector series of a TXT file |
|
176 | /// Tests parsing vector series of a TXT file | |
157 | void testReadVectorTxt(); |
|
177 | void testReadVectorTxt(); | |
158 | }; |
|
178 | }; | |
159 |
|
179 | |||
160 | void TestAmdaResultParser::testReadScalarTxt_data() |
|
180 | void TestAmdaResultParser::testReadScalarTxt_data() | |
161 | { |
|
181 | { | |
162 | testReadDataStructure<ScalarSeries>(); |
|
182 | testReadDataStructure<ScalarSeries>(); | |
163 |
|
183 | |||
164 | // ////////// // |
|
184 | // ////////// // | |
165 | // Test cases // |
|
185 | // Test cases // | |
166 | // ////////// // |
|
186 | // ////////// // | |
167 |
|
187 | |||
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}) | |
174 |
|
|
194 | .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), | |
175 |
|
|
195 | dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), | |
176 |
|
|
196 | dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), | |
177 |
|
|
197 | dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), | |
178 | QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, |
|
198 | dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}) | |
179 | -2.55800, -2.43250, -2.42200}}; |
|
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 | 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() | |
245 | { |
|
273 | { | |
246 | testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR); |
|
274 | testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR); | |
247 | } |
|
275 | } | |
248 |
|
276 | |||
249 | void TestAmdaResultParser::testReadVectorTxt_data() |
|
277 | void TestAmdaResultParser::testReadVectorTxt_data() | |
250 | { |
|
278 | { | |
251 | testReadDataStructure<VectorSeries>(); |
|
279 | testReadDataStructure<VectorSeries>(); | |
252 |
|
280 | |||
253 | // ////////// // |
|
281 | // ////////// // | |
254 | // Test cases // |
|
282 | // Test cases // | |
255 | // ////////// // |
|
283 | // ////////// // | |
256 |
|
284 | |||
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}) | |
263 |
|
|
291 | .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), | |
264 |
|
|
292 | dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), | |
265 |
|
|
293 | dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), | |
266 |
|
|
294 | dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), | |
267 | QVector<QVector<double> >{ |
|
295 | dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}) | |
268 | {-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, |
|
296 | .setValuesData( | |
269 | {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, |
|
297 | {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, | |
270 | {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}}; |
|
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 | // 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() | |
281 | { |
|
312 | { | |
282 | testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR); |
|
313 | testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR); | |
283 | } |
|
314 | } | |
284 |
|
315 | |||
285 | QTEST_MAIN(TestAmdaResultParser) |
|
316 | QTEST_MAIN(TestAmdaResultParser) | |
286 | #include "TestAmdaResultParser.moc" |
|
317 | #include "TestAmdaResultParser.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now