##// END OF EJS Templates
Next var request parameter is now based on previous request instead of...
Next var request parameter is now based on previous request instead of initial variable parameter

File last commit:

r805:5cfef4c240d4
r807:0f020366c50a
Show More
TestDataSeries.cpp
707 lines | 26.3 KiB | text/x-c | CppLexer
/ core / tests / Data / TestDataSeries.cpp
Alexandre Leroux
Units tests on sorting data series
r455 #include "Data/DataSeries.h"
#include "Data/ScalarSeries.h"
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 #include "Data/VectorSeries.h"
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Fixes compilation on linux
r617 #include <cmath>
Alexandre Leroux
Units tests on sorting data series
r455 #include <QObject>
#include <QtTest>
Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>)
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>)
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Updates unit tests
r647 namespace {
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 using DataContainer = std::vector<double>;
void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData,
const DataContainer &valuesData)
Alexandre Leroux
Updates unit tests
r647 {
QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
[](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
QVERIFY(std::equal(
first, last, valuesData.cbegin(), valuesData.cend(),
[](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
}
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 void validateRange(DataSeriesIterator first, DataSeriesIterator last, const DataContainer &xData,
const std::vector<DataContainer> &valuesData)
Alexandre Leroux
Implements unit tests
r678 {
QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(),
[](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
for (auto i = 0; i < valuesData.size(); ++i) {
auto componentData = valuesData.at(i);
QVERIFY(std::equal(
first, last, componentData.cbegin(), componentData.cend(),
[i](const auto &it, const auto &expectedVal) { return it.value(i) == expectedVal; }));
}
}
Alexandre Leroux
Updates unit tests
r647 } // namespace
Alexandre Leroux
Units tests on sorting data series
r455 class TestDataSeries : public QObject {
Q_OBJECT
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 private:
template <typename T>
void testValuesBoundsStructure()
{
// ////////////// //
// Test structure //
// ////////////// //
// Data series to get values bounds
QTest::addColumn<std::shared_ptr<T> >("dataSeries");
// x-axis range
QTest::addColumn<double>("minXAxis");
QTest::addColumn<double>("maxXAxis");
// Expected results
QTest::addColumn<bool>(
"expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators)
QTest::addColumn<double>("expectedMinValue");
QTest::addColumn<double>("expectedMaxValue");
}
template <typename T>
void testValuesBounds()
{
QFETCH(std::shared_ptr<T>, dataSeries);
QFETCH(double, minXAxis);
QFETCH(double, maxXAxis);
QFETCH(bool, expectedOK);
QFETCH(double, expectedMinValue);
QFETCH(double, expectedMaxValue);
auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis);
auto end = dataSeries->cend();
// Checks iterators with expected result
QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end);
if (expectedOK) {
auto compare = [](const auto &v1, const auto &v2) {
return (std::isnan(v1) && std::isnan(v2)) || v1 == v2;
};
QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue()));
QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue()));
}
}
Alexandre Leroux
Implements unit tests
r678 template <typename T>
void testPurgeStructure()
{
// ////////////// //
// Test structure //
// ////////////// //
// Data series to purge
QTest::addColumn<std::shared_ptr<T> >("dataSeries");
QTest::addColumn<double>("min");
QTest::addColumn<double>("max");
// Expected values after purge
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedXAxisData");
QTest::addColumn<std::vector<DataContainer> >("expectedValuesData");
Alexandre Leroux
Implements unit tests
r678 }
template <typename T>
void testPurge()
{
QFETCH(std::shared_ptr<T>, dataSeries);
QFETCH(double, min);
QFETCH(double, max);
dataSeries->purge(min, max);
// Validates results
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedXAxisData);
QFETCH(std::vector<DataContainer>, expectedValuesData);
Alexandre Leroux
Implements unit tests
r678
validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData,
expectedValuesData);
}
Alexandre Leroux
Adds unit test for merge of two different series' type
r798 template <typename SourceType, typename DestType>
void testMergeDifferentTypesStructure()
{
// ////////////// //
// Test structure //
// ////////////// //
// Data series to merge
QTest::addColumn<std::shared_ptr<DestType> >("dest");
QTest::addColumn<std::shared_ptr<SourceType> >("source");
// Expected values in the dest data series after merge
QTest::addColumn<DataContainer>("expectedXAxisData");
QTest::addColumn<DataContainer>("expectedValuesData");
}
template <typename SourceType, typename DestType>
void testMergeDifferentTypes()
{
// Merges series
QFETCH(std::shared_ptr<SourceType>, source);
QFETCH(std::shared_ptr<DestType>, dest);
dest->merge(source.get());
// Validates results : we check that the merge is valid and the data series is sorted on its
// x-axis data
QFETCH(DataContainer, expectedXAxisData);
QFETCH(DataContainer, expectedValuesData);
validateRange(dest->cbegin(), dest->cend(), expectedXAxisData, expectedValuesData);
}
Alexandre Leroux
Units tests on sorting data series
r455 private slots:
Alexandre Leroux
Implements unit tests
r678
Alexandre Leroux
Units tests on sorting data series
r455 /// Input test data
/// @sa testCtor()
void testCtor_data();
/// Tests construction of a data series
void testCtor();
/// Input test data
/// @sa testMerge()
void testMerge_data();
/// Tests merge of two data series
void testMerge();
Alexandre Leroux
Fixes subData() method and adds unit tests
r586
Alexandre Leroux
Adds unit test for merge of two different series' type
r798 /// Input test data
/// @sa testMergeVectorInScalar()
void testMergeVectorInScalar_data();
/// Tests merge of vector series in scalar series
void testMergeVectorInScalar();
Alexandre Leroux
Implements unit tests
r678 /// Input test data
/// @sa testPurgeScalar()
void testPurgeScalar_data();
/// Tests purge of a scalar series
void testPurgeScalar();
/// Input test data
/// @sa testPurgeVector()
void testPurgeVector_data();
/// Tests purge of a vector series
void testPurgeVector();
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 /// Input test data
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 /// @sa testMinXAxisData()
void testMinXAxisData_data();
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 /// Tests get min x-axis data of a data series
void testMinXAxisData();
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 /// Input test data
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 /// @sa testMaxXAxisData()
void testMaxXAxisData_data();
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 /// Tests get max x-axis data of a data series
void testMaxXAxisData();
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600
/// Input test data
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 /// @sa testXAxisRange()
void testXAxisRange_data();
Alexandre Leroux
Fixes subData() method and adds unit tests
r586
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 /// Tests get x-axis range of a data series
void testXAxisRange();
Alexandre Leroux
Makes unit tests
r610
/// Input test data
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 /// @sa testValuesBoundsScalar()
void testValuesBoundsScalar_data();
Alexandre Leroux
Makes unit tests
r610
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 /// Tests get values bounds of a scalar series
void testValuesBoundsScalar();
Alexandre Leroux
Implements unit tests for vectors
r612
/// Input test data
/// @sa testValuesBoundsVector()
void testValuesBoundsVector_data();
/// Tests get values bounds of a vector series
void testValuesBoundsVector();
Alexandre Leroux
Units tests on sorting data series
r455 };
void TestDataSeries::testCtor_data()
{
// ////////////// //
// Test structure //
// ////////////// //
// x-axis data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("xAxisData");
Alexandre Leroux
Units tests on sorting data series
r455 // values data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("valuesData");
Alexandre Leroux
Units tests on sorting data series
r455
// expected x-axis data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedXAxisData");
Alexandre Leroux
Units tests on sorting data series
r455 // expected values data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedValuesData");
Alexandre Leroux
Units tests on sorting data series
r455
// ////////// //
// Test cases //
// ////////// //
QTest::newRow("invalidData (different sizes of vectors)")
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300.} << DataContainer{}
<< DataContainer{};
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("sortedData") << DataContainer{1., 2., 3., 4., 5.}
<< DataContainer{100., 200., 300., 400., 500.}
<< DataContainer{1., 2., 3., 4., 5.}
<< DataContainer{100., 200., 300., 400., 500.};
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("unsortedData") << DataContainer{5., 4., 3., 2., 1.}
<< DataContainer{100., 200., 300., 400., 500.}
<< DataContainer{1., 2., 3., 4., 5.}
<< DataContainer{500., 400., 300., 200., 100.};
Alexandre Leroux
Units tests on sorting data series
r455
QTest::newRow("unsortedData2")
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << DataContainer{1., 4., 3., 5., 2.} << DataContainer{100., 200., 300., 400., 500.}
<< DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 500., 300., 200., 400.};
Alexandre Leroux
Units tests on sorting data series
r455 }
void TestDataSeries::testCtor()
{
// Creates series
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, xAxisData);
QFETCH(DataContainer, valuesData);
Alexandre Leroux
Units tests on sorting data series
r455
auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData),
Unit{}, Unit{});
// Validates results : we check that the data series is sorted on its x-axis data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedXAxisData);
QFETCH(DataContainer, expectedValuesData);
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Updates unit tests
r647 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData);
Alexandre Leroux
Units tests on sorting data series
r455 }
namespace {
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 std::shared_ptr<ScalarSeries> createScalarSeries(DataContainer xAxisData, DataContainer valuesData)
Alexandre Leroux
Units tests on sorting data series
r455 {
return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{},
Unit{});
}
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 std::shared_ptr<VectorSeries> createVectorSeries(DataContainer xAxisData, DataContainer xValuesData,
DataContainer yValuesData,
DataContainer zValuesData)
Alexandre Leroux
Implements unit tests for vectors
r612 {
return std::make_shared<VectorSeries>(std::move(xAxisData), std::move(xValuesData),
std::move(yValuesData), std::move(zValuesData), Unit{},
Unit{});
}
Alexandre Leroux
Units tests on sorting data series
r455 } // namespace
void TestDataSeries::testMerge_data()
{
// ////////////// //
// Test structure //
// ////////////// //
// Data series to merge
QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2");
// Expected values in the first data series after merge
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedXAxisData");
QTest::addColumn<DataContainer>("expectedValuesData");
Alexandre Leroux
Units tests on sorting data series
r455
// ////////// //
// Test cases //
// ////////// //
QTest::newRow("sortedMerge")
Alexandre Leroux
Minor refactoring
r613 << createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
<< createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
<< DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
Alexandre Leroux
Units tests on sorting data series
r455
QTest::newRow("unsortedMerge")
Alexandre Leroux
Minor refactoring
r613 << createScalarSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.})
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << DataContainer{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}
<< DataContainer{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.};
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::newRow("unsortedMerge2 (merge not made because source is in the bounds of dest)")
<< createScalarSeries({1., 2., 8., 9., 10}, {100., 200., 800., 900., 1000.})
<< createScalarSeries({3., 4., 5., 6., 7.}, {300., 400., 500., 600., 700.})
<< DataContainer{1., 2., 8., 9., 10.} << DataContainer{100., 200., 800., 900., 1000.};
Alexandre Leroux
Units tests on sorting data series
r455
QTest::newRow("unsortedMerge3")
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << createScalarSeries({3., 4., 5., 7., 8}, {300., 400., 500., 700., 800.})
<< createScalarSeries({1., 2., 3., 7., 10.}, {100., 200., 333., 777., 1000.})
<< DataContainer{1., 2., 3., 4., 5., 7., 8., 10.}
<< DataContainer{100., 200., 300., 400., 500., 700., 800., 1000.};
Alexandre Leroux
Completes DataSeries::merge() test
r800
QTest::newRow("emptySource") << createScalarSeries({3., 4., 5., 7., 8},
{300., 400., 500., 700., 800.})
<< createScalarSeries({}, {}) << DataContainer{3., 4., 5., 7., 8.}
<< DataContainer{300., 400., 500., 700., 800.};
Alexandre Leroux
Units tests on sorting data series
r455 }
void TestDataSeries::testMerge()
{
// Merges series
QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2);
dataSeries->merge(dataSeries2.get());
// Validates results : we check that the merge is valid and the data series is sorted on its
// x-axis data
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedXAxisData);
QFETCH(DataContainer, expectedValuesData);
Alexandre Leroux
Units tests on sorting data series
r455
Alexandre Leroux
Updates unit tests
r647 validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData);
Alexandre Leroux
Units tests on sorting data series
r455 }
Alexandre Leroux
Adds unit test for merge of two different series' type
r798 void TestDataSeries::testMergeVectorInScalar_data()
{
testMergeDifferentTypesStructure<VectorSeries, ScalarSeries>();
// ////////// //
// Test cases //
// ////////// //
QTest::newRow("purgeVectorInScalar")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
<< createVectorSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.},
{610., 710., 810., 910., 1010.}, {620., 720., 820., 920., 1020.})
<< DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300., 400., 500.};
}
void TestDataSeries::testMergeVectorInScalar()
{
testMergeDifferentTypes<VectorSeries, ScalarSeries>();
}
Alexandre Leroux
Implements unit tests
r678 void TestDataSeries::testPurgeScalar_data()
{
testPurgeStructure<ScalarSeries>();
// ////////// //
// Test cases //
// ////////// //
QTest::newRow("purgeScalar") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 2. << 4. << DataContainer{2., 3., 4.}
<< std::vector<DataContainer>{{200., 300., 400.}};
Alexandre Leroux
Completes DataSeries::purge() and DataSeries::xAxisRange() tests
r797 QTest::newRow("purgeScalar1 (min/max swap)")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 4. << 2.
<< DataContainer{2., 3., 4.} << std::vector<DataContainer>{{200., 300., 400.}};
Alexandre Leroux
Implements unit tests
r678 QTest::newRow("purgeScalar2") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 0. << 2.5 << DataContainer{1., 2.}
<< std::vector<DataContainer>{{100., 200.}};
Alexandre Leroux
Implements unit tests
r678 QTest::newRow("purgeScalar3") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 3.5 << 7. << DataContainer{4., 5.}
<< std::vector<DataContainer>{{400., 500.}};
Alexandre Leroux
Implements unit tests
r678 QTest::newRow("purgeScalar4") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 0. << 7. << DataContainer{1., 2., 3., 4., 5.}
<< std::vector<DataContainer>{{100., 200., 300., 400., 500.}};
Alexandre Leroux
Implements unit tests
r678 QTest::newRow("purgeScalar5") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 5.5 << 7. << DataContainer{} << std::vector<DataContainer>{{}};
Alexandre Leroux
Implements unit tests
r678 }
void TestDataSeries::testPurgeScalar()
{
testPurge<ScalarSeries>();
}
void TestDataSeries::testPurgeVector_data()
{
testPurgeStructure<VectorSeries>();
// ////////// //
// Test cases //
// ////////// //
QTest::newRow("purgeVector") << createVectorSeries({1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.},
{11., 12., 13., 14., 15.},
{16., 17., 18., 19., 20.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 2. << 4. << DataContainer{2., 3., 4.}
<< std::vector<DataContainer>{
Alexandre Leroux
Implements unit tests
r678 {7., 8., 9.}, {12., 13., 14.}, {17., 18., 19.}};
}
void TestDataSeries::testPurgeVector()
{
testPurge<VectorSeries>();
}
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 void TestDataSeries::testMinXAxisData_data()
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 {
// ////////////// //
// Test structure //
// ////////////// //
// Data series to get min data
QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
// Min data
QTest::addColumn<double>("min");
// Expected results
QTest::addColumn<bool>(
"expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
QTest::addColumn<double>(
"expectedMin"); // Expected value when method doesn't return end iterator
// ////////// //
// Test cases //
// ////////// //
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData1") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << 0. << true << 1.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData2") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << 1. << true << 1.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData3") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << 1.1 << true << 2.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData4") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << 5. << true << 5.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData5") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("minData6") << createScalarSeries({}, {}) << 1.1 << false
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 << std::numeric_limits<double>::quiet_NaN();
}
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 void TestDataSeries::testMinXAxisData()
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599 {
QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
QFETCH(double, min);
QFETCH(bool, expectedOK);
QFETCH(double, expectedMin);
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 auto it = dataSeries->minXAxisData(min);
Alexandre Leroux
Shows min x-axis data in Variable widget (1)...
r599
QCOMPARE(expectedOK, it != dataSeries->cend());
// If the method doesn't return a end iterator, checks with expected value
if (expectedOK) {
QCOMPARE(expectedMin, it->x());
}
}
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 void TestDataSeries::testMaxXAxisData_data()
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 {
// ////////////// //
// Test structure //
// ////////////// //
// Data series to get max data
QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
// Max data
QTest::addColumn<double>("max");
// Expected results
QTest::addColumn<bool>(
"expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
QTest::addColumn<double>(
"expectedMax"); // Expected value when method doesn't return end iterator
// ////////// //
// Test cases //
// ////////// //
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData1") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << 6. << true << 5.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData2") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << 5. << true << 5.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData3") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << 4.9 << true << 4.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData4") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << 1.1 << true << 1.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData5") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << 1. << true << 1.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("maxData6") << createScalarSeries({}, {}) << 1.1 << false
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 << std::numeric_limits<double>::quiet_NaN();
}
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 void TestDataSeries::testMaxXAxisData()
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600 {
QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
QFETCH(double, max);
QFETCH(bool, expectedOK);
QFETCH(double, expectedMax);
Alexandre Leroux
(Refactoring) Renames IDataSeries::minData() and IDataSeries::maxData()
r604 auto it = dataSeries->maxXAxisData(max);
Alexandre Leroux
Shows min/max x-axis data in Variable widget (2)...
r600
QCOMPARE(expectedOK, it != dataSeries->cend());
// If the method doesn't return a end iterator, checks with expected value
if (expectedOK) {
QCOMPARE(expectedMax, it->x());
}
}
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 void TestDataSeries::testXAxisRange_data()
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 {
// ////////////// //
// Test structure //
// ////////////// //
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 // Data series to get x-axis range
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
// Min/max values
QTest::addColumn<double>("min");
QTest::addColumn<double>("max");
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 // Expected values
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QTest::addColumn<DataContainer>("expectedXAxisData");
QTest::addColumn<DataContainer>("expectedValuesData");
Alexandre Leroux
Fixes subData() method and adds unit tests
r586
// ////////// //
// Test cases //
// ////////// //
Alexandre Leroux
Completes DataSeries::purge() and DataSeries::xAxisRange() tests
r797 QTest::newRow("xAxisRange") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
<< -1. << 3.2 << DataContainer{1., 2., 3.}
<< DataContainer{100., 200., 300.};
QTest::newRow("xAxisRange1 (min/max swap)")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 3.2 << -1.
<< DataContainer{1., 2., 3.} << DataContainer{100., 200., 300.};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange2") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 1. << 4. << DataContainer{1., 2., 3., 4.}
<< DataContainer{100., 200., 300., 400.};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange3") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 1. << 3.9 << DataContainer{1., 2., 3.}
<< DataContainer{100., 200., 300.};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange4") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 0. << 0.9 << DataContainer{} << DataContainer{};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange5") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 0. << 1. << DataContainer{1.} << DataContainer{100.};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange6") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 2.1 << 6. << DataContainer{3., 4., 5.}
<< DataContainer{300., 400., 500.};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange7") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 6. << 9. << DataContainer{} << DataContainer{};
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("xAxisRange8") << createScalarSeries({1., 2., 3., 4., 5.},
{100., 200., 300., 400., 500.})
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 << 5. << 9. << DataContainer{5.} << DataContainer{500.};
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 }
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 void TestDataSeries::testXAxisRange()
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 {
QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
QFETCH(double, min);
QFETCH(double, max);
Alexandre Leroux
Uses std::vector instead of QVector in ArrayData (2)...
r695 QFETCH(DataContainer, expectedXAxisData);
QFETCH(DataContainer, expectedValuesData);
Alexandre Leroux
Fixes subData() method and adds unit tests
r586
Alexandre Leroux
(Refactoring) Renames IDataSeries::subData()
r605 auto bounds = dataSeries->xAxisRange(min, max);
Alexandre Leroux
Updates unit tests
r647 validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData);
Alexandre Leroux
Fixes subData() method and adds unit tests
r586 }
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 void TestDataSeries::testValuesBoundsScalar_data()
Alexandre Leroux
Makes unit tests
r610 {
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 testValuesBoundsStructure<ScalarSeries>();
Alexandre Leroux
Makes unit tests
r610
// ////////// //
// Test cases //
// ////////// //
Alexandre Leroux
Minor refactoring
r613 auto nan = std::numeric_limits<double>::quiet_NaN();
QTest::newRow("scalarBounds1")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6.
<< true << 100. << 500.;
QTest::newRow("scalarBounds2")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4.
<< true << 200. << 400.;
QTest::newRow("scalarBounds3")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5
<< false << nan << nan;
QTest::newRow("scalarBounds4")
<< createScalarSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6.
<< false << nan << nan;
update for clang format
r805 QTest::newRow("scalarBounds5") << createScalarSeries({1.}, {100.}) << 0. << 2. << true << 100.
<< 100.;
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("scalarBounds6") << createScalarSeries({}, {}) << 0. << 2. << false << nan << nan;
Alexandre Leroux
Makes unit tests
r610
// Tests with NaN values: NaN values are not included in min/max search
Alexandre Leroux
Minor refactoring
r613 QTest::newRow("scalarBounds7")
<< createScalarSeries({1., 2., 3., 4., 5.}, {nan, 200., 300., 400., nan}) << 0. << 6.
<< true << 200. << 400.;
QTest::newRow("scalarBounds8")
<< createScalarSeries({1., 2., 3., 4., 5.}, {nan, nan, nan, nan, nan}) << 0. << 6. << true
<< std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN();
Alexandre Leroux
Makes unit tests
r610 }
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 void TestDataSeries::testValuesBoundsScalar()
Alexandre Leroux
Makes unit tests
r610 {
Alexandre Leroux
Makes unit test templated to use it for vectors too
r611 testValuesBounds<ScalarSeries>();
Alexandre Leroux
Makes unit tests
r610 }
Alexandre Leroux
Implements unit tests for vectors
r612 void TestDataSeries::testValuesBoundsVector_data()
{
testValuesBoundsStructure<VectorSeries>();
// ////////// //
// Test cases //
// ////////// //
Alexandre Leroux
Minor refactoring
r613 auto nan = std::numeric_limits<double>::quiet_NaN();
Alexandre Leroux
Implements unit tests for vectors
r612
QTest::newRow("vectorBounds1")
<< createVectorSeries({1., 2., 3., 4., 5.}, {10., 15., 20., 13., 12.},
{35., 24., 10., 9., 0.3}, {13., 14., 12., 9., 24.})
<< 0. << 6. << true << 0.3 << 35.; // min/max in same component
QTest::newRow("vectorBounds2")
<< createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
{35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
<< 0. << 6. << true << 2.3 << 35.; // min/max in same entry
QTest::newRow("vectorBounds3")
<< createVectorSeries({1., 2., 3., 4., 5.}, {2.3, 15., 20., 13., 12.},
{35., 24., 10., 9., 4.}, {13., 14., 12., 9., 24.})
<< 2. << 3. << true << 10. << 24.;
// Tests with NaN values: NaN values are not included in min/max search
QTest::newRow("vectorBounds4")
Alexandre Leroux
Minor refactoring
r613 << createVectorSeries({1., 2.}, {nan, nan}, {nan, nan}, {nan, nan}) << 0. << 6. << true
<< nan << nan;
Alexandre Leroux
Implements unit tests for vectors
r612 }
void TestDataSeries::testValuesBoundsVector()
{
testValuesBounds<VectorSeries>();
}
Alexandre Leroux
Units tests on sorting data series
r455 QTEST_MAIN(TestDataSeries)
#include "TestDataSeries.moc"