##// END OF EJS Templates
Inits unit tests for spectrograms
Alexandre Leroux -
r946:329fd53c53b6
parent child
Show More
@@ -1,357 +1,381
1 #include "AmdaResultParser.h"
1 #include "AmdaResultParser.h"
2
2
3 #include <Data/ScalarSeries.h>
3 #include <Data/ScalarSeries.h>
4 #include <Data/SpectrogramSeries.h>
4 #include <Data/VectorSeries.h>
5 #include <Data/VectorSeries.h>
5
6
6 #include <QObject>
7 #include <QObject>
7 #include <QtTest>
8 #include <QtTest>
8
9
9 namespace {
10 namespace {
10
11
11 /// Path for the tests
12 /// Path for the tests
12 const auto TESTS_RESOURCES_PATH
13 const auto TESTS_RESOURCES_PATH
13 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
14
15
15 QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds)
16 QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds)
16 {
17 {
17 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
18 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
18 }
19 }
19
20
20 QString inputFilePath(const QString &inputFileName)
21 QString inputFilePath(const QString &inputFileName)
21 {
22 {
22 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
23 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
23 }
24 }
24
25
25 template <typename T>
26 template <typename T>
26 struct ExpectedResults {
27 struct ExpectedResults {
27
28
28 ExpectedResults &setParsingOK(bool parsingOK)
29 ExpectedResults &setParsingOK(bool parsingOK)
29 {
30 {
30 m_ParsingOK = parsingOK;
31 m_ParsingOK = parsingOK;
31 return *this;
32 return *this;
32 }
33 }
33
34
34 ExpectedResults &setXAxisUnit(Unit xAxisUnit)
35 ExpectedResults &setXAxisUnit(Unit xAxisUnit)
35 {
36 {
36 m_XAxisUnit = std::move(xAxisUnit);
37 m_XAxisUnit = std::move(xAxisUnit);
37 return *this;
38 return *this;
38 }
39 }
39
40
40 ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData)
41 ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData)
41 {
42 {
42 m_XAxisData.clear();
43 m_XAxisData.clear();
43
44
44 // Converts QVector<QDateTime> to QVector<double>
45 // Converts QVector<QDateTime> to QVector<double>
45 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
46 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
46 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
47 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
47
48
48 return *this;
49 return *this;
49 }
50 }
50
51
51 ExpectedResults &setValuesUnit(Unit valuesUnit)
52 ExpectedResults &setValuesUnit(Unit valuesUnit)
52 {
53 {
53 m_ValuesUnit = std::move(valuesUnit);
54 m_ValuesUnit = std::move(valuesUnit);
54 return *this;
55 return *this;
55 }
56 }
56
57
57 ExpectedResults &setValuesData(QVector<double> valuesData)
58 ExpectedResults &setValuesData(QVector<double> valuesData)
58 {
59 {
59 m_ValuesData.clear();
60 m_ValuesData.clear();
60 m_ValuesData.push_back(std::move(valuesData));
61 m_ValuesData.push_back(std::move(valuesData));
61 return *this;
62 return *this;
62 }
63 }
63
64
64 ExpectedResults &setValuesData(QVector<QVector<double> > valuesData)
65 ExpectedResults &setValuesData(QVector<QVector<double> > valuesData)
65 {
66 {
66 m_ValuesData = std::move(valuesData);
67 m_ValuesData = std::move(valuesData);
67 return *this;
68 return *this;
68 }
69 }
69
70
70 ExpectedResults &setYAxisEnabled(bool yAxisEnabled)
71 ExpectedResults &setYAxisEnabled(bool yAxisEnabled)
71 {
72 {
72 m_YAxisEnabled = yAxisEnabled;
73 m_YAxisEnabled = yAxisEnabled;
73 return *this;
74 return *this;
74 }
75 }
75
76
76 ExpectedResults &setYAxisUnit(Unit yAxisUnit)
77 ExpectedResults &setYAxisUnit(Unit yAxisUnit)
77 {
78 {
78 m_YAxisUnit = std::move(yAxisUnit);
79 m_YAxisUnit = std::move(yAxisUnit);
79 return *this;
80 return *this;
80 }
81 }
81
82
82 ExpectedResults &setYAxisData(QVector<double> yAxisData)
83 ExpectedResults &setYAxisData(QVector<double> yAxisData)
83 {
84 {
84 m_YAxisData = std::move(yAxisData);
85 m_YAxisData = std::move(yAxisData);
85 return *this;
86 return *this;
86 }
87 }
87
88
88 /**
89 /**
89 * Validates a DataSeries compared to the expected results
90 * Validates a DataSeries compared to the expected results
90 * @param results the DataSeries to validate
91 * @param results the DataSeries to validate
91 */
92 */
92 void validate(std::shared_ptr<IDataSeries> results)
93 void validate(std::shared_ptr<IDataSeries> results)
93 {
94 {
94 if (m_ParsingOK) {
95 if (m_ParsingOK) {
95 auto dataSeries = dynamic_cast<T *>(results.get());
96 auto dataSeries = dynamic_cast<T *>(results.get());
96 if (dataSeries == nullptr) {
97 if (dataSeries == nullptr) {
97
98
98 // No unit detected, parsink ok but data is nullptr
99 // No unit detected, parsink ok but data is nullptr
99 // TODO, improve the test to verify that the data is null
100 // TODO, improve the test to verify that the data is null
100 return;
101 return;
101 }
102 }
102
103
103 // Checks units
104 // Checks units
104 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
105 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
105 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
106 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
106
107
107 auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) {
108 auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) {
108 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(),
109 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(),
109 expectedData.cend(),
110 expectedData.cend(),
110 [&equalFun](const auto &dataSeriesIt, const auto &expectedX) {
111 [&equalFun](const auto &dataSeriesIt, const auto &expectedX) {
111 return equalFun(dataSeriesIt, expectedX);
112 return equalFun(dataSeriesIt, expectedX);
112 }));
113 }));
113 };
114 };
114
115
115 // Checks x-axis data
116 // Checks x-axis data
116 verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) {
117 verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) {
117 return seriesIt.x() == value;
118 return seriesIt.x() == value;
118 });
119 });
119
120
120 // Checks values data of each component
121 // Checks values data of each component
121 for (auto i = 0; i < m_ValuesData.size(); ++i) {
122 for (auto i = 0; i < m_ValuesData.size(); ++i) {
122 verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) {
123 verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) {
123 auto itValue = seriesIt.value(i);
124 auto itValue = seriesIt.value(i);
124 return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value;
125 return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value;
125 });
126 });
126 }
127 }
127
128
128 // Checks y-axis (if defined)
129 // Checks y-axis (if defined)
129 auto yAxis = dataSeries->yAxis();
130 auto yAxis = dataSeries->yAxis();
130 QCOMPARE(yAxis.isDefined(), m_YAxisEnabled);
131 QCOMPARE(yAxis.isDefined(), m_YAxisEnabled);
131
132
132 if (m_YAxisEnabled) {
133 if (m_YAxisEnabled) {
133 // Unit
134 // Unit
134 QCOMPARE(yAxis.unit(), m_YAxisUnit);
135 QCOMPARE(yAxis.unit(), m_YAxisUnit);
135
136
136 // Data
137 // Data
137 auto yAxisSize = yAxis.size();
138 auto yAxisSize = yAxis.size();
138 QCOMPARE(yAxisSize, m_YAxisData.size());
139 QCOMPARE(yAxisSize, m_YAxisData.size());
139 for (auto i = 0; i < yAxisSize; ++i) {
140 for (auto i = 0; i < yAxisSize; ++i) {
140 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
141 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
141 }
142 }
142 }
143 }
143 }
144 }
144 else {
145 else {
145 QVERIFY(results == nullptr);
146 QVERIFY(results == nullptr);
146 }
147 }
147 }
148 }
148
149
149 // Parsing was successfully completed
150 // Parsing was successfully completed
150 bool m_ParsingOK{false};
151 bool m_ParsingOK{false};
151 // Expected x-axis unit
152 // Expected x-axis unit
152 Unit m_XAxisUnit{};
153 Unit m_XAxisUnit{};
153 // Expected x-axis data
154 // Expected x-axis data
154 QVector<double> m_XAxisData{};
155 QVector<double> m_XAxisData{};
155 // Expected values unit
156 // Expected values unit
156 Unit m_ValuesUnit{};
157 Unit m_ValuesUnit{};
157 // Expected values data
158 // Expected values data
158 QVector<QVector<double> > m_ValuesData{};
159 QVector<QVector<double> > m_ValuesData{};
159 // Expected data series has y-axis
160 // Expected data series has y-axis
160 bool m_YAxisEnabled{false};
161 bool m_YAxisEnabled{false};
161 // Expected y-axis unit (if axis defined)
162 // Expected y-axis unit (if axis defined)
162 Unit m_YAxisUnit{};
163 Unit m_YAxisUnit{};
163 // Expected y-axis data (if axis defined)
164 // Expected y-axis data (if axis defined)
164 QVector<double> m_YAxisData{};
165 QVector<double> m_YAxisData{};
165 };
166 };
166
167
167 } // namespace
168 } // namespace
168
169
169 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
170 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
171 Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>)
170 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
172 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
171
173
172 class TestAmdaResultParser : public QObject {
174 class TestAmdaResultParser : public QObject {
173 Q_OBJECT
175 Q_OBJECT
174 private:
176 private:
175 template <typename T>
177 template <typename T>
176 void testReadDataStructure()
178 void testReadDataStructure()
177 {
179 {
178 // ////////////// //
180 // ////////////// //
179 // Test structure //
181 // Test structure //
180 // ////////////// //
182 // ////////////// //
181
183
182 // Name of TXT file to read
184 // Name of TXT file to read
183 QTest::addColumn<QString>("inputFileName");
185 QTest::addColumn<QString>("inputFileName");
184 // Expected results
186 // Expected results
185 QTest::addColumn<ExpectedResults<T> >("expectedResults");
187 QTest::addColumn<ExpectedResults<T> >("expectedResults");
186 }
188 }
187
189
188 template <typename T>
190 template <typename T>
189 void testRead(AmdaResultParser::ValueType valueType)
191 void testRead(AmdaResultParser::ValueType valueType)
190 {
192 {
191 QFETCH(QString, inputFileName);
193 QFETCH(QString, inputFileName);
192 QFETCH(ExpectedResults<T>, expectedResults);
194 QFETCH(ExpectedResults<T>, expectedResults);
193
195
194 // Parses file
196 // Parses file
195 auto filePath = inputFilePath(inputFileName);
197 auto filePath = inputFilePath(inputFileName);
196 auto results = AmdaResultParser::readTxt(filePath, valueType);
198 auto results = AmdaResultParser::readTxt(filePath, valueType);
197
199
198 // ///////////////// //
200 // ///////////////// //
199 // Validates results //
201 // Validates results //
200 // ///////////////// //
202 // ///////////////// //
201 expectedResults.validate(results);
203 expectedResults.validate(results);
202 }
204 }
203
205
204 private slots:
206 private slots:
205 /// Input test data
207 /// Input test data
206 /// @sa testReadScalarTxt()
208 /// @sa testReadScalarTxt()
207 void testReadScalarTxt_data();
209 void testReadScalarTxt_data();
208
210
209 /// Tests parsing scalar series of a TXT file
211 /// Tests parsing scalar series of a TXT file
210 void testReadScalarTxt();
212 void testReadScalarTxt();
211
213
212 /// Input test data
214 /// Input test data
215 /// @sa testReadSpectrogramTxt()
216 void testReadSpectrogramTxt_data();
217
218 /// Tests parsing spectrogram series of a TXT file
219 void testReadSpectrogramTxt();
220
221 /// Input test data
213 /// @sa testReadVectorTxt()
222 /// @sa testReadVectorTxt()
214 void testReadVectorTxt_data();
223 void testReadVectorTxt_data();
215
224
216 /// Tests parsing vector series of a TXT file
225 /// Tests parsing vector series of a TXT file
217 void testReadVectorTxt();
226 void testReadVectorTxt();
218 };
227 };
219
228
220 void TestAmdaResultParser::testReadScalarTxt_data()
229 void TestAmdaResultParser::testReadScalarTxt_data()
221 {
230 {
222 testReadDataStructure<ScalarSeries>();
231 testReadDataStructure<ScalarSeries>();
223
232
224 // ////////// //
233 // ////////// //
225 // Test cases //
234 // Test cases //
226 // ////////// //
235 // ////////// //
227
236
228 // Valid files
237 // Valid files
229 QTest::newRow("Valid file")
238 QTest::newRow("Valid file")
230 << QStringLiteral("ValidScalar1.txt")
239 << QStringLiteral("ValidScalar1.txt")
231 << ExpectedResults<ScalarSeries>{}
240 << ExpectedResults<ScalarSeries>{}
232 .setParsingOK(true)
241 .setParsingOK(true)
233 .setXAxisUnit(Unit{"nT", true})
242 .setXAxisUnit(Unit{"nT", true})
234 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
243 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
235 dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30),
244 dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30),
236 dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30),
245 dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30),
237 dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30),
246 dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30),
238 dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)})
247 dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)})
239 .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
248 .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
240 -2.55800, -2.43250, -2.42200});
249 -2.55800, -2.43250, -2.42200});
241
250
242 QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN")
251 QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN")
243 << QStringLiteral("WrongValue.txt")
252 << QStringLiteral("WrongValue.txt")
244 << ExpectedResults<ScalarSeries>{}
253 << ExpectedResults<ScalarSeries>{}
245 .setParsingOK(true)
254 .setParsingOK(true)
246 .setXAxisUnit(Unit{"nT", true})
255 .setXAxisUnit(Unit{"nT", true})
247 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
256 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
248 dateTime(2013, 9, 23, 9, 2, 30)})
257 dateTime(2013, 9, 23, 9, 2, 30)})
249 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
258 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
250
259
251 QTest::newRow("Valid file that contains NaN values")
260 QTest::newRow("Valid file that contains NaN values")
252 << QStringLiteral("NaNValue.txt")
261 << QStringLiteral("NaNValue.txt")
253 << ExpectedResults<ScalarSeries>{}
262 << ExpectedResults<ScalarSeries>{}
254 .setParsingOK(true)
263 .setParsingOK(true)
255 .setXAxisUnit(Unit{("nT"), true})
264 .setXAxisUnit(Unit{("nT"), true})
256 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
265 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
257 dateTime(2013, 9, 23, 9, 2, 30)})
266 dateTime(2013, 9, 23, 9, 2, 30)})
258 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
267 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
259
268
260 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
269 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
261 QTest::newRow("No unit file")
270 QTest::newRow("No unit file")
262 << QStringLiteral("NoUnit.txt")
271 << QStringLiteral("NoUnit.txt")
263 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true});
272 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true});
264
273
265 QTest::newRow("Wrong unit file")
274 QTest::newRow("Wrong unit file")
266 << QStringLiteral("WrongUnit.txt")
275 << QStringLiteral("WrongUnit.txt")
267 << ExpectedResults<ScalarSeries>{}
276 << ExpectedResults<ScalarSeries>{}
268 .setParsingOK(true)
277 .setParsingOK(true)
269 .setXAxisUnit(Unit{"", true})
278 .setXAxisUnit(Unit{"", true})
270 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
279 .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
271 dateTime(2013, 9, 23, 9, 2, 30)})
280 dateTime(2013, 9, 23, 9, 2, 30)})
272 .setValuesData({-2.83950, -2.71850, -2.52150});
281 .setValuesData({-2.83950, -2.71850, -2.52150});
273
282
274 QTest::newRow("Wrong results file (date of first line is invalid")
283 QTest::newRow("Wrong results file (date of first line is invalid")
275 << QStringLiteral("WrongDate.txt")
284 << QStringLiteral("WrongDate.txt")
276 << ExpectedResults<ScalarSeries>{}
285 << ExpectedResults<ScalarSeries>{}
277 .setParsingOK(true)
286 .setParsingOK(true)
278 .setXAxisUnit(Unit{"nT", true})
287 .setXAxisUnit(Unit{"nT", true})
279 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
288 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
280 .setValuesData({-2.71850, -2.52150});
289 .setValuesData({-2.71850, -2.52150});
281
290
282 QTest::newRow("Wrong results file (too many values for first line")
291 QTest::newRow("Wrong results file (too many values for first line")
283 << QStringLiteral("TooManyValues.txt")
292 << QStringLiteral("TooManyValues.txt")
284 << ExpectedResults<ScalarSeries>{}
293 << ExpectedResults<ScalarSeries>{}
285 .setParsingOK(true)
294 .setParsingOK(true)
286 .setXAxisUnit(Unit{"nT", true})
295 .setXAxisUnit(Unit{"nT", true})
287 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
296 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
288 .setValuesData({-2.71850, -2.52150});
297 .setValuesData({-2.71850, -2.52150});
289
298
290 QTest::newRow("Wrong results file (x of first line is NaN")
299 QTest::newRow("Wrong results file (x of first line is NaN")
291 << QStringLiteral("NaNX.txt")
300 << QStringLiteral("NaNX.txt")
292 << ExpectedResults<ScalarSeries>{}
301 << ExpectedResults<ScalarSeries>{}
293 .setParsingOK(true)
302 .setParsingOK(true)
294 .setXAxisUnit(Unit{"nT", true})
303 .setXAxisUnit(Unit{"nT", true})
295 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
304 .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)})
296 .setValuesData({-2.71850, -2.52150});
305 .setValuesData({-2.71850, -2.52150});
297
306
298 QTest::newRow("Invalid file type (vector)")
307 QTest::newRow("Invalid file type (vector)")
299 << QStringLiteral("ValidVector1.txt")
308 << QStringLiteral("ValidVector1.txt")
300 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true});
309 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true});
301
310
302 // Invalid files
311 // Invalid files
303 QTest::newRow("Invalid file (unexisting file)")
312 QTest::newRow("Invalid file (unexisting file)")
304 << QStringLiteral("UnexistingFile.txt")
313 << QStringLiteral("UnexistingFile.txt")
305 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
314 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
306
315
307 QTest::newRow("Invalid file (file not found on server)")
316 QTest::newRow("Invalid file (file not found on server)")
308 << QStringLiteral("FileNotFound.txt")
317 << QStringLiteral("FileNotFound.txt")
309 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
318 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
310 }
319 }
311
320
312 void TestAmdaResultParser::testReadScalarTxt()
321 void TestAmdaResultParser::testReadScalarTxt()
313 {
322 {
314 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
323 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
315 }
324 }
316
325
326 void TestAmdaResultParser::testReadSpectrogramTxt_data()
327 {
328 testReadDataStructure<SpectrogramSeries>();
329
330 // ////////// //
331 // Test cases //
332 // ////////// //
333
334 }
335
336 void TestAmdaResultParser::testReadSpectrogramTxt()
337 {
338 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
339 }
340
317 void TestAmdaResultParser::testReadVectorTxt_data()
341 void TestAmdaResultParser::testReadVectorTxt_data()
318 {
342 {
319 testReadDataStructure<VectorSeries>();
343 testReadDataStructure<VectorSeries>();
320
344
321 // ////////// //
345 // ////////// //
322 // Test cases //
346 // Test cases //
323 // ////////// //
347 // ////////// //
324
348
325 // Valid files
349 // Valid files
326 QTest::newRow("Valid file")
350 QTest::newRow("Valid file")
327 << QStringLiteral("ValidVector1.txt")
351 << QStringLiteral("ValidVector1.txt")
328 << ExpectedResults<VectorSeries>{}
352 << ExpectedResults<VectorSeries>{}
329 .setParsingOK(true)
353 .setParsingOK(true)
330 .setXAxisUnit(Unit{"nT", true})
354 .setXAxisUnit(Unit{"nT", true})
331 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
355 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
332 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
356 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
333 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
357 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
334 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
358 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
335 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
359 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
336 .setValuesData(
360 .setValuesData(
337 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
361 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
338 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
362 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
339 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
363 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
340
364
341 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
365 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
342 QTest::newRow("Invalid file type (scalar)")
366 QTest::newRow("Invalid file type (scalar)")
343 << QStringLiteral("ValidScalar1.txt")
367 << QStringLiteral("ValidScalar1.txt")
344 << ExpectedResults<VectorSeries>{}
368 << ExpectedResults<VectorSeries>{}
345 .setParsingOK(true)
369 .setParsingOK(true)
346 .setXAxisUnit(Unit{"nT", true})
370 .setXAxisUnit(Unit{"nT", true})
347 .setXAxisData({})
371 .setXAxisData({})
348 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
372 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
349 }
373 }
350
374
351 void TestAmdaResultParser::testReadVectorTxt()
375 void TestAmdaResultParser::testReadVectorTxt()
352 {
376 {
353 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
377 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
354 }
378 }
355
379
356 QTEST_MAIN(TestAmdaResultParser)
380 QTEST_MAIN(TestAmdaResultParser)
357 #include "TestAmdaResultParser.moc"
381 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now