From 16e3b7f34e6f31128342110baa1dc1ac7693c195 2017-08-08 07:43:09 From: Alexandre Leroux Date: 2017-08-08 07:43:09 Subject: [PATCH] Tests clear() and size() methods --- diff --git a/core/tests/Data/TestOneDimArrayData.cpp b/core/tests/Data/TestOneDimArrayData.cpp index 163614e..b184a68 100644 --- a/core/tests/Data/TestOneDimArrayData.cpp +++ b/core/tests/Data/TestOneDimArrayData.cpp @@ -13,6 +13,14 @@ private slots: void testAdd_data(); void testAdd(); + /// Tests @sa ArrayData::clear() + void testClear_data(); + void testClear(); + + /// Tests @sa ArrayData::size() + void testSize_data(); + void testSize(); + }; void TestOneDimArrayData::testDataByComponentIndex_data() @@ -71,5 +79,33 @@ void TestOneDimArrayData::testAdd() QVERIFY(arrayData.data() == expectedData); } +void TestOneDimArrayData::testClear() +{ + QFETCH(QVector, inputData); + + ArrayData<1> arrayData{inputData}; + arrayData.clear(); + QVERIFY(arrayData.data() == QVector{}); +} + +void TestOneDimArrayData::testSize_data() +{ + // Test structure + QTest::addColumn >("inputData"); // array data's input + QTest::addColumn("expectedSize"); // expected array data size + + // Test cases + QTest::newRow("data1") << QVector{1., 2., 3., 4., 5.} << 5; +} + +void TestOneDimArrayData::testSize() +{ + QFETCH(QVector, inputData); + QFETCH(int, expectedSize); + + ArrayData<1> arrayData{inputData}; + QVERIFY(arrayData.size() == expectedSize); +} + QTEST_MAIN(TestOneDimArrayData) #include "TestOneDimArrayData.moc" diff --git a/core/tests/Data/TestTwoDimArrayData.cpp b/core/tests/Data/TestTwoDimArrayData.cpp index b6381dd..672e471 100644 --- a/core/tests/Data/TestTwoDimArrayData.cpp +++ b/core/tests/Data/TestTwoDimArrayData.cpp @@ -15,6 +15,14 @@ private slots: void testAdd_data(); void testAdd(); + /// Tests @sa ArrayData::clear() + void testClear_data(); + void testClear(); + + /// Tests @sa ArrayData::size() + void testSize_data(); + void testSize(); + }; void TestTwoDimArrayData::testDataByComponentIndex_data() @@ -89,5 +97,50 @@ void TestTwoDimArrayData::testAdd() } } +void TestTwoDimArrayData::testClear_data() +{ + // Test structure + QTest::addColumn("inputData"); // array data's input + + // Test cases + QTest::newRow("data1") << DataContainer{ + {1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; +} + +void TestTwoDimArrayData::testClear() +{ + QFETCH(DataContainer, inputData); + + ArrayData<2> arrayData{inputData}; + arrayData.clear(); + + for (auto i = 0; i < inputData.size(); ++i) { + QVERIFY(arrayData.data(i) == QVector{}); + } +} + +void TestTwoDimArrayData::testSize_data() +{ + // Test structure + QTest::addColumn > >("inputData"); // array data's input + QTest::addColumn("expectedSize"); // expected array data size + + // Test cases + QTest::newRow("data1") << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}} << 5; + QTest::newRow("data2") << DataContainer{{1., 2., 3., 4., 5.}, + {6., 7., 8., 9., 10.}, + {11., 12., 13., 14., 15.}} + << 5; +} + +void TestTwoDimArrayData::testSize() +{ + QFETCH(DataContainer, inputData); + QFETCH(int, expectedSize); + + ArrayData<2> arrayData{inputData}; + QVERIFY(arrayData.size() == expectedSize); +} + QTEST_MAIN(TestTwoDimArrayData) #include "TestTwoDimArrayData.moc"