@@ -21,8 +21,31 private slots: | |||||
21 | void testSize_data(); |
|
21 | void testSize_data(); | |
22 | void testSize(); |
|
22 | void testSize(); | |
23 |
|
23 | |||
|
24 | /// Tests @sa ArrayData::sort() | |||
|
25 | void testSort_data(); | |||
|
26 | void testSort(); | |||
24 | }; |
|
27 | }; | |
25 |
|
28 | |||
|
29 | void TestOneDimArrayData::testData_data() | |||
|
30 | { | |||
|
31 | // Test structure | |||
|
32 | QTest::addColumn<QVector<double> >("inputData"); // array's data input | |||
|
33 | QTest::addColumn<QVector<double> >("expectedData"); // expected data | |||
|
34 | ||||
|
35 | // Test cases | |||
|
36 | QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} | |||
|
37 | << QVector<double>{1., 2., 3., 4., 5.}; | |||
|
38 | } | |||
|
39 | ||||
|
40 | void TestOneDimArrayData::testData() | |||
|
41 | { | |||
|
42 | QFETCH(QVector<double>, inputData); | |||
|
43 | QFETCH(QVector<double>, expectedData); | |||
|
44 | ||||
|
45 | ArrayData<1> arrayData{inputData}; | |||
|
46 | QVERIFY(arrayData.data() == expectedData); | |||
|
47 | } | |||
|
48 | ||||
26 | void TestOneDimArrayData::testDataByComponentIndex_data() |
|
49 | void TestOneDimArrayData::testDataByComponentIndex_data() | |
27 | { |
|
50 | { | |
28 | // Test structure |
|
51 | // Test structure | |
@@ -107,5 +130,31 void TestOneDimArrayData::testSize() | |||||
107 | QVERIFY(arrayData.size() == expectedSize); |
|
130 | QVERIFY(arrayData.size() == expectedSize); | |
108 | } |
|
131 | } | |
109 |
|
132 | |||
|
133 | void TestOneDimArrayData::testSort_data() | |||
|
134 | { | |||
|
135 | // Test structure | |||
|
136 | QTest::addColumn<QVector<double> >("inputData"); // array data's input | |||
|
137 | QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data | |||
|
138 | QTest::addColumn<QVector<double> >("expectedData"); // expected data after sorting | |||
|
139 | ||||
|
140 | // Test cases | |||
|
141 | 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.}; | |||
|
143 | 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.}; | |||
|
145 | } | |||
|
146 | ||||
|
147 | void TestOneDimArrayData::testSort() | |||
|
148 | { | |||
|
149 | QFETCH(QVector<double>, inputData); | |||
|
150 | QFETCH(std::vector<int>, sortPermutation); | |||
|
151 | QFETCH(QVector<double>, expectedData); | |||
|
152 | ||||
|
153 | ArrayData<1> arrayData{inputData}; | |||
|
154 | auto sortedArrayData = arrayData.sort(sortPermutation); | |||
|
155 | QVERIFY(sortedArrayData); | |||
|
156 | QVERIFY(sortedArrayData->data() == expectedData); | |||
|
157 | } | |||
|
158 | ||||
110 | QTEST_MAIN(TestOneDimArrayData) |
|
159 | QTEST_MAIN(TestOneDimArrayData) | |
111 | #include "TestOneDimArrayData.moc" |
|
160 | #include "TestOneDimArrayData.moc" |
@@ -23,6 +23,9 private slots: | |||||
23 | void testSize_data(); |
|
23 | void testSize_data(); | |
24 | void testSize(); |
|
24 | void testSize(); | |
25 |
|
25 | |||
|
26 | /// Tests @sa ArrayData::sort() | |||
|
27 | void testSort_data(); | |||
|
28 | void testSort(); | |||
26 | }; |
|
29 | }; | |
27 |
|
30 | |||
28 | void TestTwoDimArrayData::testDataByComponentIndex_data() |
|
31 | void TestTwoDimArrayData::testDataByComponentIndex_data() | |
@@ -142,5 +145,38 void TestTwoDimArrayData::testSize() | |||||
142 | QVERIFY(arrayData.size() == expectedSize); |
|
145 | QVERIFY(arrayData.size() == expectedSize); | |
143 | } |
|
146 | } | |
144 |
|
147 | |||
|
148 | void TestTwoDimArrayData::testSort_data() | |||
|
149 | { | |||
|
150 | // Test structure | |||
|
151 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |||
|
152 | QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data | |||
|
153 | QTest::addColumn<DataContainer>("expectedData"); // expected data after sorting | |||
|
154 | ||||
|
155 | // Test cases | |||
|
156 | QTest::newRow("data1") | |||
|
157 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}} | |||
|
158 | << std::vector<int>{0, 2, 3, 1, 4} | |||
|
159 | << DataContainer{{1., 3., 4., 2., 5.}, {6., 8., 9., 7., 10.}, {11., 13., 14., 12., 15.}}; | |||
|
160 | QTest::newRow("data2") | |||
|
161 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}} | |||
|
162 | << std::vector<int>{2, 4, 3, 0, 1} | |||
|
163 | << DataContainer{{3., 5., 4., 1., 2.}, {8., 10., 9., 6., 7.}, {13., 15., 14., 11., 12.}}; | |||
|
164 | } | |||
|
165 | ||||
|
166 | void TestTwoDimArrayData::testSort() | |||
|
167 | { | |||
|
168 | QFETCH(DataContainer, inputData); | |||
|
169 | QFETCH(std::vector<int>, sortPermutation); | |||
|
170 | QFETCH(DataContainer, expectedData); | |||
|
171 | ||||
|
172 | ArrayData<2> arrayData{inputData}; | |||
|
173 | auto sortedArrayData = arrayData.sort(sortPermutation); | |||
|
174 | QVERIFY(sortedArrayData); | |||
|
175 | ||||
|
176 | for (auto i = 0; i < expectedData.size(); ++i) { | |||
|
177 | QVERIFY(sortedArrayData->data(i) == expectedData.at(i)); | |||
|
178 | } | |||
|
179 | } | |||
|
180 | ||||
145 | QTEST_MAIN(TestTwoDimArrayData) |
|
181 | QTEST_MAIN(TestTwoDimArrayData) | |
146 | #include "TestTwoDimArrayData.moc" |
|
182 | #include "TestTwoDimArrayData.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now