##// END OF EJS Templates
Tests clear() and size() methods
Alexandre Leroux -
r517:16e3b7f34e6f
parent child
Show More
@@ -1,75 +1,111
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()
12 /// Tests @sa ArrayData::add()
13 void testAdd_data();
13 void testAdd_data();
14 void testAdd();
14 void testAdd();
15
15
16 /// Tests @sa ArrayData::clear()
17 void testClear_data();
18 void testClear();
19
20 /// Tests @sa ArrayData::size()
21 void testSize_data();
22 void testSize();
23
16 };
24 };
17
25
18 void TestOneDimArrayData::testDataByComponentIndex_data()
26 void TestOneDimArrayData::testDataByComponentIndex_data()
19 {
27 {
20 // Test structure
28 // Test structure
21 QTest::addColumn<QVector<double> >("inputData"); // array data's input
29 QTest::addColumn<QVector<double> >("inputData"); // array data's input
22 QTest::addColumn<int>("componentIndex"); // component index to test
30 QTest::addColumn<int>("componentIndex"); // component index to test
23 QTest::addColumn<QVector<double> >("expectedData"); // expected data
31 QTest::addColumn<QVector<double> >("expectedData"); // expected data
24
32
25 // Test cases
33 // Test cases
26 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
34 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
27 << QVector<double>{1., 2., 3., 4., 5.};
35 << QVector<double>{1., 2., 3., 4., 5.};
28 QTest::newRow("invalidIndex1")
36 QTest::newRow("invalidIndex1")
29 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
37 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
30 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
38 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
31 }
39 }
32
40
33 void TestOneDimArrayData::testDataByComponentIndex()
41 void TestOneDimArrayData::testDataByComponentIndex()
34 {
42 {
35 QFETCH(QVector<double>, inputData);
43 QFETCH(QVector<double>, inputData);
36 QFETCH(int, componentIndex);
44 QFETCH(int, componentIndex);
37 QFETCH(QVector<double>, expectedData);
45 QFETCH(QVector<double>, expectedData);
38
46
39 ArrayData<1> arrayData{inputData};
47 ArrayData<1> arrayData{inputData};
40 QVERIFY(arrayData.data(componentIndex) == expectedData);
48 QVERIFY(arrayData.data(componentIndex) == expectedData);
41 }
49 }
42
50
43 void TestOneDimArrayData::testAdd_data()
51 void TestOneDimArrayData::testAdd_data()
44 {
52 {
45 // Test structure
53 // Test structure
46 QTest::addColumn<QVector<double> >("inputData"); // array's data input
54 QTest::addColumn<QVector<double> >("inputData"); // array's data input
47 QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with
55 QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with
48 QTest::addColumn<bool>("prepend"); // prepend or append merge
56 QTest::addColumn<bool>("prepend"); // prepend or append merge
49 QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge
57 QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge
50
58
51 // Test cases
59 // Test cases
52 QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.}
60 QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.}
53 << QVector<double>{6., 7., 8.} << false
61 << QVector<double>{6., 7., 8.} << false
54 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.};
62 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.};
55 QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.}
63 QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.}
56 << QVector<double>{6., 7., 8.} << true
64 << QVector<double>{6., 7., 8.} << true
57 << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.};
65 << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.};
58 }
66 }
59
67
60 void TestOneDimArrayData::testAdd()
68 void TestOneDimArrayData::testAdd()
61 {
69 {
62 QFETCH(QVector<double>, inputData);
70 QFETCH(QVector<double>, inputData);
63 QFETCH(QVector<double>, otherData);
71 QFETCH(QVector<double>, otherData);
64 QFETCH(bool, prepend);
72 QFETCH(bool, prepend);
65 QFETCH(QVector<double>, expectedData);
73 QFETCH(QVector<double>, expectedData);
66
74
67 ArrayData<1> arrayData{inputData};
75 ArrayData<1> arrayData{inputData};
68 ArrayData<1> other{otherData};
76 ArrayData<1> other{otherData};
69
77
70 arrayData.add(other, prepend);
78 arrayData.add(other, prepend);
71 QVERIFY(arrayData.data() == expectedData);
79 QVERIFY(arrayData.data() == expectedData);
72 }
80 }
73
81
82 void TestOneDimArrayData::testClear()
83 {
84 QFETCH(QVector<double>, inputData);
85
86 ArrayData<1> arrayData{inputData};
87 arrayData.clear();
88 QVERIFY(arrayData.data() == QVector<double>{});
89 }
90
91 void TestOneDimArrayData::testSize_data()
92 {
93 // Test structure
94 QTest::addColumn<QVector<double> >("inputData"); // array data's input
95 QTest::addColumn<int>("expectedSize"); // expected array data size
96
97 // Test cases
98 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << 5;
99 }
100
101 void TestOneDimArrayData::testSize()
102 {
103 QFETCH(QVector<double>, inputData);
104 QFETCH(int, expectedSize);
105
106 ArrayData<1> arrayData{inputData};
107 QVERIFY(arrayData.size() == expectedSize);
108 }
109
74 QTEST_MAIN(TestOneDimArrayData)
110 QTEST_MAIN(TestOneDimArrayData)
75 #include "TestOneDimArrayData.moc"
111 #include "TestOneDimArrayData.moc"
@@ -1,93 +1,146
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()
14 /// Tests @sa ArrayData::add()
15 void testAdd_data();
15 void testAdd_data();
16 void testAdd();
16 void testAdd();
17
17
18 /// Tests @sa ArrayData::clear()
19 void testClear_data();
20 void testClear();
21
22 /// Tests @sa ArrayData::size()
23 void testSize_data();
24 void testSize();
25
18 };
26 };
19
27
20 void TestTwoDimArrayData::testDataByComponentIndex_data()
28 void TestTwoDimArrayData::testDataByComponentIndex_data()
21 {
29 {
22 // Test structure
30 // Test structure
23 QTest::addColumn<DataContainer>("inputData"); // array data's input
31 QTest::addColumn<DataContainer>("inputData"); // array data's input
24 QTest::addColumn<int>("componentIndex"); // component index to test
32 QTest::addColumn<int>("componentIndex"); // component index to test
25 QTest::addColumn<QVector<double> >("expectedData"); // expected data
33 QTest::addColumn<QVector<double> >("expectedData"); // expected data
26
34
27 // Test cases
35 // Test cases
28 auto inputData
36 auto inputData
29 = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
37 = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
30
38
31 QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.};
39 QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.};
32 QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.};
40 QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.};
33 QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.};
41 QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.};
34 QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{};
42 QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{};
35 QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{};
43 QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{};
36 }
44 }
37
45
38 void TestTwoDimArrayData::testDataByComponentIndex()
46 void TestTwoDimArrayData::testDataByComponentIndex()
39 {
47 {
40 QFETCH(DataContainer, inputData);
48 QFETCH(DataContainer, inputData);
41 QFETCH(int, componentIndex);
49 QFETCH(int, componentIndex);
42 QFETCH(QVector<double>, expectedData);
50 QFETCH(QVector<double>, expectedData);
43
51
44 ArrayData<2> arrayData{inputData};
52 ArrayData<2> arrayData{inputData};
45 QVERIFY(arrayData.data(componentIndex) == expectedData);
53 QVERIFY(arrayData.data(componentIndex) == expectedData);
46 }
54 }
47
55
48 void TestTwoDimArrayData::testAdd_data()
56 void TestTwoDimArrayData::testAdd_data()
49 {
57 {
50 // Test structure
58 // Test structure
51 QTest::addColumn<DataContainer>("inputData"); // array's data input
59 QTest::addColumn<DataContainer>("inputData"); // array's data input
52 QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with
60 QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with
53 QTest::addColumn<bool>("prepend"); // prepend or append merge
61 QTest::addColumn<bool>("prepend"); // prepend or append merge
54 QTest::addColumn<DataContainer>("expectedData"); // expected data after merge
62 QTest::addColumn<DataContainer>("expectedData"); // expected data after merge
55
63
56 // Test cases
64 // Test cases
57 auto inputData
65 auto inputData
58 = DataContainer{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}};
66 = DataContainer{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}};
59
67
60 auto vectorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}};
68 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},
69 auto tensorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28},
62 {36., 37., 38.}, {46., 47., 48.}, {56., 57., 58}};
70 {36., 37., 38.}, {46., 47., 48.}, {56., 57., 58}};
63
71
64 QTest::newRow("appendMerge") << inputData << vectorContainer << false
72 QTest::newRow("appendMerge") << inputData << vectorContainer << false
65 << DataContainer{{1., 2., 3., 4., 5., 6., 7., 8.},
73 << DataContainer{{1., 2., 3., 4., 5., 6., 7., 8.},
66 {11., 12., 13., 14., 15., 16., 17., 18.},
74 {11., 12., 13., 14., 15., 16., 17., 18.},
67 {21., 22., 23., 24., 25., 26., 27., 28}};
75 {21., 22., 23., 24., 25., 26., 27., 28}};
68 QTest::newRow("prependMerge") << inputData << vectorContainer << true
76 QTest::newRow("prependMerge") << inputData << vectorContainer << true
69 << DataContainer{{6., 7., 8., 1., 2., 3., 4., 5.},
77 << DataContainer{{6., 7., 8., 1., 2., 3., 4., 5.},
70 {16., 17., 18., 11., 12., 13., 14., 15.},
78 {16., 17., 18., 11., 12., 13., 14., 15.},
71 {26., 27., 28, 21., 22., 23., 24., 25.}};
79 {26., 27., 28, 21., 22., 23., 24., 25.}};
72 QTest::newRow("invalidMerge") << inputData << tensorContainer << false << inputData;
80 QTest::newRow("invalidMerge") << inputData << tensorContainer << false << inputData;
73 }
81 }
74
82
75 void TestTwoDimArrayData::testAdd()
83 void TestTwoDimArrayData::testAdd()
76 {
84 {
77 QFETCH(DataContainer, inputData);
85 QFETCH(DataContainer, inputData);
78 QFETCH(DataContainer, otherData);
86 QFETCH(DataContainer, otherData);
79 QFETCH(bool, prepend);
87 QFETCH(bool, prepend);
80 QFETCH(DataContainer, expectedData);
88 QFETCH(DataContainer, expectedData);
81
89
82 ArrayData<2> arrayData{inputData};
90 ArrayData<2> arrayData{inputData};
83 ArrayData<2> other{otherData};
91 ArrayData<2> other{otherData};
84
92
85 arrayData.add(other, prepend);
93 arrayData.add(other, prepend);
86
94
87 for (auto i = 0; i < expectedData.size(); ++i) {
95 for (auto i = 0; i < expectedData.size(); ++i) {
88 QVERIFY(arrayData.data(i) == expectedData.at(i));
96 QVERIFY(arrayData.data(i) == expectedData.at(i));
89 }
97 }
90 }
98 }
91
99
100 void TestTwoDimArrayData::testClear_data()
101 {
102 // Test structure
103 QTest::addColumn<DataContainer>("inputData"); // array data's input
104
105 // Test cases
106 QTest::newRow("data1") << DataContainer{
107 {1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}};
108 }
109
110 void TestTwoDimArrayData::testClear()
111 {
112 QFETCH(DataContainer, inputData);
113
114 ArrayData<2> arrayData{inputData};
115 arrayData.clear();
116
117 for (auto i = 0; i < inputData.size(); ++i) {
118 QVERIFY(arrayData.data(i) == QVector<double>{});
119 }
120 }
121
122 void TestTwoDimArrayData::testSize_data()
123 {
124 // Test structure
125 QTest::addColumn<QVector<QVector<double> > >("inputData"); // array data's input
126 QTest::addColumn<int>("expectedSize"); // expected array data size
127
128 // Test cases
129 QTest::newRow("data1") << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}} << 5;
130 QTest::newRow("data2") << DataContainer{{1., 2., 3., 4., 5.},
131 {6., 7., 8., 9., 10.},
132 {11., 12., 13., 14., 15.}}
133 << 5;
134 }
135
136 void TestTwoDimArrayData::testSize()
137 {
138 QFETCH(DataContainer, inputData);
139 QFETCH(int, expectedSize);
140
141 ArrayData<2> arrayData{inputData};
142 QVERIFY(arrayData.size() == expectedSize);
143 }
144
92 QTEST_MAIN(TestTwoDimArrayData)
145 QTEST_MAIN(TestTwoDimArrayData)
93 #include "TestTwoDimArrayData.moc"
146 #include "TestTwoDimArrayData.moc"
General Comments 0
You need to be logged in to leave comments. Login now