##// END OF EJS Templates
Implements unit test (3)...
Alexandre Leroux -
r689:e4699d579435
parent child
Show More
@@ -33,8 +33,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
33 33 std::swap(start, end);
34 34 }
35 35
36 // Generates scalar series containing cosinus values (one value per second)
37 auto dataCount = end - start;
36 // Generates scalar series containing cosinus values (one value per second, end value is
37 // included)
38 auto dataCount = end - start + 1;
38 39
39 40 auto xAxisData = std::vector<double>{};
40 41 xAxisData.resize(dataCount);
@@ -44,7 +45,7 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(QUuid acqIdentifier,
44 45
45 46 int progress = 0;
46 47 auto progressEnd = dataCount;
47 for (auto time = start; time < end; ++time, ++dataIndex) {
48 for (auto time = start; time <= end; ++time, ++dataIndex) {
48 49 auto it = m_VariableToEnableProvider.find(acqIdentifier);
49 50 if (it != m_VariableToEnableProvider.end() && it.value()) {
50 51 const auto timeOnFreq = time / freq;
@@ -26,6 +26,33 const auto DATETIME_FORMAT = QStringLiteral("yyyy/MM/dd hh:mm:ss:zzz");
26 26 /// Delay after each operation on the variable before validating it (in ms)
27 27 const auto OPERATION_DELAY = 250;
28 28
29 /**
30 * Verifies that the data in the candidate series are identical to the data in the reference series
31 * in a specific range
32 * @param candidate the candidate data series
33 * @param range the range to check
34 * @param reference the reference data series
35 * @return true if the data of the candidate series and the reference series are identical in the
36 * range, false otherwise
37 */
38 bool checkDataSeries(std::shared_ptr<IDataSeries> candidate, const SqpRange &range,
39 std::shared_ptr<IDataSeries> reference)
40 {
41 if (candidate == nullptr || reference == nullptr) {
42 return candidate == reference;
43 }
44
45 auto referenceIt = reference->xAxisRange(range.m_TStart, range.m_TEnd);
46
47 return std::equal(candidate->cbegin(), candidate->cend(), referenceIt.first, referenceIt.second,
48 [](const auto &it1, const auto &it2) {
49 // - milliseconds precision for time
50 // - 1e-6 precision for value
51 return std::abs(it1.x() - it2.x()) < 1e-3
52 && std::abs(it1.value() - it2.value()) < 1e-6;
53 });
54 }
55
29 56 /// Generates the data series from the reading of a data stream
30 57 std::shared_ptr<IDataSeries> readDataStream(QTextStream &stream)
31 58 {
@@ -89,6 +116,16 void TestCosinusAcquisition::testAcquisition()
89 116 QTextStream dataStream{&dataFile};
90 117 auto dataSeries = readDataStream(dataStream);
91 118
119 /// Lambda used to validate a variable at each step
120 auto validateVariable = [dataSeries](std::shared_ptr<Variable> variable,
121 const SqpRange &range) {
122 // Checks that the variable's range has changed
123 QCOMPARE(variable->range(), range);
124
125 // Checks the variable's data series
126 QVERIFY(checkDataSeries(variable->dataSeries(), variable->cacheRange(), dataSeries));
127 };
128
92 129 // Creates variable
93 130 QFETCH(SqpRange, initialRange);
94 131 sqpApp->timeController().onTimeToUpdate(initialRange);
@@ -96,6 +133,8 void TestCosinusAcquisition::testAcquisition()
96 133 auto variable = sqpApp->variableController().createVariable("MMS", {}, provider);
97 134
98 135 QTest::qWait(OPERATION_DELAY);
136 validateVariable(variable, initialRange);
137
99 138 // Makes operations on the variable
100 139 QFETCH(std::vector<SqpRange>, operations);
101 140 for (const auto &operation : operations) {
@@ -104,6 +143,7 void TestCosinusAcquisition::testAcquisition()
104 143 variable->range(), true);
105 144
106 145 QTest::qWait(OPERATION_DELAY);
146 validateVariable(variable, operation);
107 147 }
108 148 }
109 149 else {
General Comments 0
You need to be logged in to leave comments. Login now