@@ -16,6 +16,12 struct Unit { | |||||
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 | }; |
@@ -14,8 +14,62 QString inputFilePath(const QString &inputFileName) | |||||
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: | |
@@ -29,10 +83,30 private slots: | |||||
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) |
General Comments 0
You need to be logged in to leave comments.
Login now