##// END OF EJS Templates
Units tests structure
Alexandre Leroux -
r396:4c5c8ac48250
parent child
Show More
@@ -1,63 +1,69
1 1 #ifndef SCIQLOP_IDATASERIES_H
2 2 #define SCIQLOP_IDATASERIES_H
3 3
4 4 #include <Common/MetaTypes.h>
5 5
6 6 #include <memory>
7 7
8 8 #include <QString>
9 9
10 10 template <int Dim>
11 11 class ArrayData;
12 12
13 13 struct Unit {
14 14 explicit Unit(const QString &name = {}, bool timeUnit = false)
15 15 : m_Name{name}, m_TimeUnit{timeUnit}
16 16 {
17 17 }
18 18
19 inline bool operator==(const Unit &other) const
20 {
21 return std::tie(m_Name, m_TimeUnit) == std::tie(other.m_Name, other.m_TimeUnit);
22 }
23 inline bool operator!=(const Unit &other) const { return !(*this == other); }
24
19 25 QString m_Name; ///< Unit name
20 26 bool m_TimeUnit; ///< The unit is a unit of time
21 27 };
22 28
23 29 /**
24 30 * @brief The IDataSeries aims to declare a data series.
25 31 *
26 32 * A data series is an entity that contains at least :
27 33 * - one dataset representing the x-axis
28 34 * - one dataset representing the values
29 35 *
30 36 * Each dataset is represented by an ArrayData, and is associated with a unit.
31 37 *
32 38 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
33 39 * IDataSeries. The x-axis dataset is always unidimensional.
34 40 *
35 41 * @sa ArrayData
36 42 */
37 43 class IDataSeries {
38 44 public:
39 45 virtual ~IDataSeries() noexcept = default;
40 46
41 47 /// Returns the x-axis dataset
42 48 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
43 49
44 50 /// Returns the x-axis dataset (as const)
45 51 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
46 52
47 53 virtual Unit xAxisUnit() const = 0;
48 54
49 55 virtual Unit valuesUnit() const = 0;
50 56
51 57 virtual void merge(IDataSeries *dataSeries) = 0;
52 58
53 59 virtual std::unique_ptr<IDataSeries> clone() const = 0;
54 60
55 61 virtual void lockRead() = 0;
56 62 virtual void lockWrite() = 0;
57 63 virtual void unlock() = 0;
58 64 };
59 65
60 66 // Required for using shared_ptr in signals/slots
61 67 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
62 68
63 69 #endif // SCIQLOP_IDATASERIES_H
@@ -1,39 +1,113
1 1 #include "AmdaResultParser.h"
2 2
3 3 #include <QObject>
4 4 #include <QtTest>
5 5
6 6 namespace {
7 7
8 8 /// Path for the tests
9 9 const auto TESTS_RESOURCES_PATH
10 10 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
11 11
12 12 QString inputFilePath(const QString &inputFileName)
13 13 {
14 14 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
15 15 }
16 16
17 struct ExpectedResults {
18 explicit ExpectedResults() = default;
19
20 /// Ctor with QVector<QDateTime> as x-axis data. Datetimes are converted to doubles
21 explicit ExpectedResults(Unit xAxisUnit, Unit valuesUnit, const QVector<QDateTime> &xAxisData,
22 QVector<double> valuesData)
23 : m_ParsingOK{true},
24 m_XAxisUnit{xAxisUnit},
25 m_ValuesUnit{valuesUnit},
26 m_XAxisData{},
27 m_ValuesData{std::move(valuesData)}
28 {
29 // Converts QVector<QDateTime> to QVector<double>
30 std::transform(xAxisData.cbegin(), xAxisData.cend(), std::back_inserter(m_XAxisData),
31 [](const auto &dateTime) { return dateTime.toMSecsSinceEpoch() / 1000.; });
32 }
33
34 /**
35 * Validates a DataSeries compared to the expected results
36 * @param results the DataSeries to validate
37 */
38 void validate(std::shared_ptr<IDataSeries> results)
39 {
40 if (m_ParsingOK) {
41 auto scalarSeries = dynamic_cast<ScalarSeries *>(results.get());
42 QVERIFY(scalarSeries != nullptr);
43
44 // Checks units
45 QVERIFY(scalarSeries->xAxisUnit() == m_XAxisUnit);
46 QVERIFY(scalarSeries->valuesUnit() == m_ValuesUnit);
47
48 // Checks values
49 QVERIFY(scalarSeries->xAxisData()->data() == m_XAxisData);
50 QVERIFY(scalarSeries->valuesData()->data() == m_ValuesData);
51 }
52 else {
53 QVERIFY(results == nullptr);
54 }
55 }
56
57 // Parsing was successfully completed
58 bool m_ParsingOK{false};
59 // Expected x-axis unit
60 Unit m_XAxisUnit{};
61 // Expected values unit
62 Unit m_ValuesUnit{};
63 // Expected x-axis data
64 QVector<double> m_XAxisData{};
65 // Expected values data
66 QVector<double> m_ValuesData{};
67 };
68
17 69 } // namespace
18 70
71 Q_DECLARE_METATYPE(ExpectedResults)
72
19 73 class TestAmdaResultParser : public QObject {
20 74 Q_OBJECT
21 75 private slots:
22 76 /// Input test data
23 77 /// @sa testTxtJson()
24 78 void testReadTxt_data();
25 79
26 80 /// Tests parsing of a TXT file
27 81 void testReadTxt();
28 82 };
29 83
30 84 void TestAmdaResultParser::testReadTxt_data()
31 85 {
86 // ////////////// //
87 // Test structure //
88 // ////////////// //
89
90 // Name of TXT file to read
91 QTest::addColumn<QString>("inputFileName");
92 // Expected results
93 QTest::addColumn<ExpectedResults>("expectedResults");
94
32 95 }
33 96
34 97 void TestAmdaResultParser::testReadTxt()
35 98 {
99 QFETCH(QString, inputFileName);
100 QFETCH(ExpectedResults, expectedResults);
101
102 // Parses file
103 auto filePath = inputFilePath(inputFileName);
104 auto results = AmdaResultParser::readTxt(filePath);
105
106 // ///////////////// //
107 // Validates results //
108 // ///////////////// //
109 expectedResults.validate(results);
36 110 }
37 111
38 112 QTEST_MAIN(TestAmdaResultParser)
39 113 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now