##// END OF EJS Templates
Adds Variable::nbPoints() test
Alexandre Leroux -
r802:605c8cb87267
parent child
Show More
@@ -45,6 +45,9 private slots:
45 void testNotInCacheRangeList();
45 void testNotInCacheRangeList();
46 void testInCacheRangeList();
46 void testInCacheRangeList();
47
47
48 void testNbPoints_data();
49 void testNbPoints();
50
48 void testRealRange_data();
51 void testRealRange_data();
49 void testRealRange();
52 void testRealRange();
50 };
53 };
@@ -267,6 +270,72 void TestVariable::testInCacheRangeList()
267
270
268 namespace {
271 namespace {
269
272
273 /// Struct used to represent an operation for @sa TestVariable::testNbPoints()
274 struct NbPointsOperation {
275 SqpRange m_CacheRange; /// Range to set for the variable
276 std::shared_ptr<ScalarSeries> m_DataSeries; /// Series to merge in the variable
277 int m_ExpectedNbPoints; /// Number of points in the variable expected after operation
278 };
279
280 using NbPointsOperations = std::vector<NbPointsOperation>;
281
282 } // namespace
283
284 Q_DECLARE_METATYPE(NbPointsOperations)
285
286 void TestVariable::testNbPoints_data()
287 {
288 // ////////////// //
289 // Test structure //
290 // ////////////// //
291
292 QTest::addColumn<NbPointsOperations>("operations");
293
294 // ////////// //
295 // Test cases //
296 // ////////// //
297 NbPointsOperations operations{};
298
299 // Sets cache range (expected nb points = series xAxis data + series values data)
300 auto cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 9)};
301 operations.push_back({cacheRange, dataSeries(cacheRange), 20});
302
303 // Doubles cache but don't add data series (expected nb points don't change)
304 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
305 operations.push_back({cacheRange, nullptr, 20});
306
307 // Doubles cache and data series (expected nb points change)
308 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 0), date(2017, 1, 1, 12, 0, 19)};
309 operations.push_back({cacheRange, dataSeries(cacheRange), 40});
310
311 // Decreases cache (expected nb points decreases as the series is purged)
312 cacheRange = SqpRange{date(2017, 1, 1, 12, 0, 5), date(2017, 1, 1, 12, 0, 9)};
313 operations.push_back({cacheRange, nullptr, 10});
314
315 QTest::newRow("nbPoints1") << operations;
316 }
317
318 void TestVariable::testNbPoints()
319 {
320 // Creates variable
321 Variable variable{"var"};
322 QCOMPARE(variable.nbPoints(), 0);
323
324 QFETCH(NbPointsOperations, operations);
325 for (const auto &operation : operations) {
326 // Sets cache range and merge data series
327 variable.setCacheRange(operation.m_CacheRange);
328 if (operation.m_DataSeries != nullptr) {
329 variable.mergeDataSeries(operation.m_DataSeries);
330 }
331
332 // Checks nb points
333 QCOMPARE(variable.nbPoints(), operation.m_ExpectedNbPoints);
334 }
335 }
336
337 namespace {
338
270 /// Struct used to represent a range operation on a variable
339 /// Struct used to represent a range operation on a variable
271 /// @sa TestVariable::testRealRange()
340 /// @sa TestVariable::testRealRange()
272 struct RangeOperation {
341 struct RangeOperation {
General Comments 0
You need to be logged in to leave comments. Login now