diff --git a/core/tests/Data/TestOneDimArrayData.cpp b/core/tests/Data/TestOneDimArrayData.cpp index c378f72..163614e 100644 --- a/core/tests/Data/TestOneDimArrayData.cpp +++ b/core/tests/Data/TestOneDimArrayData.cpp @@ -9,6 +9,10 @@ private slots: void testDataByComponentIndex_data(); void testDataByComponentIndex(); + /// Tests @sa ArrayData::add() + void testAdd_data(); + void testAdd(); + }; void TestOneDimArrayData::testDataByComponentIndex_data() @@ -36,5 +40,36 @@ void TestOneDimArrayData::testDataByComponentIndex() QVERIFY(arrayData.data(componentIndex) == expectedData); } +void TestOneDimArrayData::testAdd_data() +{ + // Test structure + QTest::addColumn >("inputData"); // array's data input + QTest::addColumn >("otherData"); // array data's input to merge with + QTest::addColumn("prepend"); // prepend or append merge + QTest::addColumn >("expectedData"); // expected data after merge + + // Test cases + QTest::newRow("appendMerge") << QVector{1., 2., 3., 4., 5.} + << QVector{6., 7., 8.} << false + << QVector{1., 2., 3., 4., 5., 6., 7., 8.}; + QTest::newRow("prependMerge") << QVector{1., 2., 3., 4., 5.} + << QVector{6., 7., 8.} << true + << QVector{6., 7., 8., 1., 2., 3., 4., 5.}; +} + +void TestOneDimArrayData::testAdd() +{ + QFETCH(QVector, inputData); + QFETCH(QVector, otherData); + QFETCH(bool, prepend); + QFETCH(QVector, expectedData); + + ArrayData<1> arrayData{inputData}; + ArrayData<1> other{otherData}; + + arrayData.add(other, prepend); + QVERIFY(arrayData.data() == expectedData); +} + QTEST_MAIN(TestOneDimArrayData) #include "TestOneDimArrayData.moc" diff --git a/core/tests/Data/TestTwoDimArrayData.cpp b/core/tests/Data/TestTwoDimArrayData.cpp index 43f4889..b6381dd 100644 --- a/core/tests/Data/TestTwoDimArrayData.cpp +++ b/core/tests/Data/TestTwoDimArrayData.cpp @@ -11,6 +11,10 @@ private slots: void testDataByComponentIndex_data(); void testDataByComponentIndex(); + /// Tests @sa ArrayData::add() + void testAdd_data(); + void testAdd(); + }; void TestTwoDimArrayData::testDataByComponentIndex_data() @@ -41,5 +45,49 @@ void TestTwoDimArrayData::testDataByComponentIndex() QVERIFY(arrayData.data(componentIndex) == expectedData); } +void TestTwoDimArrayData::testAdd_data() +{ + // Test structure + QTest::addColumn("inputData"); // array's data input + QTest::addColumn("otherData"); // array data's input to merge with + QTest::addColumn("prepend"); // prepend or append merge + QTest::addColumn("expectedData"); // expected data after merge + + // Test cases + auto inputData + = DataContainer{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}}; + + auto vectorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}}; + auto tensorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}, + {36., 37., 38.}, {46., 47., 48.}, {56., 57., 58}}; + + QTest::newRow("appendMerge") << inputData << vectorContainer << false + << DataContainer{{1., 2., 3., 4., 5., 6., 7., 8.}, + {11., 12., 13., 14., 15., 16., 17., 18.}, + {21., 22., 23., 24., 25., 26., 27., 28}}; + QTest::newRow("prependMerge") << inputData << vectorContainer << true + << DataContainer{{6., 7., 8., 1., 2., 3., 4., 5.}, + {16., 17., 18., 11., 12., 13., 14., 15.}, + {26., 27., 28, 21., 22., 23., 24., 25.}}; + QTest::newRow("invalidMerge") << inputData << tensorContainer << false << inputData; +} + +void TestTwoDimArrayData::testAdd() +{ + QFETCH(DataContainer, inputData); + QFETCH(DataContainer, otherData); + QFETCH(bool, prepend); + QFETCH(DataContainer, expectedData); + + ArrayData<2> arrayData{inputData}; + ArrayData<2> other{otherData}; + + arrayData.add(other, prepend); + + for (auto i = 0; i < expectedData.size(); ++i) { + QVERIFY(arrayData.data(i) == expectedData.at(i)); + } +} + QTEST_MAIN(TestTwoDimArrayData) #include "TestTwoDimArrayData.moc"