From d4548d8f520645614fac0cc8d23d44f0ce66672e 2017-11-22 16:57:11 From: Alexandre Leroux Date: 2017-11-22 16:57:11 Subject: [PATCH] Merge branch 'feature/AmdaSpectroTests' into develop --- diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/InvalidSpectrogramWrongBands.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/InvalidSpectrogramWrongBands.txt new file mode 100644 index 0000000..4749d9f --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/InvalidSpectrogramWrongBands.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 5.00000,6.50000,8.70000,11.4000 +# PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000 +# PARAMETER_FILL_VALUE : nan +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T10:35:07.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2] +# +2012-11-06T09:14:35.000 16313.780 15405.838 8946.475 +2012-11-06T09:16:10.000 12631.465 11957.925 18133.158 +2012-11-06T09:17:45.000 8223.368 15026.249 10875.621 +2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 +2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram1.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram1.txt new file mode 100644 index 0000000..53737ce --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram1.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 5.00000,6.50000,8.70000 +# PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000 +# PARAMETER_FILL_VALUE : nan +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T09:21:00.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2] +# +2012-11-06T09:14:35.000 16313.780 15405.838 8946.475 +2012-11-06T09:16:10.000 12631.465 11957.925 18133.158 +2012-11-06T09:17:45.000 8223.368 15026.249 10875.621 +2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 +2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram2.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram2.txt new file mode 100644 index 0000000..609650f --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram2.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 5.00000,6.50000,8.70000,11.4000 +# PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000,14.6000 +# PARAMETER_FILL_VALUE : nan +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T09:21:00.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3] +# +2012-11-06T09:14:35.000 16313.780 15405.838 8946.475 20907.664 +2012-11-06T09:16:10.000 12631.465 11957.925 18133.158 32076.725 +2012-11-06T09:17:45.000 8223.368 15026.249 10875.621 13008.381 +2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 13142.759 +2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 23226.998 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram3.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram3.txt new file mode 100644 index 0000000..d726d7e --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogram3.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 8.70000,6.50000,11.4000,5.00000 +# PARAMETER_TABLE_MAX_VALUES[0] : 11.4000,8.70000,14.6000,6.50000 +# PARAMETER_FILL_VALUE : nan +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T09:21:00.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3] +# +2012-11-06T09:14:35.000 8946.475 15405.838 20907.664 16313.780 +2012-11-06T09:16:10.000 18133.158 11957.925 32076.725 12631.465 +2012-11-06T09:17:45.000 10875.621 15026.249 13008.381 8223.368 +2012-11-06T09:19:20.000 24051.619 25617.533 13142.759 27595.301 +2012-11-06T09:20:55.000 19283.221 11179.109 23226.998 12820.613 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramFillValues.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramFillValues.txt new file mode 100644 index 0000000..86b6b82 --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramFillValues.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 5.00000,6.50000,8.70000,11.4000 +# PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000,14.6000 +# PARAMETER_FILL_VALUE : -1. +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T09:21:00.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3] +# +2012-11-06T09:14:35.000 -1.000 15405.838 8946.475 -1.000 +2012-11-06T09:16:10.000 12631.465 -1.000 18133.158 -1.000 +2012-11-06T09:17:45.000 8223.368 -1.000 10875.621 -1.000 +2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 -1.000 +2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 -1.000 \ No newline at end of file diff --git a/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramNaNValues.txt b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramNaNValues.txt new file mode 100644 index 0000000..a5178ca --- /dev/null +++ b/plugins/amda/tests-resources/TestAmdaResultParser/spectro/ValidSpectrogramNaNValues.txt @@ -0,0 +1,59 @@ +# ----------- +# AMDA INFO : +# ----------- +# AMDA_ABOUT : Created by CDPP/AMDA(c) +# AMDA_VERSION : 3.5.0 +# AMDA_ACKNOWLEDGEMENT : CDPP/AMDA Team +# +# -------------- +# REQUEST INFO : +# -------------- +# REQUEST_STRUCTURE : one-file-per-parameter-per-interval +# REQUEST_TIME_FORMAT : ISO 8601 +# REQUEST_OUTPUT_PARAMS : tha_ion_sp +# +# ----------------- +# BASE PARAMETERS : +# ----------------- +# +# MISSION_ID : NONE +# +# INSTRUMENT_ID : NONE +# +# DATASET_ID : tha-esa-l2i +# DATASET_NAME : ion full mode +# DATASET_SOURCE : CDPP/DDServer +# DATASET_GLOBAL_START : 2007-03-07T18:53:59.134 +# DATASET_GLOBAL_STOP : 2017-11-04T18:35:25.907 +# DATASET_MIN_SAMPLING : 96 +# DATASET_MAX_SAMPLING : 385 +# +# PARAMETER_ID : tha_ion_sp +# PARAMETER_NAME : tha_ion_sp +# PARAMETER_SHORT_NAME : spectra +# PARAMETER_UNITS : eV/(cm^2-s-sr-eV) +# PARAMETER_TENSOR_ORDER : 0 +# PARAMETER_TABLE[0] : energy +# PARAMETER_TABLE_UNITS[0] : eV +# PARAMETER_TABLE_MIN_VALUES[0] : 5.00000,6.50000,8.70000,11.4000 +# PARAMETER_TABLE_MAX_VALUES[0] : 6.50000,8.70000,11.4000,14.6000 +# PARAMETER_FILL_VALUE : nan +# PARAMETER_UCD : phys.flux.density;phys.energy;phys.atmol.ionStage +# +# +# --------------- +# INTERVAL INFO : +# --------------- +# INTERVAL_START : 2012-11-06T09:13:31.000 +# INTERVAL_STOP : 2012-11-06T09:21:00.000 +# +# ------ +# DATA : +# ------ +# DATA_COLUMNS : AMDA_TIME, tha_ion_sp[0], tha_ion_sp[1], tha_ion_sp[2], tha_ion_sp[3] +# +2012-11-06T09:14:35.000 nan 15405.838 8946.475 nan +2012-11-06T09:16:10.000 12631.465 nan 18133.158 nan +2012-11-06T09:17:45.000 8223.368 nan 10875.621 nan +2012-11-06T09:19:20.000 27595.301 25617.533 24051.619 nan +2012-11-06T09:20:55.000 12820.613 11179.109 19283.221 nan \ No newline at end of file diff --git a/plugins/amda/tests/TestAmdaResultParser.cpp b/plugins/amda/tests/TestAmdaResultParser.cpp index e51de2b..8aa3ad8 100644 --- a/plugins/amda/tests/TestAmdaResultParser.cpp +++ b/plugins/amda/tests/TestAmdaResultParser.cpp @@ -1,6 +1,7 @@ #include "AmdaResultParser.h" #include +#include #include #include @@ -24,27 +25,65 @@ 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; + } + + ExpectedResults &setYAxisEnabled(bool yAxisEnabled) + { + m_YAxisEnabled = yAxisEnabled; + return *this; + } + + ExpectedResults &setYAxisUnit(Unit yAxisUnit) + { + m_YAxisUnit = std::move(yAxisUnit); + return *this; + } + + ExpectedResults &setYAxisData(QVector yAxisData) + { + m_YAxisData = std::move(yAxisData); + return *this; } /** @@ -86,6 +125,22 @@ struct ExpectedResults { return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; }); } + + // Checks y-axis (if defined) + auto yAxis = dataSeries->yAxis(); + QCOMPARE(yAxis.isDefined(), m_YAxisEnabled); + + if (m_YAxisEnabled) { + // Unit + QCOMPARE(yAxis.unit(), m_YAxisUnit); + + // Data + auto yAxisSize = yAxis.size(); + QCOMPARE(yAxisSize, m_YAxisData.size()); + for (auto i = 0; i < yAxisSize; ++i) { + QCOMPARE(yAxis.at(i), m_YAxisData.at(i)); + } + } } else { QVERIFY(results == nullptr); @@ -96,17 +151,24 @@ 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{}; + // Expected data series has y-axis + bool m_YAxisEnabled{false}; + // Expected y-axis unit (if axis defined) + Unit m_YAxisUnit{}; + // Expected y-axis data (if axis defined) + QVector m_YAxisData{}; }; } // namespace Q_DECLARE_METATYPE(ExpectedResults) +Q_DECLARE_METATYPE(ExpectedResults) Q_DECLARE_METATYPE(ExpectedResults) class TestAmdaResultParser : public QObject { @@ -150,6 +212,13 @@ private slots: void testReadScalarTxt(); /// Input test data + /// @sa testReadSpectrogramTxt() + void testReadSpectrogramTxt_data(); + + /// Tests parsing spectrogram series of a TXT file + void testReadSpectrogramTxt(); + + /// Input test data /// @sa testReadVectorTxt() void testReadVectorTxt_data(); @@ -168,77 +237,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() @@ -246,6 +323,91 @@ void TestAmdaResultParser::testReadScalarTxt() testRead(AmdaResultParser::ValueType::SCALAR); } +void TestAmdaResultParser::testReadSpectrogramTxt_data() +{ + testReadDataStructure(); + + // ////////// // + // Test cases // + // ////////// // + + // Valid files + QTest::newRow("Valid file (three bands)") + << QStringLiteral("spectro/ValidSpectrogram1.txt") + << ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"t", true}) + .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), + dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), + dateTime(2012, 11, 6, 9, 20, 55)}) + .setYAxisEnabled(true) + .setYAxisUnit(Unit{"eV"}) + .setYAxisData({5.75, 7.6, 10.05}) // middle of the intervals of each band + .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) + .setValuesData(QVector >{ + {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, + {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, + {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}}); + + auto fourBandsResult + = ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"t", true}) + .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), + dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), + dateTime(2012, 11, 6, 9, 20, 55)}) + .setYAxisEnabled(true) + .setYAxisUnit(Unit{"eV"}) + .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band + .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) + .setValuesData(QVector >{ + {16313.780, 12631.465, 8223.368, 27595.301, 12820.613}, + {15405.838, 11957.925, 15026.249, 25617.533, 11179.109}, + {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, + {20907.664, 32076.725, 13008.381, 13142.759, 23226.998}}); + + QTest::newRow("Valid file (four bands)") + << QStringLiteral("spectro/ValidSpectrogram2.txt") << fourBandsResult; + QTest::newRow("Valid file (four unsorted bands)") + << QStringLiteral("spectro/ValidSpectrogram3.txt") + << fourBandsResult; // Bands and values are sorted + + auto nan = std::numeric_limits::quiet_NaN(); + + auto nanValuesResult + = ExpectedResults{} + .setParsingOK(true) + .setXAxisUnit(Unit{"t", true}) + .setXAxisData({dateTime(2012, 11, 6, 9, 14, 35), dateTime(2012, 11, 6, 9, 16, 10), + dateTime(2012, 11, 6, 9, 17, 45), dateTime(2012, 11, 6, 9, 19, 20), + dateTime(2012, 11, 6, 9, 20, 55)}) + .setYAxisEnabled(true) + .setYAxisUnit(Unit{"eV"}) + .setYAxisData({5.75, 7.6, 10.05, 13.}) // middle of the intervals of each band + .setValuesUnit(Unit{"eV/(cm^2-s-sr-eV)"}) + .setValuesData( + QVector >{{nan, 12631.465, 8223.368, 27595.301, 12820.613}, + {15405.838, nan, nan, 25617.533, 11179.109}, + {8946.475, 18133.158, 10875.621, 24051.619, 19283.221}, + {nan, nan, nan, nan, nan}}); + + QTest::newRow("Valid file (containing NaN values)") + << QStringLiteral("spectro/ValidSpectrogramNaNValues.txt") << nanValuesResult; + QTest::newRow("Valid file (containing fill values)") + << QStringLiteral("spectro/ValidSpectrogramFillValues.txt") + << nanValuesResult; // Fill values are replaced by NaN values in the data series + + // Invalid files + QTest::newRow("Invalid file (inconsistent bands)") + << QStringLiteral("spectro/InvalidSpectrogramWrongBands.txt") + << ExpectedResults{}.setParsingOK(false); +} + +void TestAmdaResultParser::testReadSpectrogramTxt() +{ + testRead(AmdaResultParser::ValueType::SPECTROGRAM); +} + void TestAmdaResultParser::testReadVectorTxt_data() { testReadDataStructure(); @@ -257,24 +419,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()