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