##// END OF EJS Templates
Adds unit tests for reading vectors in AMDA
Alexandre Leroux -
r568:a7ded9f58584
parent child
Show More
@@ -0,0 +1,12
1 #Time Format : YYYY-MM-DDThh:mm:ss.mls
2 #imf - Type : Local Parameter @ CDPP/AMDA - Name : imf_gse - Units : nT - Size : 3 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim
3 2013-07-02T09:13:50.000 -0.332000 3.20600 0.0580000
4 2013-07-02T09:14:06.000 -1.01100 2.99900 0.496000
5 2013-07-02T09:14:22.000 -1.45700 2.78500 1.01800
6 2013-07-02T09:14:38.000 -1.29300 2.73600 1.48500
7 2013-07-02T09:14:54.000 -1.21700 2.61200 1.66200
8 2013-07-02T09:15:10.000 -1.44300 2.56400 1.50500
9 2013-07-02T09:15:26.000 -1.27800 2.89200 1.16800
10 2013-07-02T09:15:42.000 -1.20200 2.86200 1.24400
11 2013-07-02T09:15:58.000 -1.22000 2.85900 1.15000
12 2013-07-02T09:16:14.000 -1.25900 2.76400 1.35800 No newline at end of file
@@ -1,298 +1,313
1 1 #ifndef SCIQLOP_ARRAYDATA_H
2 2 #define SCIQLOP_ARRAYDATA_H
3 3
4 4 #include <Common/SortUtils.h>
5 5
6 6 #include <QReadLocker>
7 7 #include <QReadWriteLock>
8 8 #include <QVector>
9 9
10 10 #include <memory>
11 11
12 12 template <int Dim>
13 13 class ArrayData;
14 14
15 15 using DataContainer = QVector<QVector<double> >;
16 16
17 17 namespace arraydata_detail {
18 18
19 19 /// Struct used to sort ArrayData
20 20 template <int Dim>
21 21 struct Sort {
22 22 static std::shared_ptr<ArrayData<Dim> > sort(const DataContainer &data,
23 23 const std::vector<int> &sortPermutation)
24 24 {
25 25 auto nbComponents = data.size();
26 26 auto sortedData = DataContainer(nbComponents);
27 27
28 28 for (auto i = 0; i < nbComponents; ++i) {
29 29 sortedData[i] = SortUtils::sort(data.at(i), sortPermutation);
30 30 }
31 31
32 32 return std::make_shared<ArrayData<Dim> >(std::move(sortedData));
33 33 }
34 34 };
35 35
36 36 /// Specialization for uni-dimensional ArrayData
37 37 template <>
38 38 struct Sort<1> {
39 39 static std::shared_ptr<ArrayData<1> > sort(const DataContainer &data,
40 40 const std::vector<int> &sortPermutation)
41 41 {
42 42 return std::make_shared<ArrayData<1> >(SortUtils::sort(data.at(0), sortPermutation));
43 43 }
44 44 };
45 45
46 46 } // namespace arraydata_detail
47 47
48 48 /**
49 49 * @brief The ArrayData class represents a dataset for a data series.
50 50 *
51 51 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
52 52 * template-parameter. In a case of a two-dimensional dataset, each dataset component has the same
53 53 * number of values
54 54 *
55 55 * @tparam Dim the dimension of the ArrayData (one or two)
56 56 * @sa IDataSeries
57 57 */
58 58 template <int Dim>
59 59 class ArrayData {
60 60 public:
61 61 class IteratorValue {
62 62 public:
63 63 explicit IteratorValue(const DataContainer &container, bool begin) : m_Its{}
64 64 {
65 65 for (auto i = 0; i < container.size(); ++i) {
66 66 m_Its.push_back(begin ? container.at(i).cbegin() : container.at(i).cend());
67 67 }
68 68 }
69 69
70 70 double at(int index) const { return *m_Its.at(index); }
71 71 double first() const { return *m_Its.front(); }
72 72
73 73 void next()
74 74 {
75 75 for (auto &it : m_Its) {
76 76 ++it;
77 77 }
78 78 }
79 79
80 80 bool operator==(const IteratorValue &other) const { return m_Its == other.m_Its; }
81 81
82 82 private:
83 83 std::vector<DataContainer::value_type::const_iterator> m_Its;
84 84 };
85 85
86 86 class Iterator {
87 87 public:
88 88 using iterator_category = std::forward_iterator_tag;
89 89 using value_type = const IteratorValue;
90 90 using difference_type = std::ptrdiff_t;
91 91 using pointer = value_type *;
92 92 using reference = value_type &;
93 93
94 94 Iterator(const DataContainer &container, bool begin) : m_CurrentValue{container, begin} {}
95 95
96 96 virtual ~Iterator() noexcept = default;
97 97 Iterator(const Iterator &) = default;
98 98 Iterator(Iterator &&) = default;
99 99 Iterator &operator=(const Iterator &) = default;
100 100 Iterator &operator=(Iterator &&) = default;
101 101
102 102 Iterator &operator++()
103 103 {
104 104 m_CurrentValue.next();
105 105 return *this;
106 106 }
107 107
108 108 pointer operator->() const { return &m_CurrentValue; }
109 109 reference operator*() const { return m_CurrentValue; }
110 110
111 111 bool operator==(const Iterator &other) const
112 112 {
113 113 return m_CurrentValue == other.m_CurrentValue;
114 114 }
115 115
116 116 bool operator!=(const Iterator &other) const { return !(*this == other); }
117 117
118 118 private:
119 119 IteratorValue m_CurrentValue;
120 120 };
121 121
122 122 // ///// //
123 123 // Ctors //
124 124 // ///// //
125 125
126 126 /**
127 127 * Ctor for a unidimensional ArrayData
128 128 * @param data the data the ArrayData will hold
129 129 */
130 130 template <int D = Dim, typename = std::enable_if_t<D == 1> >
131 131 explicit ArrayData(QVector<double> data) : m_Data{1, QVector<double>{}}
132 132 {
133 133 m_Data[0] = std::move(data);
134 134 }
135 135
136 136 /**
137 137 * Ctor for a two-dimensional ArrayData. The number of components (number of vectors) must be
138 138 * greater than 2 and each component must have the same number of values
139 139 * @param data the data the ArrayData will hold
140 140 * @throws std::invalid_argument if the number of components is less than 2
141 141 * @remarks if the number of values is not the same for each component, no value is set
142 142 */
143 143 template <int D = Dim, typename = std::enable_if_t<D == 2> >
144 144 explicit ArrayData(DataContainer data)
145 145 {
146 146 auto nbComponents = data.size();
147 147 if (nbComponents < 2) {
148 148 throw std::invalid_argument{
149 149 QString{"A multidimensional ArrayData must have at least 2 components (found: %1"}
150 150 .arg(data.size())
151 151 .toStdString()};
152 152 }
153 153
154 154 auto nbValues = data.front().size();
155 155 if (std::all_of(data.cbegin(), data.cend(), [nbValues](const auto &component) {
156 156 return component.size() == nbValues;
157 157 })) {
158 158 m_Data = std::move(data);
159 159 }
160 160 else {
161 161 m_Data = DataContainer{nbComponents, QVector<double>{}};
162 162 }
163 163 }
164 164
165 165 /// Copy ctor
166 166 explicit ArrayData(const ArrayData &other)
167 167 {
168 168 QReadLocker otherLocker{&other.m_Lock};
169 169 m_Data = other.m_Data;
170 170 }
171 171
172 172 // /////////////// //
173 173 // General methods //
174 174 // /////////////// //
175 175
176 176 /**
177 177 * Merges into the array data an other array data. The two array datas must have the same number
178 178 * of components so the merge can be done
179 179 * @param other the array data to merge with
180 180 * @param prepend if true, the other array data is inserted at the beginning, otherwise it is
181 181 * inserted at the end
182 182 */
183 183 void add(const ArrayData<Dim> &other, bool prepend = false)
184 184 {
185 185 QWriteLocker locker{&m_Lock};
186 186 QReadLocker otherLocker{&other.m_Lock};
187 187
188 188 auto nbComponents = m_Data.size();
189 189 if (nbComponents != other.m_Data.size()) {
190 190 return;
191 191 }
192 192
193 193 for (auto componentIndex = 0; componentIndex < nbComponents; ++componentIndex) {
194 194 if (prepend) {
195 195 const auto &otherData = other.data(componentIndex);
196 196 const auto otherDataSize = otherData.size();
197 197
198 198 auto &data = m_Data[componentIndex];
199 199 data.insert(data.begin(), otherDataSize, 0.);
200 200
201 201 for (auto i = 0; i < otherDataSize; ++i) {
202 202 data.replace(i, otherData.at(i));
203 203 }
204 204 }
205 205 else {
206 206 m_Data[componentIndex] += other.data(componentIndex);
207 207 }
208 208 }
209 209 }
210 210
211 211 void clear()
212 212 {
213 213 QWriteLocker locker{&m_Lock};
214 214
215 215 auto nbComponents = m_Data.size();
216 216 for (auto i = 0; i < nbComponents; ++i) {
217 217 m_Data[i].clear();
218 218 }
219 219 }
220 220
221 221 /**
222 222 * @return the data of a component
223 223 * @param componentIndex the index of the component to retrieve the data
224 224 * @return the component's data, empty vector if the index is invalid
225 225 */
226 226 QVector<double> data(int componentIndex) const noexcept
227 227 {
228 228 QReadLocker locker{&m_Lock};
229 229
230 230 return (componentIndex >= 0 && componentIndex < m_Data.size()) ? m_Data.at(componentIndex)
231 231 : QVector<double>{};
232 232 }
233 233
234 234 /// @return the size (i.e. number of values) of a single component
235 235 /// @remarks in a case of a two-dimensional ArrayData, each component has the same size
236 236 int size() const
237 237 {
238 238 QReadLocker locker{&m_Lock};
239 239 return m_Data[0].size();
240 240 }
241 241
242 242 std::shared_ptr<ArrayData<Dim> > sort(const std::vector<int> &sortPermutation)
243 243 {
244 244 QReadLocker locker{&m_Lock};
245 245 return arraydata_detail::Sort<Dim>::sort(m_Data, sortPermutation);
246 246 }
247 247
248 248 // ///////// //
249 249 // Iterators //
250 250 // ///////// //
251 251
252 252 Iterator cbegin() const { return Iterator{m_Data, true}; }
253 253 Iterator cend() const { return Iterator{m_Data, false}; }
254 254
255 255 // ///////////// //
256 256 // 1-dim methods //
257 257 // ///////////// //
258 258
259 259 /**
260 260 * @return the data at a specified index
261 261 * @remarks index must be a valid position
262 262 * @remarks this method is only available for a unidimensional ArrayData
263 263 */
264 264 template <int D = Dim, typename = std::enable_if_t<D == 1> >
265 265 double at(int index) const noexcept
266 266 {
267 267 QReadLocker locker{&m_Lock};
268 268 return m_Data[0].at(index);
269 269 }
270 270
271 271 /**
272 272 * @return the data as a vector, as a const reference
273 273 * @remarks this method is only available for a unidimensional ArrayData
274 274 */
275 275 template <int D = Dim, typename = std::enable_if_t<D == 1> >
276 276 const QVector<double> &cdata() const noexcept
277 277 {
278 278 QReadLocker locker{&m_Lock};
279 279 return m_Data.at(0);
280 280 }
281 281
282 282 /**
283 283 * @return the data as a vector
284 284 * @remarks this method is only available for a unidimensional ArrayData
285 285 */
286 286 template <int D = Dim, typename = std::enable_if_t<D == 1> >
287 287 QVector<double> data() const noexcept
288 288 {
289 289 QReadLocker locker{&m_Lock};
290 290 return m_Data[0];
291 291 }
292 292
293 // ///////////// //
294 // 2-dim methods //
295 // ///////////// //
296
297 /**
298 * @return the data
299 * @remarks this method is only available for a two-dimensional ArrayData
300 */
301 template <int D = Dim, typename = std::enable_if_t<D == 2> >
302 DataContainer data() const noexcept
303 {
304 QReadLocker locker{&m_Lock};
305 return m_Data;
306 }
307
293 308 private:
294 309 DataContainer m_Data;
295 310 mutable QReadWriteLock m_Lock;
296 311 };
297 312
298 313 #endif // SCIQLOP_ARRAYDATA_H
@@ -1,212 +1,310
1 1 #include "AmdaResultParser.h"
2 2
3 3 #include <Data/ScalarSeries.h>
4 #include <Data/VectorSeries.h>
4 5
5 6 #include <QObject>
6 7 #include <QtTest>
7 8
8 9 namespace {
9 10
10 11 /// Path for the tests
11 12 const auto TESTS_RESOURCES_PATH
12 13 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
13 14
15 QDateTime dateTime(int year, int month, int day, int hours, int minutes, int seconds)
16 {
17 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
18 }
19
14 20 /// Compares two vectors that can potentially contain NaN values
15 21 bool compareVectors(const QVector<double> &v1, const QVector<double> &v2)
16 22 {
17 23 if (v1.size() != v2.size()) {
18 24 return false;
19 25 }
20 26
21 27 auto result = true;
22 28 auto v2It = v2.cbegin();
23 29 for (auto v1It = v1.cbegin(), v1End = v1.cend(); v1It != v1End && result; ++v1It, ++v2It) {
24 30 auto v1Value = *v1It;
25 31 auto v2Value = *v2It;
26 32
27 33 // If v1 is NaN, v2 has to be NaN too
28 34 result = std::isnan(v1Value) ? std::isnan(v2Value) : (v1Value == v2Value);
29 35 }
30 36
31 37 return result;
32 38 }
33 39
40 bool compareVectors(const QVector<QVector<double> > &v1, const QVector<QVector<double> > &v2)
41 {
42 if (v1.size() != v2.size()) {
43 return false;
44 }
45
46 auto result = true;
47 for (auto i = 0; i < v1.size() && result; ++i) {
48 result &= compareVectors(v1.at(i), v2.at(i));
49 }
50
51 return result;
52 }
53
54 QVector<QVector<double> > valuesData(const ArrayData<1> &arrayData)
55 {
56 return QVector<QVector<double> >{arrayData.data()};
57 }
58
59 QVector<QVector<double> > valuesData(const ArrayData<2> &arrayData)
60 {
61 return arrayData.data();
62 }
63
64
34 65 QString inputFilePath(const QString &inputFileName)
35 66 {
36 67 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
37 68 }
38 69
70 template <typename T>
39 71 struct ExpectedResults {
40 72 explicit ExpectedResults() = default;
41 73
42 /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles
43 74 explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData,
44 75 QVector<double> valuesData)
76 : ExpectedResults(xAxisUnit, valuesUnit, xAxisData,
77 QVector<QVector<double> >{std::move(valuesData)})
78 {
79 }
80
81 /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles
82 explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData,
83 QVector<QVector<double> > valuesData)
45 84 : m_ParsingOK{true},
46 85 m_XAxisUnit{xAxisUnit},
47 86 m_ValuesUnit{valuesUnit},
48 87 m_XAxisData{},
49 88 m_ValuesData{std::move(valuesData)}
50 89 {
51 90 // Converts QVector<QDateTime> to QVector<double>
52 91 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
53 92 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
54 93 }
55 94
56 95 /**
57 96 * Validates a DataSeries compared to the expected results
58 97 * @param results the DataSeries to validate
59 98 */
60 99 void validate(std::shared_ptr<IDataSeries> results)
61 100 {
62 101 if (m_ParsingOK) {
63 auto scalarSeries = dynamic_cast<ScalarSeries *>(results.get());
64 QVERIFY(scalarSeries != nullptr);
102 auto dataSeries = dynamic_cast<T *>(results.get());
103 QVERIFY(dataSeries != nullptr);
65 104
66 105 // Checks units
67 QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit);
68 QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit);
106 QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit);
107 QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit);
69 108
70 109 // Checks values : as the vectors can potentially contain NaN values, we must use a
71 110 // custom vector comparison method
72 QVERIFY(compareVectors(scalarSeries->xAxisData()->data(), m_XAxisData));
73 QVERIFY(compareVectors(scalarSeries->valuesData()->data(), m_ValuesData));
111 QVERIFY(compareVectors(dataSeries->xAxisData()->data(), m_XAxisData));
112 QVERIFY(compareVectors(valuesData(*dataSeries->valuesData()), m_ValuesData));
74 113 }
75 114 else {
76 115 QVERIFY(results == nullptr);
77 116 }
78 117 }
79 118
80 119 // Parsing was successfully completed
81 120 bool m_ParsingOK{false};
82 121 // Expected x-axis unit
83 122 Unit m_XAxisUnit{};
84 123 // Expected values unit
85 124 Unit m_ValuesUnit{};
86 125 // Expected x-axis data
87 126 QVector<double> m_XAxisData{};
88 127 // Expected values data
89 QVector<double> m_ValuesData{};
128 QVector<QVector<double> > m_ValuesData{};
90 129 };
91 130
92 131 } // namespace
93 132
94 Q_DECLARE_METATYPE(ExpectedResults)
133 Q_DECLARE_METATYPE(ExpectedResults<ScalarSeries>)
134 Q_DECLARE_METATYPE(ExpectedResults<VectorSeries>)
95 135
96 136 class TestAmdaResultParser : public QObject {
97 137 Q_OBJECT
138 private:
139 template <typename T>
140 void testReadDataStructure()
141 {
142 // ////////////// //
143 // Test structure //
144 // ////////////// //
145
146 // Name of TXT file to read
147 QTest::addColumn<QString>("inputFileName");
148 // Expected results
149 QTest::addColumn<ExpectedResults<T> >("expectedResults");
150 }
151
152 template <typename T>
153 void testRead(AmdaResultParser::ValueType valueType)
154 {
155 QFETCH(QString, inputFileName);
156 QFETCH(ExpectedResults<T>, expectedResults);
157
158 // Parses file
159 auto filePath = inputFilePath(inputFileName);
160 auto results = AmdaResultParser::readTxt(filePath, valueType);
161
162 // ///////////////// //
163 // Validates results //
164 // ///////////////// //
165 expectedResults.validate(results);
166 }
167
98 168 private slots:
99 169 /// Input test data
100 /// @sa testTxtJson()
101 void testReadTxt_data();
170 /// @sa testReadScalarTxt()
171 void testReadScalarTxt_data();
102 172
103 /// Tests parsing of a TXT file
104 void testReadTxt();
173 /// Tests parsing scalar series of a TXT file
174 void testReadScalarTxt();
175
176 /// Input test data
177 /// @sa testReadVectorTxt()
178 void testReadVectorTxt_data();
179
180 /// Tests parsing vector series of a TXT file
181 void testReadVectorTxt();
105 182 };
106 183
107 void TestAmdaResultParser::testReadTxt_data()
184 void TestAmdaResultParser::testReadScalarTxt_data()
108 185 {
109 // ////////////// //
110 // Test structure //
111 // ////////////// //
112
113 // Name of TXT file to read
114 QTest::addColumn<QString>("inputFileName");
115 // Expected results
116 QTest::addColumn<ExpectedResults>("expectedResults");
186 testReadDataStructure<ScalarSeries>();
117 187
118 188 // ////////// //
119 189 // Test cases //
120 190 // ////////// //
121 191
122 auto dateTime = [](int year, int month, int day, int hours, int minutes, int seconds) {
123 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
124 };
125
126 192 // Valid files
127 193 QTest::newRow("Valid file")
128 194 << QStringLiteral("ValidScalar1.txt")
129 << ExpectedResults{
195 << ExpectedResults<ScalarSeries>{
130 196 Unit{QStringLiteral("nT"), true}, Unit{},
131 197 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
132 198 dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30),
133 199 dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30),
134 200 dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30),
135 201 dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)},
136 202 QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
137 203 -2.55800, -2.43250, -2.42200}};
138 204
139 205 QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN")
140 206 << QStringLiteral("WrongValue.txt")
141 << ExpectedResults{
207 << ExpectedResults<ScalarSeries>{
142 208 Unit{QStringLiteral("nT"), true}, Unit{},
143 209 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
144 210 dateTime(2013, 9, 23, 9, 2, 30)},
145 211 QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}};
146 212
147 213 QTest::newRow("Valid file that contains NaN values")
148 214 << QStringLiteral("NaNValue.txt")
149 << ExpectedResults{
215 << ExpectedResults<ScalarSeries>{
150 216 Unit{QStringLiteral("nT"), true}, Unit{},
151 217 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
152 218 dateTime(2013, 9, 23, 9, 2, 30)},
153 219 QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}};
154 220
155 221 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
156 222 QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt")
157 << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{},
158 QVector<QDateTime>{}, QVector<double>{}};
223 << ExpectedResults<ScalarSeries>{Unit{QStringLiteral(""), true},
224 Unit{}, QVector<QDateTime>{},
225 QVector<double>{}};
159 226 QTest::newRow("Wrong unit file")
160 227 << QStringLiteral("WrongUnit.txt")
161 << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{},
162 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30),
163 dateTime(2013, 9, 23, 9, 1, 30),
164 dateTime(2013, 9, 23, 9, 2, 30)},
165 QVector<double>{-2.83950, -2.71850, -2.52150}};
228 << ExpectedResults<ScalarSeries>{Unit{QStringLiteral(""), true}, Unit{},
229 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30),
230 dateTime(2013, 9, 23, 9, 1, 30),
231 dateTime(2013, 9, 23, 9, 2, 30)},
232 QVector<double>{-2.83950, -2.71850, -2.52150}};
166 233
167 234 QTest::newRow("Wrong results file (date of first line is invalid")
168 235 << QStringLiteral("WrongDate.txt")
169 << ExpectedResults{
236 << ExpectedResults<ScalarSeries>{
170 237 Unit{QStringLiteral("nT"), true}, Unit{},
171 238 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
172 239 QVector<double>{-2.71850, -2.52150}};
173 240
174 241 QTest::newRow("Wrong results file (too many values for first line")
175 242 << QStringLiteral("TooManyValues.txt")
176 << ExpectedResults{
243 << ExpectedResults<ScalarSeries>{
177 244 Unit{QStringLiteral("nT"), true}, Unit{},
178 245 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
179 246 QVector<double>{-2.71850, -2.52150}};
180 247
181 248 QTest::newRow("Wrong results file (x of first line is NaN")
182 249 << QStringLiteral("NaNX.txt")
183 << ExpectedResults{
250 << ExpectedResults<ScalarSeries>{
184 251 Unit{QStringLiteral("nT"), true}, Unit{},
185 252 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
186 253 QVector<double>{-2.71850, -2.52150}};
187 254
255 QTest::newRow("Invalid file type (vector)")
256 << QStringLiteral("ValidVector1.txt")
257 << ExpectedResults<ScalarSeries>{Unit{QStringLiteral("nT"), true}, Unit{},
258 QVector<QDateTime>{}, QVector<double>{}};
259
188 260 // Invalid files
189 QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt")
190 << ExpectedResults{};
261 QTest::newRow("Invalid file (unexisting file)")
262 << QStringLiteral("UnexistingFile.txt") << ExpectedResults<ScalarSeries>{};
263
264 QTest::newRow("Invalid file (file not found on server)")
265 << QStringLiteral("FileNotFound.txt") << ExpectedResults<ScalarSeries>{};
266 }
191 267
192 QTest::newRow("Invalid file (file not found on server)") << QStringLiteral("FileNotFound.txt")
193 << ExpectedResults{};
268 void TestAmdaResultParser::testReadScalarTxt()
269 {
270 testRead<ScalarSeries>(AmdaResultParser::ValueType::SCALAR);
194 271 }
195 272
196 void TestAmdaResultParser::testReadTxt()
273 void TestAmdaResultParser::testReadVectorTxt_data()
197 274 {
198 QFETCH(QString, inputFileName);
199 QFETCH(ExpectedResults, expectedResults);
275 testReadDataStructure<VectorSeries>();
276
277 // ////////// //
278 // Test cases //
279 // ////////// //
280
281 // Valid files
282 QTest::newRow("Valid file")
283 << QStringLiteral("ValidVector1.txt")
284 << ExpectedResults<VectorSeries>{
285 Unit{QStringLiteral("nT"), true}, Unit{},
286 QVector<QDateTime>{dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6),
287 dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38),
288 dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10),
289 dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42),
290 dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)},
291 QVector<QVector<double> >{
292 {-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259},
293 {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764},
294 {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}};
200 295
201 // Parses file
202 auto filePath = inputFilePath(inputFileName);
203 auto results = AmdaResultParser::readTxt(filePath);
296 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
297 QTest::newRow("Invalid file type (scalar)")
298 << QStringLiteral("ValidScalar1.txt")
299 << ExpectedResults<VectorSeries>{Unit{QStringLiteral("nT"), true}, Unit{},
300 QVector<QDateTime>{},
301 QVector<QVector<double> >{{}, {}, {}}};
302 }
204 303
205 // ///////////////// //
206 // Validates results //
207 // ///////////////// //
208 expectedResults.validate(results);
304 void TestAmdaResultParser::testReadVectorTxt()
305 {
306 testRead<VectorSeries>(AmdaResultParser::ValueType::VECTOR);
209 307 }
210 308
211 309 QTEST_MAIN(TestAmdaResultParser)
212 310 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now