From 6d79c86d7f6986cac58291d433395c25d169e4ec 2017-08-08 07:43:09 From: Alexandre Leroux Date: 2017-08-08 07:43:09 Subject: [PATCH] Tests get data by index method --- diff --git a/core/tests/Data/TestOneDimArrayData.cpp b/core/tests/Data/TestOneDimArrayData.cpp index bd49ab7..c378f72 100644 --- a/core/tests/Data/TestOneDimArrayData.cpp +++ b/core/tests/Data/TestOneDimArrayData.cpp @@ -5,7 +5,36 @@ class TestOneDimArrayData : public QObject { Q_OBJECT private slots: + /// Tests @sa ArrayData::data(int componentIndex) + void testDataByComponentIndex_data(); + void testDataByComponentIndex(); + }; +void TestOneDimArrayData::testDataByComponentIndex_data() +{ + // Test structure + QTest::addColumn >("inputData"); // array data's input + QTest::addColumn("componentIndex"); // component index to test + QTest::addColumn >("expectedData"); // expected data + + // Test cases + QTest::newRow("validIndex") << QVector{1., 2., 3., 4., 5.} << 0 + << QVector{1., 2., 3., 4., 5.}; + QTest::newRow("invalidIndex1") + << QVector{1., 2., 3., 4., 5.} << -1 << QVector{}; + QTest::newRow("invalidIndex2") << QVector{1., 2., 3., 4., 5.} << 1 << QVector{}; +} + +void TestOneDimArrayData::testDataByComponentIndex() +{ + QFETCH(QVector, inputData); + QFETCH(int, componentIndex); + QFETCH(QVector, expectedData); + + ArrayData<1> arrayData{inputData}; + QVERIFY(arrayData.data(componentIndex) == expectedData); +} + QTEST_MAIN(TestOneDimArrayData) #include "TestOneDimArrayData.moc" diff --git a/core/tests/Data/TestTwoDimArrayData.cpp b/core/tests/Data/TestTwoDimArrayData.cpp index 3c4dd0f..43f4889 100644 --- a/core/tests/Data/TestTwoDimArrayData.cpp +++ b/core/tests/Data/TestTwoDimArrayData.cpp @@ -7,7 +7,39 @@ using DataContainer = QVector >; class TestTwoDimArrayData : public QObject { Q_OBJECT private slots: + /// Tests @sa ArrayData::data(int componentIndex) + void testDataByComponentIndex_data(); + void testDataByComponentIndex(); + }; +void TestTwoDimArrayData::testDataByComponentIndex_data() +{ + // Test structure + QTest::addColumn("inputData"); // array data's input + QTest::addColumn("componentIndex"); // component index to test + QTest::addColumn >("expectedData"); // expected data + + // Test cases + auto inputData + = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; + + QTest::newRow("validIndex1") << inputData << 0 << QVector{1., 2., 3., 4., 5.}; + QTest::newRow("validIndex2") << inputData << 1 << QVector{6., 7., 8., 9., 10.}; + QTest::newRow("validIndex3") << inputData << 2 << QVector{11., 12., 13., 14., 15.}; + QTest::newRow("invalidIndex1") << inputData << -1 << QVector{}; + QTest::newRow("invalidIndex2") << inputData << 3 << QVector{}; +} + +void TestTwoDimArrayData::testDataByComponentIndex() +{ + QFETCH(DataContainer, inputData); + QFETCH(int, componentIndex); + QFETCH(QVector, expectedData); + + ArrayData<2> arrayData{inputData}; + QVERIFY(arrayData.data(componentIndex) == expectedData); +} + QTEST_MAIN(TestTwoDimArrayData) #include "TestTwoDimArrayData.moc"