##// END OF EJS Templates
Tests add() method
Alexandre Leroux -
r516:7502b07f0f38
parent child
Show More
@@ -1,40 +1,75
1 #include "Data/ArrayData.h"
1 #include "Data/ArrayData.h"
2 #include <QObject>
2 #include <QObject>
3 #include <QtTest>
3 #include <QtTest>
4
4
5 class TestOneDimArrayData : public QObject {
5 class TestOneDimArrayData : public QObject {
6 Q_OBJECT
6 Q_OBJECT
7 private slots:
7 private slots:
8 /// Tests @sa ArrayData::data(int componentIndex)
8 /// Tests @sa ArrayData::data(int componentIndex)
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()
15 {
19 {
16 // Test structure
20 // Test structure
17 QTest::addColumn<QVector<double> >("inputData"); // array data's input
21 QTest::addColumn<QVector<double> >("inputData"); // array data's input
18 QTest::addColumn<int>("componentIndex"); // component index to test
22 QTest::addColumn<int>("componentIndex"); // component index to test
19 QTest::addColumn<QVector<double> >("expectedData"); // expected data
23 QTest::addColumn<QVector<double> >("expectedData"); // expected data
20
24
21 // Test cases
25 // Test cases
22 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
26 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
23 << QVector<double>{1., 2., 3., 4., 5.};
27 << QVector<double>{1., 2., 3., 4., 5.};
24 QTest::newRow("invalidIndex1")
28 QTest::newRow("invalidIndex1")
25 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
29 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
26 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
30 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
27 }
31 }
28
32
29 void TestOneDimArrayData::testDataByComponentIndex()
33 void TestOneDimArrayData::testDataByComponentIndex()
30 {
34 {
31 QFETCH(QVector<double>, inputData);
35 QFETCH(QVector<double>, inputData);
32 QFETCH(int, componentIndex);
36 QFETCH(int, componentIndex);
33 QFETCH(QVector<double>, expectedData);
37 QFETCH(QVector<double>, expectedData);
34
38
35 ArrayData<1> arrayData{inputData};
39 ArrayData<1> arrayData{inputData};
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"
@@ -1,45 +1,93
1 #include "Data/ArrayData.h"
1 #include "Data/ArrayData.h"
2 #include <QObject>
2 #include <QObject>
3 #include <QtTest>
3 #include <QtTest>
4
4
5 using DataContainer = QVector<QVector<double> >;
5 using DataContainer = QVector<QVector<double> >;
6
6
7 class TestTwoDimArrayData : public QObject {
7 class TestTwoDimArrayData : public QObject {
8 Q_OBJECT
8 Q_OBJECT
9 private slots:
9 private slots:
10 /// Tests @sa ArrayData::data(int componentIndex)
10 /// Tests @sa ArrayData::data(int componentIndex)
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()
17 {
21 {
18 // Test structure
22 // Test structure
19 QTest::addColumn<DataContainer>("inputData"); // array data's input
23 QTest::addColumn<DataContainer>("inputData"); // array data's input
20 QTest::addColumn<int>("componentIndex"); // component index to test
24 QTest::addColumn<int>("componentIndex"); // component index to test
21 QTest::addColumn<QVector<double> >("expectedData"); // expected data
25 QTest::addColumn<QVector<double> >("expectedData"); // expected data
22
26
23 // Test cases
27 // Test cases
24 auto inputData
28 auto inputData
25 = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
29 = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
26
30
27 QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.};
31 QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.};
28 QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.};
32 QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.};
29 QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.};
33 QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.};
30 QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{};
34 QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{};
31 QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{};
35 QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{};
32 }
36 }
33
37
34 void TestTwoDimArrayData::testDataByComponentIndex()
38 void TestTwoDimArrayData::testDataByComponentIndex()
35 {
39 {
36 QFETCH(DataContainer, inputData);
40 QFETCH(DataContainer, inputData);
37 QFETCH(int, componentIndex);
41 QFETCH(int, componentIndex);
38 QFETCH(QVector<double>, expectedData);
42 QFETCH(QVector<double>, expectedData);
39
43
40 ArrayData<2> arrayData{inputData};
44 ArrayData<2> arrayData{inputData};
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