##// END OF EJS Templates
Adds valid test cases on NaN and fill values
Alexandre Leroux -
r1015:6d53eb686f3e
parent child
Show More
@@ -0,0 +1,59
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 : 385
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] : 5.00000,6.50000,8.70000,11.4000
39 # PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000,14.6000
40 # PARAMETER_FILL_VALUE : -1.
41 # PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage
42 #
43 #
44 # ---------------
45 # INTERVAL INFO :
46 # ---------------
47 # INTERVAL_START : 2012-11-06T09:13:31.000
48 # INTERVAL_STOP : 2012-11-06T09:21:00.000
49 #
50 # ------
51 # DATA :
52 # ------
53 # DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3]
54 #
55 2012-11-06T09:14:35.000 -1.000 15405.838 8946.475 -1.000
56 2012-11-06T09:16:10.000 12631.465 -1.000 18133.158 -1.000
57 2012-11-06T09:17:45.000 8223.368 -1.000 10875.621 -1.000
58 2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 -1.000
59 2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 -1.000 No newline at end of file
@@ -0,0 +1,59
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 : 385
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] : 5.00000,6.50000,8.70000,11.4000
39 # PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000,14.6000
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 : 2012-11-06T09:13:31.000
48 # INTERVAL_STOP : 2012-11-06T09:21:00.000
49 #
50 # ------
51 # DATA :
52 # ------
53 # DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3]
54 #
55 2012-11-06T09:14:35.000 nan 15405.838 8946.475 nan
56 2012-11-06T09:16:10.000 12631.465 nan 18133.158 nan
57 2012-11-06T09:17:45.000 8223.368 nan 10875.621 nan
58 2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 nan
59 2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 nan No newline at end of file
@@ -1,422 +1,447
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();
376
377 auto nanValuesResult
378 = ExpectedResults<SpectrogramSeries>{}
379 .setParsingOK(true)
380 .setXAxisUnit(Unit{"t", true})
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),
383 dateTime(2012, 11, 6, 9, 20, 55)})
384 .setYAxisEnabled(true)
385 .setYAxisUnit(Unit{"eV"})
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)"})
388 .setValuesData(
389 QVector<QVector<double> >{{nan, 12631.465, 8223.368, 27595.301, 12820.613},
390 {15405.838, nan, nan, 25617.533, 11179.109},
391 {8946.475, 18133.158, 10875.621, 24051.619, 19283.221},
392 {nan, nan, nan, nan, nan}});
393
394 QTest::newRow("Valid file (containing NaN values)")
395 << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult;
396 QTest::newRow("Valid file (containing fill values)")
397 << QStringLiteral("spectro/ValidSpectrogramFillValues.txt")
398 << nanValuesResult; // Fill values are replaced by NaN values in the data series
399
375 }
400 }
376
401
377 void TestAmdaResultParser::testReadSpectrogramTxt()
402 void TestAmdaResultParser::testReadSpectrogramTxt()
378 {
403 {
379 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
404 testRead<SpectrogramSeries>(AmdaResultParser::ValueType::SPECTROGRAM);
380 }
405 }
381
406
382 void TestAmdaResultParser::testReadVectorTxt_data()
407 void TestAmdaResultParser::testReadVectorTxt_data()
383 {
408 {
384 testReadDataStructure<VectorSeries>();
409 testReadDataStructure<VectorSeries>();
385
410
386 // ////////// //
411 // ////////// //
387 // Test cases //
412 // Test cases //
388 // ////////// //
413 // ////////// //
389
414
390 // Valid files
415 // Valid files
391 QTest::newRow("Valid file")
416 QTest::newRow("Valid file")
392 << QStringLiteral("ValidVector1.txt")
417 << QStringLiteral("ValidVector1.txt")
393 << ExpectedResults<VectorSeries>{}
418 << ExpectedResults<VectorSeries>{}
394 .setParsingOK(true)
419 .setParsingOK(true)
395 .setXAxisUnit(Unit{"nT", true})
420 .setXAxisUnit(Unit{"nT", true})
396 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
421 .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
397 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
422 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
398 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
423 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
399 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
424 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
400 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
425 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)})
401 .setValuesData(
426 .setValuesData(
402 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
427 {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
403 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
428 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
404 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
429 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}});
405
430
406 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
431 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
407 QTest::newRow("Invalid file type (scalar)")
432 QTest::newRow("Invalid file type (scalar)")
408 << QStringLiteral("ValidScalar1.txt")
433 << QStringLiteral("ValidScalar1.txt")
409 << ExpectedResults<VectorSeries>{}
434 << ExpectedResults<VectorSeries>{}
410 .setParsingOK(true)
435 .setParsingOK(true)
411 .setXAxisUnit(Unit{"nT", true})
436 .setXAxisUnit(Unit{"nT", true})
412 .setXAxisData({})
437 .setXAxisData({})
413 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
438 .setValuesData(QVector<QVector<double> >{{}, {}, {}});
414 }
439 }
415
440
416 void TestAmdaResultParser::testReadVectorTxt()
441 void TestAmdaResultParser::testReadVectorTxt()
417 {
442 {
418 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
443 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
419 }
444 }
420
445
421 QTEST_MAIN(TestAmdaResultParser)
446 QTEST_MAIN(TestAmdaResultParser)
422 #include "TestAmdaResultParser.moc"
447 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now