##// END OF EJS Templates
Makes unit tests
Alexandre Leroux -
r610:24d4175c19b0
parent child
Show More
@@ -43,6 +43,13 private slots:
43
43
44 /// Tests get x-axis range of a data series
44 /// Tests get x-axis range of a data series
45 void testXAxisRange();
45 void testXAxisRange();
46
47 /// Input test data
48 /// @sa testValuesBounds()
49 void testValuesBounds_data();
50
51 /// Tests get values bounds of a data series
52 void testValuesBounds();
46 };
53 };
47
54
48 void TestDataSeries::testCtor_data()
55 void TestDataSeries::testCtor_data()
@@ -358,5 +365,88 void TestDataSeries::testXAxisRange()
358 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
365 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
359 }
366 }
360
367
368 void TestDataSeries::testValuesBounds_data()
369 {
370 // ////////////// //
371 // Test structure //
372 // ////////////// //
373
374 // Data series to get values bounds
375 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
376
377 // x-axis range
378 QTest::addColumn<double>("minXAxis");
379 QTest::addColumn<double>("maxXAxis");
380
381 // Expected results
382 QTest::addColumn<bool>(
383 "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
384 QTest::addColumn<double>("expectedMinValue");
385 QTest::addColumn<double>("expectedMaxValue");
386
387 // ////////// //
388 // Test cases //
389 // ////////// //
390
391 QTest::newRow("valuesBounds1")
392 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6. << true
393 << 100. << 500.;
394 QTest::newRow("valuesBounds2")
395 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4. << true
396 << 200. << 400.;
397 QTest::newRow("valuesBounds3")
398 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5 << false
399 << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
400 QTest::newRow("valuesBounds4")
401 << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6. << false
402 << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
403 QTest::newRow("valuesBounds5")
404 << createSeries({1.}, {100.}) << 0. << 2. << true << 100. << 100.;
405 QTest::newRow("valuesBounds6")
406 << createSeries({}, {}) << 0. << 2. << false << std::numeric_limits<double>::quiet_NaN()
407 << std::numeric_limits<double>::quiet_NaN();
408
409 // Tests with NaN values: NaN values are not included in min/max search
410 QTest::newRow("valuesBounds7")
411 << createSeries({1., 2., 3., 4., 5.},
412 {std::numeric_limits<double>::quiet_NaN(), 200., 300., 400.,
413 std::numeric_limits<double>::quiet_NaN()})
414 << 0. << 6. << true << 200. << 400.;
415 QTest::newRow("valuesBounds8")
416 << createSeries(
417 {1., 2., 3., 4., 5.},
418 {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
419 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(),
420 std::numeric_limits<double>::quiet_NaN()})
421 << 0. << 6. << true << std::numeric_limits<double>::quiet_NaN()
422 << std::numeric_limits<double>::quiet_NaN();
423 }
424
425 void TestDataSeries::testValuesBounds()
426 {
427 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
428 QFETCH(double, minXAxis);
429 QFETCH(double, maxXAxis);
430
431 QFETCH(bool, expectedOK);
432 QFETCH(double, expectedMinValue);
433 QFETCH(double, expectedMaxValue);
434
435 auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
436 auto end = dataSeries->cend();
437
438 // Checks iterators with expected result
439 QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
440
441 if (expectedOK) {
442 auto compare = [](const auto &v1, const auto &v2) {
443 return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
444 };
445
446 QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
447 QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
448 }
449 }
450
361 QTEST_MAIN(TestDataSeries)
451 QTEST_MAIN(TestDataSeries)
362 #include "TestDataSeries.moc"
452 #include "TestDataSeries.moc"
General Comments 0
You need to be logged in to leave comments. Login now