##// END OF EJS Templates
Tests add() method
Alexandre Leroux -
r516:7502b07f0f38
parent child
Show More
@@ -9,6 +9,10 private slots:
9 void testDataByComponentIndex_data();
9 void testDataByComponentIndex_data();
10 void testDataByComponentIndex();
10 void testDataByComponentIndex();
11
11
12 /// Tests @sa ArrayData::add()
13 void testAdd_data();
14 void testAdd();
15
12 };
16 };
13
17
14 void TestOneDimArrayData::testDataByComponentIndex_data()
18 void TestOneDimArrayData::testDataByComponentIndex_data()
@@ -36,5 +40,36 void TestOneDimArrayData::testDataByComponentIndex()
36 QVERIFY(arrayData.data(componentIndex) == expectedData);
40 QVERIFY(arrayData.data(componentIndex) == expectedData);
37 }
41 }
38
42
43 void TestOneDimArrayData::testAdd_data()
44 {
45 // Test structure
46 QTest::addColumn<QVector<double> >("inputData"); // array's data input
47 QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with
48 QTest::addColumn<bool>("prepend"); // prepend or append merge
49 QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge
50
51 // Test cases
52 QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.}
53 << QVector<double>{6., 7., 8.} << false
54 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.};
55 QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.}
56 << QVector<double>{6., 7., 8.} << true
57 << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.};
58 }
59
60 void TestOneDimArrayData::testAdd()
61 {
62 QFETCH(QVector<double>, inputData);
63 QFETCH(QVector<double>, otherData);
64 QFETCH(bool, prepend);
65 QFETCH(QVector<double>, expectedData);
66
67 ArrayData<1> arrayData{inputData};
68 ArrayData<1> other{otherData};
69
70 arrayData.add(other, prepend);
71 QVERIFY(arrayData.data() == expectedData);
72 }
73
39 QTEST_MAIN(TestOneDimArrayData)
74 QTEST_MAIN(TestOneDimArrayData)
40 #include "TestOneDimArrayData.moc"
75 #include "TestOneDimArrayData.moc"
@@ -11,6 +11,10 private slots:
11 void testDataByComponentIndex_data();
11 void testDataByComponentIndex_data();
12 void testDataByComponentIndex();
12 void testDataByComponentIndex();
13
13
14 /// Tests @sa ArrayData::add()
15 void testAdd_data();
16 void testAdd();
17
14 };
18 };
15
19
16 void TestTwoDimArrayData::testDataByComponentIndex_data()
20 void TestTwoDimArrayData::testDataByComponentIndex_data()
@@ -41,5 +45,49 void TestTwoDimArrayData::testDataByComponentIndex()
41 QVERIFY(arrayData.data(componentIndex) == expectedData);
45 QVERIFY(arrayData.data(componentIndex) == expectedData);
42 }
46 }
43
47
48 void TestTwoDimArrayData::testAdd_data()
49 {
50 // Test structure
51 QTest::addColumn<DataContainer>("inputData"); // array's data input
52 QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with
53 QTest::addColumn<bool>("prepend"); // prepend or append merge
54 QTest::addColumn<DataContainer>("expectedData"); // expected data after merge
55
56 // Test cases
57 auto inputData
58 = DataContainer{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}};
59
60 auto vectorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}};
61 auto tensorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28},
62 {36., 37., 38.}, {46., 47., 48.}, {56., 57., 58}};
63
64 QTest::newRow("appendMerge") << inputData << vectorContainer << false
65 << DataContainer{{1., 2., 3., 4., 5., 6., 7., 8.},
66 {11., 12., 13., 14., 15., 16., 17., 18.},
67 {21., 22., 23., 24., 25., 26., 27., 28}};
68 QTest::newRow("prependMerge") << inputData << vectorContainer << true
69 << DataContainer{{6., 7., 8., 1., 2., 3., 4., 5.},
70 {16., 17., 18., 11., 12., 13., 14., 15.},
71 {26., 27., 28, 21., 22., 23., 24., 25.}};
72 QTest::newRow("invalidMerge") << inputData << tensorContainer << false << inputData;
73 }
74
75 void TestTwoDimArrayData::testAdd()
76 {
77 QFETCH(DataContainer, inputData);
78 QFETCH(DataContainer, otherData);
79 QFETCH(bool, prepend);
80 QFETCH(DataContainer, expectedData);
81
82 ArrayData<2> arrayData{inputData};
83 ArrayData<2> other{otherData};
84
85 arrayData.add(other, prepend);
86
87 for (auto i = 0; i < expectedData.size(); ++i) {
88 QVERIFY(arrayData.data(i) == expectedData.at(i));
89 }
90 }
91
44 QTEST_MAIN(TestTwoDimArrayData)
92 QTEST_MAIN(TestTwoDimArrayData)
45 #include "TestTwoDimArrayData.moc"
93 #include "TestTwoDimArrayData.moc"
General Comments 0
You need to be logged in to leave comments. Login now