|
@@
-11,6
+11,26
namespace {
|
|
11
|
const auto TESTS_RESOURCES_PATH
|
|
11
|
const auto TESTS_RESOURCES_PATH
|
|
12
|
= QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
|
|
12
|
= QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
|
|
13
|
|
|
13
|
|
|
|
|
|
14
|
/// Compares two vectors that can potentially contain NaN values
|
|
|
|
|
15
|
bool compareVectors(const QVector<double> &v1, const QVector<double> &v2)
|
|
|
|
|
16
|
{
|
|
|
|
|
17
|
if (v1.size() != v2.size()) {
|
|
|
|
|
18
|
return false;
|
|
|
|
|
19
|
}
|
|
|
|
|
20
|
|
|
|
|
|
21
|
auto result = true;
|
|
|
|
|
22
|
auto v2It = v2.cbegin();
|
|
|
|
|
23
|
for (auto v1It = v1.cbegin(), v1End = v1.cend(); v1It != v1End && result; ++v1It, ++v2It) {
|
|
|
|
|
24
|
auto v1Value = *v1It;
|
|
|
|
|
25
|
auto v2Value = *v2It;
|
|
|
|
|
26
|
|
|
|
|
|
27
|
// If v1 is NaN, v2 has to be NaN too
|
|
|
|
|
28
|
result = std::isnan(v1Value) ? std::isnan(v2Value) : (v1Value == v2Value);
|
|
|
|
|
29
|
}
|
|
|
|
|
30
|
|
|
|
|
|
31
|
return result;
|
|
|
|
|
32
|
}
|
|
|
|
|
33
|
|
|
14
|
QString inputFilePath(const QString &inputFileName)
|
|
34
|
QString inputFilePath(const QString &inputFileName)
|
|
15
|
{
|
|
35
|
{
|
|
16
|
return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
|
|
36
|
return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
|
|
@@
-47,9
+67,10
struct ExpectedResults {
|
|
47
|
QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit);
|
|
67
|
QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit);
|
|
48
|
QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit);
|
|
68
|
QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit);
|
|
49
|
|
|
69
|
|
|
50
|
// Checks values
|
|
70
|
// Checks values : as the vectors can potentially contain NaN values, we must use a
|
|
51
|
QVERIFY(scalarSeries->xAxisData()->data() == m_XAxisData);
|
|
71
|
// custom vector comparison method
|
|
52
|
QVERIFY(scalarSeries->valuesData()->data() == m_ValuesData);
|
|
72
|
QVERIFY(compareVectors(scalarSeries->xAxisData()->data(), m_XAxisData));
|
|
|
|
|
73
|
QVERIFY(compareVectors(scalarSeries->valuesData()->data(), m_ValuesData));
|
|
53
|
}
|
|
74
|
}
|
|
54
|
else {
|
|
75
|
else {
|
|
55
|
QVERIFY(results == nullptr);
|
|
76
|
QVERIFY(results == nullptr);
|
|
@@
-102,7
+123,7
void TestAmdaResultParser::testReadTxt_data()
|
|
102
|
return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
|
|
123
|
return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
|
|
103
|
};
|
|
124
|
};
|
|
104
|
|
|
125
|
|
|
105
|
// Valid file
|
|
126
|
// Valid files
|
|
106
|
QTest::newRow("Valid file")
|
|
127
|
QTest::newRow("Valid file")
|
|
107
|
<< QStringLiteral("ValidScalar1.txt")
|
|
128
|
<< QStringLiteral("ValidScalar1.txt")
|
|
108
|
<< ExpectedResults{
|
|
129
|
<< ExpectedResults{
|
|
@@
-115,6
+136,22
void TestAmdaResultParser::testReadTxt_data()
|
|
115
|
QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
|
|
136
|
QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
|
|
116
|
-2.55800, -2.43250, -2.42200}};
|
|
137
|
-2.55800, -2.43250, -2.42200}};
|
|
117
|
|
|
138
|
|
|
|
|
|
139
|
QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN")
|
|
|
|
|
140
|
<< QStringLiteral("WrongValue.txt")
|
|
|
|
|
141
|
<< ExpectedResults{
|
|
|
|
|
142
|
Unit{QStringLiteral("nT"), true}, Unit{},
|
|
|
|
|
143
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
|
|
|
|
|
144
|
dateTime(2013, 9, 23, 9, 2, 30)},
|
|
|
|
|
145
|
QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}};
|
|
|
|
|
146
|
|
|
|
|
|
147
|
QTest::newRow("Valid file that contains NaN values")
|
|
|
|
|
148
|
<< QStringLiteral("NaNValue.txt")
|
|
|
|
|
149
|
<< ExpectedResults{
|
|
|
|
|
150
|
Unit{QStringLiteral("nT"), true}, Unit{},
|
|
|
|
|
151
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30),
|
|
|
|
|
152
|
dateTime(2013, 9, 23, 9, 2, 30)},
|
|
|
|
|
153
|
QVector<double>{std::numeric_limits<double>::quiet_NaN(), -2.71850, -2.52150}};
|
|
|
|
|
154
|
|
|
118
|
// Valid files but with some invalid lines (wrong unit, wrong values, etc.)
|
|
155
|
// Valid files but with some invalid lines (wrong unit, wrong values, etc.)
|
|
119
|
QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt")
|
|
156
|
QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt")
|
|
120
|
<< ExpectedResults{Unit{QStringLiteral(""), true}, Unit{},
|
|
157
|
<< ExpectedResults{Unit{QStringLiteral(""), true}, Unit{},
|
|
@@
-141,15
+178,8
void TestAmdaResultParser::testReadTxt_data()
|
|
141
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
|
|
178
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
|
|
142
|
QVector<double>{-2.71850, -2.52150}};
|
|
179
|
QVector<double>{-2.71850, -2.52150}};
|
|
143
|
|
|
180
|
|
|
144
|
QTest::newRow("Wrong results file (value of first line is invalid")
|
|
181
|
QTest::newRow("Wrong results file (x of first line is NaN")
|
|
145
|
<< QStringLiteral("WrongValue.txt")
|
|
182
|
<< QStringLiteral("NaNX.txt")
|
|
146
|
<< ExpectedResults{
|
|
|
|
|
147
|
Unit{QStringLiteral("nT"), true}, Unit{},
|
|
|
|
|
148
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
|
|
|
|
|
149
|
QVector<double>{-2.71850, -2.52150}};
|
|
|
|
|
150
|
|
|
|
|
|
151
|
QTest::newRow("Wrong results file (value of first line is NaN")
|
|
|
|
|
152
|
<< QStringLiteral("NaNValue.txt")
|
|
|
|
|
153
|
<< ExpectedResults{
|
|
183
|
<< ExpectedResults{
|
|
154
|
Unit{QStringLiteral("nT"), true}, Unit{},
|
|
184
|
Unit{QStringLiteral("nT"), true}, Unit{},
|
|
155
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
|
|
185
|
QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
|