##// END OF EJS Templates
Units tests structure
Alexandre Leroux -
r365:4c5c8ac48250
parent child
Show More
@@ -1,63 +1,69
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <Common/MetaTypes.h>
4 #include <Common/MetaTypes.h>
5
5
6 #include <memory>
6 #include <memory>
7
7
8 #include <QString>
8 #include <QString>
9
9
10 template <int Dim>
10 template <int Dim>
11 class ArrayData;
11 class ArrayData;
12
12
13 struct Unit {
13 struct Unit {
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
15 : m_Name{name}, m_TimeUnit{timeUnit}
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 QString m_Name; ///< Unit name
25 QString m_Name; ///< Unit name
20 bool m_TimeUnit; ///< The unit is a unit of time
26 bool m_TimeUnit; ///< The unit is a unit of time
21 };
27 };
22
28
23 /**
29 /**
24 * @brief The IDataSeries aims to declare a data series.
30 * @brief The IDataSeries aims to declare a data series.
25 *
31 *
26 * A data series is an entity that contains at least :
32 * A data series is an entity that contains at least :
27 * - one dataset representing the x-axis
33 * - one dataset representing the x-axis
28 * - one dataset representing the values
34 * - one dataset representing the values
29 *
35 *
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
36 * Each dataset is represented by an ArrayData, and is associated with a unit.
31 *
37 *
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
38 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
33 * IDataSeries. The x-axis dataset is always unidimensional.
39 * IDataSeries. The x-axis dataset is always unidimensional.
34 *
40 *
35 * @sa ArrayData
41 * @sa ArrayData
36 */
42 */
37 class IDataSeries {
43 class IDataSeries {
38 public:
44 public:
39 virtual ~IDataSeries() noexcept = default;
45 virtual ~IDataSeries() noexcept = default;
40
46
41 /// Returns the x-axis dataset
47 /// Returns the x-axis dataset
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
48 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
43
49
44 /// Returns the x-axis dataset (as const)
50 /// Returns the x-axis dataset (as const)
45 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
51 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
46
52
47 virtual Unit xAxisUnit() const = 0;
53 virtual Unit xAxisUnit() const = 0;
48
54
49 virtual Unit valuesUnit() const = 0;
55 virtual Unit valuesUnit() const = 0;
50
56
51 virtual void merge(IDataSeries *dataSeries) = 0;
57 virtual void merge(IDataSeries *dataSeries) = 0;
52
58
53 virtual std::unique_ptr<IDataSeries> clone() const = 0;
59 virtual std::unique_ptr<IDataSeries> clone() const = 0;
54
60
55 virtual void lockRead() = 0;
61 virtual void lockRead() = 0;
56 virtual void lockWrite() = 0;
62 virtual void lockWrite() = 0;
57 virtual void unlock() = 0;
63 virtual void unlock() = 0;
58 };
64 };
59
65
60 // Required for using shared_ptr in signals/slots
66 // Required for using shared_ptr in signals/slots
61 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
67 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
62
68
63 #endif // SCIQLOP_IDATASERIES_H
69 #endif // SCIQLOP_IDATASERIES_H
@@ -1,39 +1,113
1 #include "AmdaResultParser.h"
1 #include "AmdaResultParser.h"
2
2
3 #include <QObject>
3 #include <QObject>
4 #include <QtTest>
4 #include <QtTest>
5
5
6 namespace {
6 namespace {
7
7
8 /// Path for the tests
8 /// Path for the tests
9 const auto TESTS_RESOURCES_PATH
9 const auto TESTS_RESOURCES_PATH
10 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
10 = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaResultParser"}.absoluteFilePath();
11
11
12 QString inputFilePath(const QString &inputFileName)
12 QString inputFilePath(const QString &inputFileName)
13 {
13 {
14 return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath();
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 } // namespace
69 } // namespace
18
70
71 Q_DECLARE_METATYPE(ExpectedResults)
72
19 class TestAmdaResultParser : public QObject {
73 class TestAmdaResultParser : public QObject {
20 Q_OBJECT
74 Q_OBJECT
21 private slots:
75 private slots:
22 /// Input test data
76 /// Input test data
23 /// @sa testTxtJson()
77 /// @sa testTxtJson()
24 void testReadTxt_data();
78 void testReadTxt_data();
25
79
26 /// Tests parsing of a TXT file
80 /// Tests parsing of a TXT file
27 void testReadTxt();
81 void testReadTxt();
28 };
82 };
29
83
30 void TestAmdaResultParser::testReadTxt_data()
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 void TestAmdaResultParser::testReadTxt()
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 QTEST_MAIN(TestAmdaResultParser)
112 QTEST_MAIN(TestAmdaResultParser)
39 #include "TestAmdaResultParser.moc"
113 #include "TestAmdaResultParser.moc"
General Comments 0
You need to be logged in to leave comments. Login now