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