##// END OF EJS Templates
Adds unit test with data holes
Alexandre Leroux -
r954:a2b3fcb759c0
parent child
Show More
@@ -0,0 +1,62
1 # -----------
2 # AMDA INFO :
3 # -----------
4 # AMDA_ABOUT : Created by CDPP/AMDA(c)
5 # AMDA_VERSION : 3.5.0
6 # AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team
7 #
8 # --------------
9 # REQUEST INFO :
10 # --------------
11 # REQUEST_STRUCTURE : one-file-per-parameter-per-interval
12 # REQUEST_TIME_FORMAT : ISO 8601
13 # REQUEST_OUTPUT_PARAMS : tha_ion_sp
14 #
15 # -----------------
16 # BASE PARAMETERS :
17 # -----------------
18 #
19 # MISSION_ID : NONE
20 #
21 # INSTRUMENT_ID : NONE
22 #
23 # DATASET_ID : tha-esa-l2i
24 # DATASET_NAME : ion full mode
25 # DATASET_SOURCE : CDPP/DDServer
26 # DATASET_GLOBAL_START : 2007-03-07T18:53:59.134
27 # DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907
28 # DATASET_MIN_SAMPLING : 96
29 # DATASET_MAX_SAMPLING : 180
30 #
31 # PARAMETER_ID : tha_ion_sp
32 # PARAMETER_NAME : tha_ion_sp
33 # PARAMETER_SHORT_NAME : spectra
34 # PARAMETER_UNITS : eV/(cm^2-s-sr-eV)
35 # PARAMETER_TENSOR_ORDER : 0
36 # PARAMETER_TABLE[0] : energy
37 # PARAMETER_TABLE_UNITS[0] : eV
38 # PARAMETER_TABLE_MIN_VALUES[0] : 14234.4,18737.3
39 # PARAMETER_TABLE_MAX_VALUES[0] : 18737.3,23254.9
40 # PARAMETER_FILL_VALUE : nan
41 # PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage
42 #
43 #
44 # ---------------
45 # INTERVAL INFO :
46 # ---------------
47 # INTERVAL_START : 2011-12-10T12:10:00.000
48 # INTERVAL_STOP : 2011-12-10T12:40:00.000
49 #
50 # ------
51 # DATA :
52 # ------
53 # DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1]
54 #
55 2011-12-10T12:10:54.000 2577578.000 2336016.000
56 2011-12-10T12:17:23.000 2314121.500 1712093.125
57 2011-12-10T12:23:51.000 2063608.750 1614491.625
58 2011-12-10T12:30:19.000 2234525.500 1764516.500
59 2011-12-10T12:35:04.000 1670215.250 1688078.500
60 2011-12-10T12:36:41.000 1689243.250 1743183.500
61 2011-12-10T12:38:18.000 1654617.125 1733603.250
62 2011-12-10T12:39:55.000 1504983.750 1708356.500 No newline at end of file
@@ -1,451 +1,506
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/SpectrogramSeries.h>
5 #include <Data/VectorSeries.h>
5 #include <Data/VectorSeries.h>
6
6
7 #include <QObject>
7 #include <QObject>
8 #include <QtTest>
8 #include <QtTest>
9
9
10 namespace {
10 namespace {
11
11
12 /// Path for the tests
12 /// Path for the tests
13 const auto TESTS_RESOURCES_PATH
13 const auto TESTS_RESOURCES_PATH
14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
14 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
15
15
16 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)
17 {
17 {
18 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
18 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
19 }
19 }
20
20
21 QString inputFilePath(const QString &inputFileName)
21 QString inputFilePath(const QString &inputFileName)
22 {
22 {
23 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
23 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
24 }
24 }
25
25
26 template <typename T>
26 template <typename T>
27 struct ExpectedResults {
27 struct ExpectedResults {
28
28
29 ExpectedResults &setParsingOK(bool parsingOK)
29 ExpectedResults &setParsingOK(bool parsingOK)
30 {
30 {
31 m_ParsingOK = parsingOK;
31 m_ParsingOK = parsingOK;
32 return *this;
32 return *this;
33 }
33 }
34
34
35 ExpectedResults &setXAxisUnit(Unit xAxisUnit)
35 ExpectedResults &setXAxisUnit(Unit xAxisUnit)
36 {
36 {
37 m_XAxisUnit = std::move(xAxisUnit);
37 m_XAxisUnit = std::move(xAxisUnit);
38 return *this;
38 return *this;
39 }
39 }
40
40
41 ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData)
41 ExpectedResults &setXAxisData(const QVector<QDateTime> &xAxisData)
42 {
42 {
43 m_XAxisData.clear();
43 m_XAxisData.clear();
44
44
45 // Converts QVector<QDateTime> to QVector<double>
45 // Converts QVector<QDateTime> to QVector<double>
46 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
46 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
47 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
47 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
48
48
49 return *this;
49 return *this;
50 }
50 }
51
51
52 ExpectedResults &setValuesUnit(Unit valuesUnit)
52 ExpectedResults &setValuesUnit(Unit valuesUnit)
53 {
53 {
54 m_ValuesUnit = std::move(valuesUnit);
54 m_ValuesUnit = std::move(valuesUnit);
55 return *this;
55 return *this;
56 }
56 }
57
57
58 ExpectedResults &setValuesData(QVector<double> valuesData)
58 ExpectedResults &setValuesData(QVector<double> valuesData)
59 {
59 {
60 m_ValuesData.clear();
60 m_ValuesData.clear();
61 m_ValuesData.push_back(std::move(valuesData));
61 m_ValuesData.push_back(std::move(valuesData));
62 return *this;
62 return *this;
63 }
63 }
64
64
65 ExpectedResults &setValuesData(QVector<QVector<double> > valuesData)
65 ExpectedResults &setValuesData(QVector<QVector<double> > valuesData)
66 {
66 {
67 m_ValuesData = std::move(valuesData);
67 m_ValuesData = std::move(valuesData);
68 return *this;
68 return *this;
69 }
69 }
70
70
71 ExpectedResults &setYAxisEnabled(bool yAxisEnabled)
71 ExpectedResults &setYAxisEnabled(bool yAxisEnabled)
72 {
72 {
73 m_YAxisEnabled = yAxisEnabled;
73 m_YAxisEnabled = yAxisEnabled;
74 return *this;
74 return *this;
75 }
75 }
76
76
77 ExpectedResults &setYAxisUnit(Unit yAxisUnit)
77 ExpectedResults &setYAxisUnit(Unit yAxisUnit)
78 {
78 {
79 m_YAxisUnit = std::move(yAxisUnit);
79 m_YAxisUnit = std::move(yAxisUnit);
80 return *this;
80 return *this;
81 }
81 }
82
82
83 ExpectedResults &setYAxisData(QVector<double> yAxisData)
83 ExpectedResults &setYAxisData(QVector<double> yAxisData)
84 {
84 {
85 m_YAxisData = std::move(yAxisData);
85 m_YAxisData = std::move(yAxisData);
86 return *this;
86 return *this;
87 }
87 }
88
88
89 /**
89 /**
90 * Validates a DataSeries compared to the expected results
90 * Validates a DataSeries compared to the expected results
91 * @param results the DataSeries to validate
91 * @param results the DataSeries to validate
92 */
92 */
93 void validate(std::shared_ptr<IDataSeries> results)
93 void validate(std::shared_ptr<IDataSeries> results)
94 {
94 {
95 if (m_ParsingOK) {
95 if (m_ParsingOK) {
96 auto dataSeries = dynamic_cast<T *>(results.get());
96 auto dataSeries = dynamic_cast<T *>(results.get());
97 if (dataSeries == nullptr) {
97 if (dataSeries == nullptr) {
98
98
99 // No unit detected, parsink ok but data is nullptr
99 // No unit detected, parsink ok but data is nullptr
100 // TODO, improve the test to verify that the data is null
100 // TODO, improve the test to verify that the data is null
101 return;
101 return;
102 }
102 }
103
103
104 // Checks units
104 // Checks units
105 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
105 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
106 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
106 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
107
107
108 auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) {
108 auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) {
109 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(),
109 QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(),
110 expectedData.cend(),
110 expectedData.cend(),
111 [&equalFun](const auto &dataSeriesIt, const auto &expectedX) {
111 [&equalFun](const auto &dataSeriesIt, const auto &expectedX) {
112 return equalFun(dataSeriesIt, expectedX);
112 return equalFun(dataSeriesIt, expectedX);
113 }));
113 }));
114 };
114 };
115
115
116 // Checks x-axis data
116 // Checks x-axis data
117 verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) {
117 verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) {
118 return seriesIt.x() == value;
118 return seriesIt.x() == value;
119 });
119 });
120
120
121 // Checks values data of each component
121 // Checks values data of each component
122 for (auto i = 0; i < m_ValuesData.size(); ++i) {
122 for (auto i = 0; i < m_ValuesData.size(); ++i) {
123 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) {
124 auto itValue = seriesIt.value(i);
124 auto itValue = seriesIt.value(i);
125 return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value;
125 return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value;
126 });
126 });
127 }
127 }
128
128
129 // Checks y-axis (if defined)
129 // Checks y-axis (if defined)
130 auto yAxis = dataSeries->yAxis();
130 auto yAxis = dataSeries->yAxis();
131 QCOMPARE(yAxis.isDefined(), m_YAxisEnabled);
131 QCOMPARE(yAxis.isDefined(), m_YAxisEnabled);
132
132
133 if (m_YAxisEnabled) {
133 if (m_YAxisEnabled) {
134 // Unit
134 // Unit
135 QCOMPARE(yAxis.unit(), m_YAxisUnit);
135 QCOMPARE(yAxis.unit(), m_YAxisUnit);
136
136
137 // Data
137 // Data
138 auto yAxisSize = yAxis.size();
138 auto yAxisSize = yAxis.size();
139 QCOMPARE(yAxisSize, m_YAxisData.size());
139 QCOMPARE(yAxisSize, m_YAxisData.size());
140 for (auto i = 0; i < yAxisSize; ++i) {
140 for (auto i = 0; i < yAxisSize; ++i) {
141 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
141 QCOMPARE(yAxis.at(i), m_YAxisData.at(i));
142 }
142 }
143 }
143 }
144 }
144 }
145 else {
145 else {
146 QVERIFY(results == nullptr);
146 QVERIFY(results == nullptr);
147 }
147 }
148 }
148 }
149
149
150 // Parsing was successfully completed
150 // Parsing was successfully completed
151 bool m_ParsingOK{false};
151 bool m_ParsingOK{false};
152 // Expected x-axis unit
152 // Expected x-axis unit
153 Unit m_XAxisUnit{};
153 Unit m_XAxisUnit{};
154 // Expected x-axis data
154 // Expected x-axis data
155 QVector<double> m_XAxisData{};
155 QVector<double> m_XAxisData{};
156 // Expected values unit
156 // Expected values unit
157 Unit m_ValuesUnit{};
157 Unit m_ValuesUnit{};
158 // Expected values data
158 // Expected values data
159 QVector<QVector<double> > m_ValuesData{};
159 QVector<QVector<double> > m_ValuesData{};
160 // Expected data series has y-axis
160 // Expected data series has y-axis
161 bool m_YAxisEnabled{false};
161 bool m_YAxisEnabled{false};
162 // Expected y-axis unit (if axis defined)
162 // Expected y-axis unit (if axis defined)
163 Unit m_YAxisUnit{};
163 Unit m_YAxisUnit{};
164 // Expected y-axis data (if axis defined)
164 // Expected y-axis data (if axis defined)
165 QVector<double> m_YAxisData{};
165 QVector<double> m_YAxisData{};
166 };
166 };
167
167
168 } // namespace
168 } // namespace
169
169
170 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
170 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
171 Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>)
171 Q_DECLARE_METATYPE(ExpectedResults<SpectrogramSeries>)
172 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
172 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
173
173
174 class TestAmdaResultParser : public QObject {
174 class TestAmdaResultParser : public QObject {
175 Q_OBJECT
175 Q_OBJECT
176 private:
176 private:
177 template <typename T>
177 template <typename T>
178 void testReadDataStructure()
178 void testReadDataStructure()
179 {
179 {
180 // ////////////// //
180 // ////////////// //
181 // Test structure //
181 // Test structure //
182 // ////////////// //
182 // ////////////// //
183
183
184 // Name of TXT file to read
184 // Name of TXT file to read
185 QTest::addColumn<QString>("inputFileName");
185 QTest::addColumn<QString>("inputFileName");
186 // Expected results
186 // Expected results
187 QTest::addColumn<ExpectedResults<T> >("expectedResults");
187 QTest::addColumn<ExpectedResults<T> >("expectedResults");
188 }
188 }
189
189
190 template <typename T>
190 template <typename T>
191 void testRead(AmdaResultParser::ValueType valueType)
191 void testRead(AmdaResultParser::ValueType valueType)
192 {
192 {
193 QFETCH(QString, inputFileName);
193 QFETCH(QString, inputFileName);
194 QFETCH(ExpectedResults<T>, expectedResults);
194 QFETCH(ExpectedResults<T>, expectedResults);
195
195
196 // Parses file
196 // Parses file
197 auto filePath = inputFilePath(inputFileName);
197 auto filePath = inputFilePath(inputFileName);
198 auto results = AmdaResultParser::readTxt(filePath, valueType);
198 auto results = AmdaResultParser::readTxt(filePath, valueType);
199
199
200 // ///////////////// //
200 // ///////////////// //
201 // Validates results //
201 // Validates results //
202 // ///////////////// //
202 // ///////////////// //
203 expectedResults.validate(results);
203 expectedResults.validate(results);
204 }
204 }
205
205
206 private slots:
206 private slots:
207 /// Input test data
207 /// Input test data
208 /// @sa testReadScalarTxt()
208 /// @sa testReadScalarTxt()
209 void testReadScalarTxt_data();
209 void testReadScalarTxt_data();
210
210
211 /// Tests parsing scalar series of a TXT file
211 /// Tests parsing scalar series of a TXT file
212 void testReadScalarTxt();
212 void testReadScalarTxt();
213
213
214 /// Input test data
214 /// Input test data
215 /// @sa testReadSpectrogramTxt()
215 /// @sa testReadSpectrogramTxt()
216 void testReadSpectrogramTxt_data();
216 void testReadSpectrogramTxt_data();
217
217
218 /// Tests parsing spectrogram series of a TXT file
218 /// Tests parsing spectrogram series of a TXT file
219 void testReadSpectrogramTxt();
219 void testReadSpectrogramTxt();
220
220
221 /// Input test data
221 /// Input test data
222 /// @sa testReadVectorTxt()
222 /// @sa testReadVectorTxt()
223 void testReadVectorTxt_data();
223 void testReadVectorTxt_data();
224
224
225 /// Tests parsing vector series of a TXT file
225 /// Tests parsing vector series of a TXT file
226 void testReadVectorTxt();
226 void testReadVectorTxt();
227 };
227 };
228
228
229 void TestAmdaResultParser::testReadScalarTxt_data()
229 void TestAmdaResultParser::testReadScalarTxt_data()
230 {
230 {
231 testReadDataStructure<ScalarSeries>();
231 testReadDataStructure<ScalarSeries>();
232
232
233 // ////////// //
233 // ////////// //
234 // Test cases //
234 // Test cases //
235 // ////////// //
235 // ////////// //
236
236
237 // Valid files
237 // Valid files
238 QTest::newRow("Valid file")
238 QTest::newRow("Valid file")
239 << QStringLiteral("ValidScalar1.txt")
239 << QStringLiteral("ValidScalar1.txt")
240 << ExpectedResults<ScalarSeries>{}
240 << ExpectedResults<ScalarSeries>{}
241 .setParsingOK(true)
241 .setParsingOK(true)
242 .setXAxisUnit(Unit{"nT", true})
242 .setXAxisUnit(Unit{"nT", true})
243 .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),
244 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),
245 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),
246 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),
247 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)})
248 .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,
249 -2.55800, -2.43250, -2.42200});
249 -2.55800, -2.43250, -2.42200});
250
250
251 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")
252 << QStringLiteral("WrongValue.txt")
252 << QStringLiteral("WrongValue.txt")
253 << ExpectedResults<ScalarSeries>{}
253 << ExpectedResults<ScalarSeries>{}
254 .setParsingOK(true)
254 .setParsingOK(true)
255 .setXAxisUnit(Unit{"nT", true})
255 .setXAxisUnit(Unit{"nT", true})
256 .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),
257 dateTime(2013, 9, 23, 9, 2, 30)})
257 dateTime(2013, 9, 23, 9, 2, 30)})
258 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
258 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
259
259
260 QTest::newRow("Valid file that contains NaN values")
260 QTest::newRow("Valid file that contains NaN values")
261 << QStringLiteral("NaNValue.txt")
261 << QStringLiteral("NaNValue.txt")
262 << ExpectedResults<ScalarSeries>{}
262 << ExpectedResults<ScalarSeries>{}
263 .setParsingOK(true)
263 .setParsingOK(true)
264 .setXAxisUnit(Unit{("nT"), true})
264 .setXAxisUnit(Unit{("nT"), true})
265 .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),
266 dateTime(2013, 9, 23, 9, 2, 30)})
266 dateTime(2013, 9, 23, 9, 2, 30)})
267 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
267 .setValuesData({std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150});
268
268
269 // 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.)
270 QTest::newRow("No unit file")
270 QTest::newRow("No unit file")
271 << QStringLiteral("NoUnit.txt")
271 << QStringLiteral("NoUnit.txt")
272 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true});
272 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"", true});
273
273
274 QTest::newRow("Wrong unit file")
274 QTest::newRow("Wrong unit file")
275 << QStringLiteral("WrongUnit.txt")
275 << QStringLiteral("WrongUnit.txt")
276 << ExpectedResults<ScalarSeries>{}
276 << ExpectedResults<ScalarSeries>{}
277 .setParsingOK(true)
277 .setParsingOK(true)
278 .setXAxisUnit(Unit{"", true})
278 .setXAxisUnit(Unit{"", true})
279 .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),
280 dateTime(2013, 9, 23, 9, 2, 30)})
280 dateTime(2013, 9, 23, 9, 2, 30)})
281 .setValuesData({-2.83950, -2.71850, -2.52150});
281 .setValuesData({-2.83950, -2.71850, -2.52150});
282
282
283 QTest::newRow("Wrong results file (date of first line is invalid")
283 QTest::newRow("Wrong results file (date of first line is invalid")
284 << QStringLiteral("WrongDate.txt")
284 << QStringLiteral("WrongDate.txt")
285 << ExpectedResults<ScalarSeries>{}
285 << ExpectedResults<ScalarSeries>{}
286 .setParsingOK(true)
286 .setParsingOK(true)
287 .setXAxisUnit(Unit{"nT", true})
287 .setXAxisUnit(Unit{"nT", true})
288 .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)})
289 .setValuesData({-2.71850, -2.52150});
289 .setValuesData({-2.71850, -2.52150});
290
290
291 QTest::newRow("Wrong results file (too many values for first line")
291 QTest::newRow("Wrong results file (too many values for first line")
292 << QStringLiteral("TooManyValues.txt")
292 << QStringLiteral("TooManyValues.txt")
293 << ExpectedResults<ScalarSeries>{}
293 << ExpectedResults<ScalarSeries>{}
294 .setParsingOK(true)
294 .setParsingOK(true)
295 .setXAxisUnit(Unit{"nT", true})
295 .setXAxisUnit(Unit{"nT", true})
296 .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)})
297 .setValuesData({-2.71850, -2.52150});
297 .setValuesData({-2.71850, -2.52150});
298
298
299 QTest::newRow("Wrong results file (x of first line is NaN")
299 QTest::newRow("Wrong results file (x of first line is NaN")
300 << QStringLiteral("NaNX.txt")
300 << QStringLiteral("NaNX.txt")
301 << ExpectedResults<ScalarSeries>{}
301 << ExpectedResults<ScalarSeries>{}
302 .setParsingOK(true)
302 .setParsingOK(true)
303 .setXAxisUnit(Unit{"nT", true})
303 .setXAxisUnit(Unit{"nT", true})
304 .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)})
305 .setValuesData({-2.71850, -2.52150});
305 .setValuesData({-2.71850, -2.52150});
306
306
307 QTest::newRow("Invalid file type (vector)")
307 QTest::newRow("Invalid file type (vector)")
308 << QStringLiteral("ValidVector1.txt")
308 << QStringLiteral("ValidVector1.txt")
309 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true});
309 << ExpectedResults<ScalarSeries>{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true});
310
310
311 // Invalid files
311 // Invalid files
312 QTest::newRow("Invalid file (unexisting file)")
312 QTest::newRow("Invalid file (unexisting file)")
313 << QStringLiteral("UnexistingFile.txt")
313 << QStringLiteral("UnexistingFile.txt")
314 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
314 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
315
315
316 QTest::newRow("Invalid file (file not found on server)")
316 QTest::newRow("Invalid file (file not found on server)")
317 << QStringLiteral("FileNotFound.txt")
317 << QStringLiteral("FileNotFound.txt")
318 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
318 << ExpectedResults<ScalarSeries>{}.setParsingOK(false);
319 }
319 }
320
320
321 void TestAmdaResultParser::testReadScalarTxt()
321 void TestAmdaResultParser::testReadScalarTxt()
322 {
322 {
323 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
323 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
324 }
324 }
325
325
326 void TestAmdaResultParser::testReadSpectrogramTxt_data()
326 void TestAmdaResultParser::testReadSpectrogramTxt_data()
327 {
327 {
328 testReadDataStructure<SpectrogramSeries>();
328 testReadDataStructure<SpectrogramSeries>();
329
329
330 // ////////// //
330 // ////////// //
331 // Test cases //
331 // Test cases //
332 // ////////// //
332 // ////////// //
333
333
334 // Valid files
334 // Valid files
335 QTest::newRow("Valid file (three bands)")
335 QTest::newRow("Valid file (three bands)")
336 << QStringLiteral("spectro/ValidSpectrogram1.txt")
336 << QStringLiteral("spectro/ValidSpectrogram1.txt")
337 << ExpectedResults<SpectrogramSeries>{}
337 << ExpectedResults<SpectrogramSeries>{}
338 .setParsingOK(true)
338 .setParsingOK(true)
339 .setXAxisUnit(Unit{"t", true})
339 .setXAxisUnit(Unit{"t", true})
340 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
340 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
341 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
341 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
342 dateTime(2012, 11, 6, 9, 20, 55)})
342 dateTime(2012, 11, 6, 9, 20, 55)})
343 .setYAxisEnabled(true)
343 .setYAxisEnabled(true)
344 .setYAxisUnit(Unit{"eV"})
344 .setYAxisUnit(Unit{"eV"})
345 .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band
345 .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band
346 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
346 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
347 .setValuesData(QVector<QVector<double> >{
347 .setValuesData(QVector<QVector<double> >{
348 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
348 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
349 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
349 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
350 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}});
350 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}});
351
351
352 auto fourBandsResult
352 auto fourBandsResult
353 = ExpectedResults<SpectrogramSeries>{}
353 = ExpectedResults<SpectrogramSeries>{}
354 .setParsingOK(true)
354 .setParsingOK(true)
355 .setXAxisUnit(Unit{"t", true})
355 .setXAxisUnit(Unit{"t", true})
356 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
356 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
357 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
357 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
358 dateTime(2012, 11, 6, 9, 20, 55)})
358 dateTime(2012, 11, 6, 9, 20, 55)})
359 .setYAxisEnabled(true)
359 .setYAxisEnabled(true)
360 .setYAxisUnit(Unit{"eV"})
360 .setYAxisUnit(Unit{"eV"})
361 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
361 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
362 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
362 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
363 .setValuesData(QVector<QVector<double> >{
363 .setValuesData(QVector<QVector<double> >{
364 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
364 {16313.780, 12631.465, 8223.368, 27595.301, 12820.613},
365 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
365 {15405.838, 11957.925, 15026.249, 25617.533, 11179.109},
366 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
366 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
367 {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}});
367 {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}});
368
368
369 QTest::newRow("Valid file (four bands)")
369 QTest::newRow("Valid file (four bands)")
370 << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult;
370 << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult;
371 QTest::newRow("Valid file (four unsorted bands)")
371 QTest::newRow("Valid file (four unsorted bands)")
372 << QStringLiteral("spectro/ValidSpectrogram3.txt")
372 << QStringLiteral("spectro/ValidSpectrogram3.txt")
373 << fourBandsResult; // Bands and values are sorted
373 << fourBandsResult; // Bands and values are sorted
374
374
375 auto nan = std::numeric_limits<double>::quiet_NaN();
375 auto nan = std::numeric_limits<double>::quiet_NaN();
376
376
377 auto nanValuesResult
377 auto nanValuesResult
378 = ExpectedResults<SpectrogramSeries>{}
378 = ExpectedResults<SpectrogramSeries>{}
379 .setParsingOK(true)
379 .setParsingOK(true)
380 .setXAxisUnit(Unit{"t", true})
380 .setXAxisUnit(Unit{"t", true})
381 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
381 .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10),
382 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
382 dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20),
383 dateTime(2012, 11, 6, 9, 20, 55)})
383 dateTime(2012, 11, 6, 9, 20, 55)})
384 .setYAxisEnabled(true)
384 .setYAxisEnabled(true)
385 .setYAxisUnit(Unit{"eV"})
385 .setYAxisUnit(Unit{"eV"})
386 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
386 .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band
387 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
387 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
388 .setValuesData(
388 .setValuesData(
389 QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613},
389 QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613},
390 {15405.838, nan, nan, 25617.533, 11179.109},
390 {15405.838, nan, nan, 25617.533, 11179.109},
391 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
391 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
392 {nan, nan, nan, nan, nan}});
392 {nan, nan, nan, nan, nan}});
393
393
394 QTest::newRow("Valid file (containing NaN values)")
394 QTest::newRow("Valid file (containing NaN values)")
395 << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult;
395 << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult;
396 QTest::newRow("Valid file (containing fill values)")
396 QTest::newRow("Valid file (containing fill values)")
397 << QStringLiteral("spectro/ValidSpectrogramFillValues.txt")
397 << QStringLiteral("spectro/ValidSpectrogramFillValues.txt")
398 << nanValuesResult; // Fill values are replaced by NaN values in the data series
398 << nanValuesResult; // Fill values are replaced by NaN values in the data series
399
399
400 QTest::newRow("Valid file (containing data holes, resolution = 3 minutes)")
401 << QStringLiteral("spectro/ValidSpectrogramDataHoles.txt")
402 << ExpectedResults<SpectrogramSeries>{}
403 .setParsingOK(true)
404 .setXAxisUnit(Unit{"t", true})
405 .setXAxisData({dateTime(2011, 12, 10, 12, 10, 54), //
406 dateTime(2011, 12, 10, 12, 13, 54), // Data hole
407 dateTime(2011, 12, 10, 12, 16, 54), // Data hole
408 dateTime(2011, 12, 10, 12, 17, 23), //
409 dateTime(2011, 12, 10, 12, 20, 23), // Data hole
410 dateTime(2011, 12, 10, 12, 23, 23), // Data hole
411 dateTime(2011, 12, 10, 12, 23, 51), //
412 dateTime(2011, 12, 10, 12, 26, 51), // Data hole
413 dateTime(2011, 12, 10, 12, 29, 51), // Data hole
414 dateTime(2011, 12, 10, 12, 30, 19), //
415 dateTime(2011, 12, 10, 12, 33, 19), // Data hole
416 dateTime(2011, 12, 10, 12, 35, 04), //
417 dateTime(2011, 12, 10, 12, 36, 41), //
418 dateTime(2011, 12, 10, 12, 38, 18), //
419 dateTime(2011, 12, 10, 12, 39, 55)})
420 .setYAxisEnabled(true)
421 .setYAxisUnit(Unit{"eV"})
422 .setYAxisData({16485.85, 20996.1}) // middle of the intervals of each band
423 .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"})
424 .setValuesData(QVector<QVector<double> >{{2577578.000, //
425 nan, // Data hole
426 nan, // Data hole
427 2314121.500, //
428 nan, // Data hole
429 nan, // Data hole
430 2063608.750, //
431 nan, // Data hole
432 nan, // Data hole
433 2234525.500, //
434 nan, // Data hole
435 1670215.250, //
436 1689243.250, //
437 1654617.125, //
438 1504983.750},
439 {2336016.000, //
440 nan, // Data hole
441 nan, // Data hole
442 1712093.125, //
443 nan, // Data hole
444 nan, // Data hole
445 1614491.625, //
446 nan, // Data hole
447 nan, // Data hole
448 1764516.500, //
449 nan, // Data hole
450 1688078.500, //
451 1743183.500, //
452 1733603.250, //
453 1708356.500}});
454
400 // Invalid files
455 // Invalid files
401 QTest::newRow("Invalid file (inconsistent bands)")
456 QTest::newRow("Invalid file (inconsistent bands)")
402 << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt")
457 << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt")
403 << ExpectedResults<SpectrogramSeries>{}.setParsingOK(false);
458 << ExpectedResults<SpectrogramSeries>{}.setParsingOK(false);
404 }
459 }
405
460
406 void TestAmdaResultParser::testReadSpectrogramTxt()
461 void TestAmdaResultParser::testReadSpectrogramTxt()
407 {
462 {
408 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
463 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
409 }
464 }
410
465
411 void TestAmdaResultParser::testReadVectorTxt_data()
466 void TestAmdaResultParser::testReadVectorTxt_data()
412 {
467 {
413 testReadDataStructure<VectorSeries>();
468 testReadDataStructure<VectorSeries>();
414
469
415 // ////////// //
470 // ////////// //
416 // Test cases //
471 // Test cases //
417 // ////////// //
472 // ////////// //
418
473
419 // Valid files
474 // Valid files
420 QTest::newRow("Valid file")
475 QTest::newRow("Valid file")
421 << QStringLiteral("ValidVector1.txt")
476 << QStringLiteral("ValidVector1.txt")
422 << ExpectedResults<VectorSeries>{}
477 << ExpectedResults<VectorSeries>{}
423 .setParsingOK(true)
478 .setParsingOK(true)
424 .setXAxisUnit(Unit{"nT", true})
479 .setXAxisUnit(Unit{"nT", true})
425 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
480 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
426 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
481 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
427 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
482 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
428 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
483 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
429 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
484 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
430 .setValuesData(
485 .setValuesData(
431 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
486 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
432 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
487 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
433 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
488 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
434
489
435 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
490 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
436 QTest::newRow("Invalid file type (scalar)")
491 QTest::newRow("Invalid file type (scalar)")
437 << QStringLiteral("ValidScalar1.txt")
492 << QStringLiteral("ValidScalar1.txt")
438 << ExpectedResults<VectorSeries>{}
493 << ExpectedResults<VectorSeries>{}
439 .setParsingOK(true)
494 .setParsingOK(true)
440 .setXAxisUnit(Unit{"nT", true})
495 .setXAxisUnit(Unit{"nT", true})
441 .setXAxisData({})
496 .setXAxisData({})
442 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
497 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
443 }
498 }
444
499
445 void TestAmdaResultParser::testReadVectorTxt()
500 void TestAmdaResultParser::testReadVectorTxt()
446 {
501 {
447 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
502 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
448 }
503 }
449
504
450 QTEST_MAIN(TestAmdaResultParser)
505 QTEST_MAIN(TestAmdaResultParser)
451 #include "TestAmdaResultParser.moc"
506 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now