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