##// END OF EJS Templates
Tests specific methods of 1-dim array data
Alexandre Leroux -
r519:766a3018077c
parent child
Show More
@@ -1,160 +1,199
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()
9 void testData_data();
10 void testData();
11
8 /// Tests @sa ArrayData::data(int componentIndex)
12 /// Tests @sa ArrayData::data(int componentIndex)
9 void testDataByComponentIndex_data();
13 void testDataByComponentIndex_data();
10 void testDataByComponentIndex();
14 void testDataByComponentIndex();
11
15
12 /// Tests @sa ArrayData::add()
16 /// Tests @sa ArrayData::add()
13 void testAdd_data();
17 void testAdd_data();
14 void testAdd();
18 void testAdd();
15
19
20 /// Tests @sa ArrayData::at(int index)
21 void testAt_data();
22 void testAt();
23
16 /// Tests @sa ArrayData::clear()
24 /// Tests @sa ArrayData::clear()
17 void testClear_data();
25 void testClear_data();
18 void testClear();
26 void testClear();
19
27
20 /// Tests @sa ArrayData::size()
28 /// Tests @sa ArrayData::size()
21 void testSize_data();
29 void testSize_data();
22 void testSize();
30 void testSize();
23
31
24 /// Tests @sa ArrayData::sort()
32 /// Tests @sa ArrayData::sort()
25 void testSort_data();
33 void testSort_data();
26 void testSort();
34 void testSort();
27 };
35 };
28
36
29 void TestOneDimArrayData::testData_data()
37 void TestOneDimArrayData::testData_data()
30 {
38 {
31 // Test structure
39 // Test structure
32 QTest::addColumn<QVector<double> >("inputData"); // array's data input
40 QTest::addColumn<QVector<double> >("inputData"); // array's data input
33 QTest::addColumn<QVector<double> >("expectedData"); // expected data
41 QTest::addColumn<QVector<double> >("expectedData"); // expected data
34
42
35 // Test cases
43 // Test cases
36 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.}
44 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.}
37 << QVector<double>{1., 2., 3., 4., 5.};
45 << QVector<double>{1., 2., 3., 4., 5.};
38 }
46 }
39
47
40 void TestOneDimArrayData::testData()
48 void TestOneDimArrayData::testData()
41 {
49 {
42 QFETCH(QVector<double>, inputData);
50 QFETCH(QVector<double>, inputData);
43 QFETCH(QVector<double>, expectedData);
51 QFETCH(QVector<double>, expectedData);
44
52
45 ArrayData<1> arrayData{inputData};
53 ArrayData<1> arrayData{inputData};
46 QVERIFY(arrayData.data() == expectedData);
54 QVERIFY(arrayData.data() == expectedData);
47 }
55 }
48
56
49 void TestOneDimArrayData::testDataByComponentIndex_data()
57 void TestOneDimArrayData::testDataByComponentIndex_data()
50 {
58 {
51 // Test structure
59 // Test structure
52 QTest::addColumn<QVector<double> >("inputData"); // array data's input
60 QTest::addColumn<QVector<double> >("inputData"); // array data's input
53 QTest::addColumn<int>("componentIndex"); // component index to test
61 QTest::addColumn<int>("componentIndex"); // component index to test
54 QTest::addColumn<QVector<double> >("expectedData"); // expected data
62 QTest::addColumn<QVector<double> >("expectedData"); // expected data
55
63
56 // Test cases
64 // Test cases
57 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
65 QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0
58 << QVector<double>{1., 2., 3., 4., 5.};
66 << QVector<double>{1., 2., 3., 4., 5.};
59 QTest::newRow("invalidIndex1")
67 QTest::newRow("invalidIndex1")
60 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
68 << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{};
61 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
69 QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{};
62 }
70 }
63
71
64 void TestOneDimArrayData::testDataByComponentIndex()
72 void TestOneDimArrayData::testDataByComponentIndex()
65 {
73 {
66 QFETCH(QVector<double>, inputData);
74 QFETCH(QVector<double>, inputData);
67 QFETCH(int, componentIndex);
75 QFETCH(int, componentIndex);
68 QFETCH(QVector<double>, expectedData);
76 QFETCH(QVector<double>, expectedData);
69
77
70 ArrayData<1> arrayData{inputData};
78 ArrayData<1> arrayData{inputData};
71 QVERIFY(arrayData.data(componentIndex) == expectedData);
79 QVERIFY(arrayData.data(componentIndex) == expectedData);
72 }
80 }
73
81
74 void TestOneDimArrayData::testAdd_data()
82 void TestOneDimArrayData::testAdd_data()
75 {
83 {
76 // Test structure
84 // Test structure
77 QTest::addColumn<QVector<double> >("inputData"); // array's data input
85 QTest::addColumn<QVector<double> >("inputData"); // array's data input
78 QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with
86 QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with
79 QTest::addColumn<bool>("prepend"); // prepend or append merge
87 QTest::addColumn<bool>("prepend"); // prepend or append merge
80 QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge
88 QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge
81
89
82 // Test cases
90 // Test cases
83 QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.}
91 QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.}
84 << QVector<double>{6., 7., 8.} << false
92 << QVector<double>{6., 7., 8.} << false
85 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.};
93 << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.};
86 QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.}
94 QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.}
87 << QVector<double>{6., 7., 8.} << true
95 << QVector<double>{6., 7., 8.} << true
88 << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.};
96 << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.};
89 }
97 }
90
98
91 void TestOneDimArrayData::testAdd()
99 void TestOneDimArrayData::testAdd()
92 {
100 {
93 QFETCH(QVector<double>, inputData);
101 QFETCH(QVector<double>, inputData);
94 QFETCH(QVector<double>, otherData);
102 QFETCH(QVector<double>, otherData);
95 QFETCH(bool, prepend);
103 QFETCH(bool, prepend);
96 QFETCH(QVector<double>, expectedData);
104 QFETCH(QVector<double>, expectedData);
97
105
98 ArrayData<1> arrayData{inputData};
106 ArrayData<1> arrayData{inputData};
99 ArrayData<1> other{otherData};
107 ArrayData<1> other{otherData};
100
108
101 arrayData.add(other, prepend);
109 arrayData.add(other, prepend);
102 QVERIFY(arrayData.data() == expectedData);
110 QVERIFY(arrayData.data() == expectedData);
103 }
111 }
104
112
113 void TestOneDimArrayData::testAt_data()
114 {
115 // Test structure
116 QTest::addColumn<QVector<double> >("inputData"); // array data's input
117 QTest::addColumn<int>("index"); // index to retrieve data
118 QTest::addColumn<double>("expectedData"); // expected data at index
119
120 // Test cases
121 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << 0 << 1.;
122 QTest::newRow("data2") << QVector<double>{1., 2., 3., 4., 5.} << 3 << 4.;
123 }
124
125 void TestOneDimArrayData::testAt()
126 {
127 QFETCH(QVector<double>, inputData);
128 QFETCH(int, index);
129 QFETCH(double, expectedData);
130
131 ArrayData<1> arrayData{inputData};
132 QVERIFY(arrayData.at(index) == expectedData);
133 }
134
135 void TestOneDimArrayData::testClear_data()
136 {
137 // Test structure
138 QTest::addColumn<QVector<double> >("inputData"); // array data's input
139
140 // Test cases
141 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.};
142 }
143
105 void TestOneDimArrayData::testClear()
144 void TestOneDimArrayData::testClear()
106 {
145 {
107 QFETCH(QVector<double>, inputData);
146 QFETCH(QVector<double>, inputData);
108
147
109 ArrayData<1> arrayData{inputData};
148 ArrayData<1> arrayData{inputData};
110 arrayData.clear();
149 arrayData.clear();
111 QVERIFY(arrayData.data() == QVector<double>{});
150 QVERIFY(arrayData.data() == QVector<double>{});
112 }
151 }
113
152
114 void TestOneDimArrayData::testSize_data()
153 void TestOneDimArrayData::testSize_data()
115 {
154 {
116 // Test structure
155 // Test structure
117 QTest::addColumn<QVector<double> >("inputData"); // array data's input
156 QTest::addColumn<QVector<double> >("inputData"); // array data's input
118 QTest::addColumn<int>("expectedSize"); // expected array data size
157 QTest::addColumn<int>("expectedSize"); // expected array data size
119
158
120 // Test cases
159 // Test cases
121 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << 5;
160 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << 5;
122 }
161 }
123
162
124 void TestOneDimArrayData::testSize()
163 void TestOneDimArrayData::testSize()
125 {
164 {
126 QFETCH(QVector<double>, inputData);
165 QFETCH(QVector<double>, inputData);
127 QFETCH(int, expectedSize);
166 QFETCH(int, expectedSize);
128
167
129 ArrayData<1> arrayData{inputData};
168 ArrayData<1> arrayData{inputData};
130 QVERIFY(arrayData.size() == expectedSize);
169 QVERIFY(arrayData.size() == expectedSize);
131 }
170 }
132
171
133 void TestOneDimArrayData::testSort_data()
172 void TestOneDimArrayData::testSort_data()
134 {
173 {
135 // Test structure
174 // Test structure
136 QTest::addColumn<QVector<double> >("inputData"); // array data's input
175 QTest::addColumn<QVector<double> >("inputData"); // array data's input
137 QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data
176 QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data
138 QTest::addColumn<QVector<double> >("expectedData"); // expected data after sorting
177 QTest::addColumn<QVector<double> >("expectedData"); // expected data after sorting
139
178
140 // Test cases
179 // Test cases
141 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << std::vector<int>{0, 2, 3, 1, 4}
180 QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << std::vector<int>{0, 2, 3, 1, 4}
142 << QVector<double>{1., 3., 4., 2., 5.};
181 << QVector<double>{1., 3., 4., 2., 5.};
143 QTest::newRow("data2") << QVector<double>{1., 2., 3., 4., 5.} << std::vector<int>{4, 1, 2, 3, 0}
182 QTest::newRow("data2") << QVector<double>{1., 2., 3., 4., 5.} << std::vector<int>{4, 1, 2, 3, 0}
144 << QVector<double>{5., 2., 3., 4., 1.};
183 << QVector<double>{5., 2., 3., 4., 1.};
145 }
184 }
146
185
147 void TestOneDimArrayData::testSort()
186 void TestOneDimArrayData::testSort()
148 {
187 {
149 QFETCH(QVector<double>, inputData);
188 QFETCH(QVector<double>, inputData);
150 QFETCH(std::vector<int>, sortPermutation);
189 QFETCH(std::vector<int>, sortPermutation);
151 QFETCH(QVector<double>, expectedData);
190 QFETCH(QVector<double>, expectedData);
152
191
153 ArrayData<1> arrayData{inputData};
192 ArrayData<1> arrayData{inputData};
154 auto sortedArrayData = arrayData.sort(sortPermutation);
193 auto sortedArrayData = arrayData.sort(sortPermutation);
155 QVERIFY(sortedArrayData);
194 QVERIFY(sortedArrayData);
156 QVERIFY(sortedArrayData->data() == expectedData);
195 QVERIFY(sortedArrayData->data() == expectedData);
157 }
196 }
158
197
159 QTEST_MAIN(TestOneDimArrayData)
198 QTEST_MAIN(TestOneDimArrayData)
160 #include "TestOneDimArrayData.moc"
199 #include "TestOneDimArrayData.moc"
General Comments 0
You need to be logged in to leave comments. Login now