diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index e51de2b..48e30b3 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -24,27 +24,47 @@ QString inputFilePath(const QString &inputFileName) template struct ExpectedResults { - explicit ExpectedResults() = default; - explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector &xAxisData, - QVector valuesData) - : ExpectedResults(xAxisUnit, valuesUnit, xAxisData, - QVector >{std::move(valuesData)}) + ExpectedResults &setParsingOK(bool parsingOK) { + m_ParsingOK = parsingOK; + return *this; } - /// Ctor with QVector as x-axis data. Datetimes are converted to doubles - explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector &xAxisData, - QVector > valuesData) - : m_ParsingOK{true}, - m_XAxisUnit{xAxisUnit}, - m_ValuesUnit{valuesUnit}, - m_XAxisData{}, - m_ValuesData{std::move(valuesData)} + ExpectedResults &setXAxisUnit(Unit xAxisUnit) { + m_XAxisUnit = std::move(xAxisUnit); + return *this; + } + + ExpectedResults &setXAxisData(const QVector &xAxisData) + { + m_XAxisData.clear(); + // Converts QVector to QVector std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData), [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; }); + + return *this; + } + + ExpectedResults &setValuesUnit(Unit valuesUnit) + { + m_ValuesUnit = std::move(valuesUnit); + return *this; + } + + ExpectedResults &setValuesData(QVector valuesData) + { + m_ValuesData.clear(); + m_ValuesData.push_back(std::move(valuesData)); + return *this; + } + + ExpectedResults &setValuesData(QVector > valuesData) + { + m_ValuesData = std::move(valuesData); + return *this; } /** @@ -96,10 +116,10 @@ struct ExpectedResults { bool m_ParsingOK{false}; // Expected x-axis unit Unit m_XAxisUnit{}; - // Expected values unit - Unit m_ValuesUnit{}; // Expected x-axis data QVector m_XAxisData{}; + // Expected values unit + Unit m_ValuesUnit{}; // Expected values data QVector > m_ValuesData{}; }; @@ -168,77 +188,85 @@ void TestAmdaResultParser::testReadScalarTxt_data() // Valid files QTest::newRow("Valid file") << QStringLiteral("ValidScalar1.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), - dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), - dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), - dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), - dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}, - QVector{-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, - -2.55800, -2.43250, -2.42200}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30), dateTime(2013, 9, 23, 9, 3, 30), + dateTime(2013, 9, 23, 9, 4, 30), dateTime(2013, 9, 23, 9, 5, 30), + dateTime(2013, 9, 23, 9, 6, 30), dateTime(2013, 9, 23, 9, 7, 30), + dateTime(2013, 9, 23, 9, 8, 30), dateTime(2013, 9, 23, 9, 9, 30)}) + .setValuesData({-2.83950, -2.71850, -2.52150, -2.57633, -2.58050, -2.48325, -2.63025, + -2.55800, -2.43250, -2.42200}); QTest::newRow("Valid file (value of first line is invalid but it is converted to NaN") << QStringLiteral("WrongValue.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), - dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{std::numeric_limits::quiet_NaN(), -2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({std::numeric_limits::quiet_NaN(), -2.71850, -2.52150}); QTest::newRow("Valid file that contains NaN values") << QStringLiteral("NaNValue.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), - dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{std::numeric_limits::quiet_NaN(), -2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{("nT"), true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({std::numeric_limits::quiet_NaN(), -2.71850, -2.52150}); // Valid files but with some invalid lines (wrong unit, wrong values, etc.) - QTest::newRow("No unit file") << QStringLiteral("NoUnit.txt") - << ExpectedResults{Unit{QStringLiteral(""), true}, - Unit{}, QVector{}, - QVector{}}; + QTest::newRow("No unit file") + << QStringLiteral("NoUnit.txt") + << ExpectedResults{}.setParsingOK(true).setXAxisUnit(Unit{"", true}); + QTest::newRow("Wrong unit file") << QStringLiteral("WrongUnit.txt") - << ExpectedResults{Unit{QStringLiteral(""), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 0, 30), - dateTime(2013, 9, 23, 9, 1, 30), - dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{-2.83950, -2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 0, 30), dateTime(2013, 9, 23, 9, 1, 30), + dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({-2.83950, -2.71850, -2.52150}); QTest::newRow("Wrong results file (date of first line is invalid") << QStringLiteral("WrongDate.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{-2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({-2.71850, -2.52150}); QTest::newRow("Wrong results file (too many values for first line") << QStringLiteral("TooManyValues.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{-2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({-2.71850, -2.52150}); QTest::newRow("Wrong results file (x of first line is NaN") << QStringLiteral("NaNX.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}, - QVector{-2.71850, -2.52150}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 9, 23, 9, 1, 30), dateTime(2013, 9, 23, 9, 2, 30)}) + .setValuesData({-2.71850, -2.52150}); QTest::newRow("Invalid file type (vector)") << QStringLiteral("ValidVector1.txt") - << ExpectedResults{Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{}, QVector{}}; + << ExpectedResults{}.setParsingOK(true).setXAxisUnit(Unit{"nT", true}); // Invalid files - QTest::newRow("Invalid file (unexisting file)") << QStringLiteral("UnexistingFile.txt") - << ExpectedResults{}; + QTest::newRow("Invalid file (unexisting file)") + << QStringLiteral("UnexistingFile.txt") + << ExpectedResults{}.setParsingOK(false); - QTest::newRow("Invalid file (file not found on server)") << QStringLiteral("FileNotFound.txt") - << ExpectedResults{}; + QTest::newRow("Invalid file (file not found on server)") + << QStringLiteral("FileNotFound.txt") + << ExpectedResults{}.setParsingOK(false); } void TestAmdaResultParser::testReadScalarTxt() @@ -257,24 +285,27 @@ void TestAmdaResultParser::testReadVectorTxt_data() // Valid files QTest::newRow("Valid file") << QStringLiteral("ValidVector1.txt") - << ExpectedResults{ - Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), - dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), - dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), - dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), - dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}, - QVector >{ - {-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, - {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, - {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({dateTime(2013, 7, 2, 9, 13, 50), dateTime(2013, 7, 2, 9, 14, 6), + dateTime(2013, 7, 2, 9, 14, 22), dateTime(2013, 7, 2, 9, 14, 38), + dateTime(2013, 7, 2, 9, 14, 54), dateTime(2013, 7, 2, 9, 15, 10), + dateTime(2013, 7, 2, 9, 15, 26), dateTime(2013, 7, 2, 9, 15, 42), + dateTime(2013, 7, 2, 9, 15, 58), dateTime(2013, 7, 2, 9, 16, 14)}) + .setValuesData( + {{-0.332, -1.011, -1.457, -1.293, -1.217, -1.443, -1.278, -1.202, -1.22, -1.259}, + {3.206, 2.999, 2.785, 2.736, 2.612, 2.564, 2.892, 2.862, 2.859, 2.764}, + {0.058, 0.496, 1.018, 1.485, 1.662, 1.505, 1.168, 1.244, 1.15, 1.358}}); // Valid files but with some invalid lines (wrong unit, wrong values, etc.) QTest::newRow("Invalid file type (scalar)") << QStringLiteral("ValidScalar1.txt") - << ExpectedResults{Unit{QStringLiteral("nT"), true}, Unit{}, - QVector{}, - QVector >{{}, {}, {}}}; + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"nT", true}) + .setXAxisData({}) + .setValuesData(QVector >{{}, {}, {}}); } void TestAmdaResultParser::testReadVectorTxt()