##// END OF EJS Templates
Updates unit tests to handle NaN values...
Alexandre Leroux -
r458:59327bc75bab
parent child
Show More
@@ -0,0 +1,6
1 #Sampling Time : 60
2 #Time Format : YYYY-MM-DDThh:mm:ss.mls
3 #imf(0) - Type : Local Parameter @ CDPP/AMDA - Name : bx_gse - Units : nT - Size : 1 - Frame : GSE - Mission : ACE - Instrument : MFI - Dataset : mfi_final-prelim
4 NaN -3.01425
5 2013-09-23T09:01:30.000 -2.71850
6 2013-09-23T09:02:30.000 -2.52150 No newline at end of file
@@ -11,6 +11,26 namespace {
11 11 const auto TESTS_RESOURCES_PATH
12 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 34 QString inputFilePath(const QString &inputFileName)
15 35 {
16 36 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
@@ -47,9 +67,10 struct ExpectedResults {
47 67 QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit);
48 68 QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit);
49 69
50 // Checks values
51 QVERIFY(scalarSeries->xAxisData()->data() == m_XAxisData);
52 QVERIFY(scalarSeries->valuesData()->data() == m_ValuesData);
70 // Checks values : as the vectors can potentially contain NaN values, we must use a
71 // custom vector comparison method
72 QVERIFY(compareVectors(scalarSeries->xAxisData()->data(), m_XAxisData));
73 QVERIFY(compareVectors(scalarSeries->valuesData()->data(), m_ValuesData));
53 74 }
54 75 else {
55 76 QVERIFY(results == nullptr);
@@ -102,7 +123,7 void TestAmdaResultParser::testReadTxt_data()
102 123 return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC};
103 124 };
104 125
105 // Valid file
126 // Valid files
106 127 QTest::newRow("Valid file")
107 128 << QStringLiteral("ValidScalar1.txt")
108 129 << ExpectedResults{
@@ -115,6 +136,22 void TestAmdaResultParser::testReadTxt_data()
115 136 QVector<double>{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025,
116 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 155 // Valid files but with some invalid lines (wrong unit, wrong values, etc.)
119 156 QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt")
120 157 << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{},
@@ -141,15 +178,8 void TestAmdaResultParser::testReadTxt_data()
141 178 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
142 179 QVector<double>{-2.71850, -2.52150}};
143 180
144 QTest::newRow("Wrong results file (value of first line is invalid")
145 << QStringLiteral("WrongValue.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")
181 QTest::newRow("Wrong results file (x of first line is NaN")
182 << QStringLiteral("NaNX.txt")
153 183 << ExpectedResults{
154 184 Unit{QStringLiteral("nT"), true}, Unit{},
155 185 QVector<QDateTime>{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)},
General Comments 0
You need to be logged in to leave comments. Login now