@@ -1,111 +1,160 | |||
|
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 | 16 | /// Tests @sa ArrayData::clear() |
|
17 | 17 | void testClear_data(); |
|
18 | 18 | void testClear(); |
|
19 | 19 | |
|
20 | 20 | /// Tests @sa ArrayData::size() |
|
21 | 21 | void testSize_data(); |
|
22 | 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 | 49 | void TestOneDimArrayData::testDataByComponentIndex_data() |
|
27 | 50 | { |
|
28 | 51 | // Test structure |
|
29 | 52 | QTest::addColumn<QVector<double> >("inputData"); // array data's input |
|
30 | 53 | QTest::addColumn<int>("componentIndex"); // component index to test |
|
31 | 54 | QTest::addColumn<QVector<double> >("expectedData"); // expected data |
|
32 | 55 | |
|
33 | 56 | // Test cases |
|
34 | 57 | QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0 |
|
35 | 58 | << QVector<double>{1., 2., 3., 4., 5.}; |
|
36 | 59 | QTest::newRow("invalidIndex1") |
|
37 | 60 | << QVector<double>{1., 2., 3., 4., 5.} << -1 << QVector<double>{}; |
|
38 | 61 | QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{}; |
|
39 | 62 | } |
|
40 | 63 | |
|
41 | 64 | void TestOneDimArrayData::testDataByComponentIndex() |
|
42 | 65 | { |
|
43 | 66 | QFETCH(QVector<double>, inputData); |
|
44 | 67 | QFETCH(int, componentIndex); |
|
45 | 68 | QFETCH(QVector<double>, expectedData); |
|
46 | 69 | |
|
47 | 70 | ArrayData<1> arrayData{inputData}; |
|
48 | 71 | QVERIFY(arrayData.data(componentIndex) == expectedData); |
|
49 | 72 | } |
|
50 | 73 | |
|
51 | 74 | void TestOneDimArrayData::testAdd_data() |
|
52 | 75 | { |
|
53 | 76 | // Test structure |
|
54 | 77 | QTest::addColumn<QVector<double> >("inputData"); // array's data input |
|
55 | 78 | QTest::addColumn<QVector<double> >("otherData"); // array data's input to merge with |
|
56 | 79 | QTest::addColumn<bool>("prepend"); // prepend or append merge |
|
57 | 80 | QTest::addColumn<QVector<double> >("expectedData"); // expected data after merge |
|
58 | 81 | |
|
59 | 82 | // Test cases |
|
60 | 83 | QTest::newRow("appendMerge") << QVector<double>{1., 2., 3., 4., 5.} |
|
61 | 84 | << QVector<double>{6., 7., 8.} << false |
|
62 | 85 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8.}; |
|
63 | 86 | QTest::newRow("prependMerge") << QVector<double>{1., 2., 3., 4., 5.} |
|
64 | 87 | << QVector<double>{6., 7., 8.} << true |
|
65 | 88 | << QVector<double>{6., 7., 8., 1., 2., 3., 4., 5.}; |
|
66 | 89 | } |
|
67 | 90 | |
|
68 | 91 | void TestOneDimArrayData::testAdd() |
|
69 | 92 | { |
|
70 | 93 | QFETCH(QVector<double>, inputData); |
|
71 | 94 | QFETCH(QVector<double>, otherData); |
|
72 | 95 | QFETCH(bool, prepend); |
|
73 | 96 | QFETCH(QVector<double>, expectedData); |
|
74 | 97 | |
|
75 | 98 | ArrayData<1> arrayData{inputData}; |
|
76 | 99 | ArrayData<1> other{otherData}; |
|
77 | 100 | |
|
78 | 101 | arrayData.add(other, prepend); |
|
79 | 102 | QVERIFY(arrayData.data() == expectedData); |
|
80 | 103 | } |
|
81 | 104 | |
|
82 | 105 | void TestOneDimArrayData::testClear() |
|
83 | 106 | { |
|
84 | 107 | QFETCH(QVector<double>, inputData); |
|
85 | 108 | |
|
86 | 109 | ArrayData<1> arrayData{inputData}; |
|
87 | 110 | arrayData.clear(); |
|
88 | 111 | QVERIFY(arrayData.data() == QVector<double>{}); |
|
89 | 112 | } |
|
90 | 113 | |
|
91 | 114 | void TestOneDimArrayData::testSize_data() |
|
92 | 115 | { |
|
93 | 116 | // Test structure |
|
94 | 117 | QTest::addColumn<QVector<double> >("inputData"); // array data's input |
|
95 | 118 | QTest::addColumn<int>("expectedSize"); // expected array data size |
|
96 | 119 | |
|
97 | 120 | // Test cases |
|
98 | 121 | QTest::newRow("data1") << QVector<double>{1., 2., 3., 4., 5.} << 5; |
|
99 | 122 | } |
|
100 | 123 | |
|
101 | 124 | void TestOneDimArrayData::testSize() |
|
102 | 125 | { |
|
103 | 126 | QFETCH(QVector<double>, inputData); |
|
104 | 127 | QFETCH(int, expectedSize); |
|
105 | 128 | |
|
106 | 129 | ArrayData<1> arrayData{inputData}; |
|
107 | 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 | 159 | QTEST_MAIN(TestOneDimArrayData) |
|
111 | 160 | #include "TestOneDimArrayData.moc" |
@@ -1,146 +1,182 | |||
|
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 | 18 | /// Tests @sa ArrayData::clear() |
|
19 | 19 | void testClear_data(); |
|
20 | 20 | void testClear(); |
|
21 | 21 | |
|
22 | 22 | /// Tests @sa ArrayData::size() |
|
23 | 23 | void testSize_data(); |
|
24 | 24 | void testSize(); |
|
25 | 25 | |
|
26 | /// Tests @sa ArrayData::sort() | |
|
27 | void testSort_data(); | |
|
28 | void testSort(); | |
|
26 | 29 | }; |
|
27 | 30 | |
|
28 | 31 | void TestTwoDimArrayData::testDataByComponentIndex_data() |
|
29 | 32 | { |
|
30 | 33 | // Test structure |
|
31 | 34 | QTest::addColumn<DataContainer>("inputData"); // array data's input |
|
32 | 35 | QTest::addColumn<int>("componentIndex"); // component index to test |
|
33 | 36 | QTest::addColumn<QVector<double> >("expectedData"); // expected data |
|
34 | 37 | |
|
35 | 38 | // Test cases |
|
36 | 39 | auto inputData |
|
37 | 40 | = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; |
|
38 | 41 | |
|
39 | 42 | QTest::newRow("validIndex1") << inputData << 0 << QVector<double>{1., 2., 3., 4., 5.}; |
|
40 | 43 | QTest::newRow("validIndex2") << inputData << 1 << QVector<double>{6., 7., 8., 9., 10.}; |
|
41 | 44 | QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.}; |
|
42 | 45 | QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{}; |
|
43 | 46 | QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{}; |
|
44 | 47 | } |
|
45 | 48 | |
|
46 | 49 | void TestTwoDimArrayData::testDataByComponentIndex() |
|
47 | 50 | { |
|
48 | 51 | QFETCH(DataContainer, inputData); |
|
49 | 52 | QFETCH(int, componentIndex); |
|
50 | 53 | QFETCH(QVector<double>, expectedData); |
|
51 | 54 | |
|
52 | 55 | ArrayData<2> arrayData{inputData}; |
|
53 | 56 | QVERIFY(arrayData.data(componentIndex) == expectedData); |
|
54 | 57 | } |
|
55 | 58 | |
|
56 | 59 | void TestTwoDimArrayData::testAdd_data() |
|
57 | 60 | { |
|
58 | 61 | // Test structure |
|
59 | 62 | QTest::addColumn<DataContainer>("inputData"); // array's data input |
|
60 | 63 | QTest::addColumn<DataContainer>("otherData"); // array data's input to merge with |
|
61 | 64 | QTest::addColumn<bool>("prepend"); // prepend or append merge |
|
62 | 65 | QTest::addColumn<DataContainer>("expectedData"); // expected data after merge |
|
63 | 66 | |
|
64 | 67 | // Test cases |
|
65 | 68 | auto inputData |
|
66 | 69 | = DataContainer{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}}; |
|
67 | 70 | |
|
68 | 71 | auto vectorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}}; |
|
69 | 72 | auto tensorContainer = DataContainer{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}, |
|
70 | 73 | {36., 37., 38.}, {46., 47., 48.}, {56., 57., 58}}; |
|
71 | 74 | |
|
72 | 75 | QTest::newRow("appendMerge") << inputData << vectorContainer << false |
|
73 | 76 | << DataContainer{{1., 2., 3., 4., 5., 6., 7., 8.}, |
|
74 | 77 | {11., 12., 13., 14., 15., 16., 17., 18.}, |
|
75 | 78 | {21., 22., 23., 24., 25., 26., 27., 28}}; |
|
76 | 79 | QTest::newRow("prependMerge") << inputData << vectorContainer << true |
|
77 | 80 | << DataContainer{{6., 7., 8., 1., 2., 3., 4., 5.}, |
|
78 | 81 | {16., 17., 18., 11., 12., 13., 14., 15.}, |
|
79 | 82 | {26., 27., 28, 21., 22., 23., 24., 25.}}; |
|
80 | 83 | QTest::newRow("invalidMerge") << inputData << tensorContainer << false << inputData; |
|
81 | 84 | } |
|
82 | 85 | |
|
83 | 86 | void TestTwoDimArrayData::testAdd() |
|
84 | 87 | { |
|
85 | 88 | QFETCH(DataContainer, inputData); |
|
86 | 89 | QFETCH(DataContainer, otherData); |
|
87 | 90 | QFETCH(bool, prepend); |
|
88 | 91 | QFETCH(DataContainer, expectedData); |
|
89 | 92 | |
|
90 | 93 | ArrayData<2> arrayData{inputData}; |
|
91 | 94 | ArrayData<2> other{otherData}; |
|
92 | 95 | |
|
93 | 96 | arrayData.add(other, prepend); |
|
94 | 97 | |
|
95 | 98 | for (auto i = 0; i < expectedData.size(); ++i) { |
|
96 | 99 | QVERIFY(arrayData.data(i) == expectedData.at(i)); |
|
97 | 100 | } |
|
98 | 101 | } |
|
99 | 102 | |
|
100 | 103 | void TestTwoDimArrayData::testClear_data() |
|
101 | 104 | { |
|
102 | 105 | // Test structure |
|
103 | 106 | QTest::addColumn<DataContainer>("inputData"); // array data's input |
|
104 | 107 | |
|
105 | 108 | // Test cases |
|
106 | 109 | QTest::newRow("data1") << DataContainer{ |
|
107 | 110 | {1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; |
|
108 | 111 | } |
|
109 | 112 | |
|
110 | 113 | void TestTwoDimArrayData::testClear() |
|
111 | 114 | { |
|
112 | 115 | QFETCH(DataContainer, inputData); |
|
113 | 116 | |
|
114 | 117 | ArrayData<2> arrayData{inputData}; |
|
115 | 118 | arrayData.clear(); |
|
116 | 119 | |
|
117 | 120 | for (auto i = 0; i < inputData.size(); ++i) { |
|
118 | 121 | QVERIFY(arrayData.data(i) == QVector<double>{}); |
|
119 | 122 | } |
|
120 | 123 | } |
|
121 | 124 | |
|
122 | 125 | void TestTwoDimArrayData::testSize_data() |
|
123 | 126 | { |
|
124 | 127 | // Test structure |
|
125 | 128 | QTest::addColumn<QVector<QVector<double> > >("inputData"); // array data's input |
|
126 | 129 | QTest::addColumn<int>("expectedSize"); // expected array data size |
|
127 | 130 | |
|
128 | 131 | // Test cases |
|
129 | 132 | QTest::newRow("data1") << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}} << 5; |
|
130 | 133 | QTest::newRow("data2") << DataContainer{{1., 2., 3., 4., 5.}, |
|
131 | 134 | {6., 7., 8., 9., 10.}, |
|
132 | 135 | {11., 12., 13., 14., 15.}} |
|
133 | 136 | << 5; |
|
134 | 137 | } |
|
135 | 138 | |
|
136 | 139 | void TestTwoDimArrayData::testSize() |
|
137 | 140 | { |
|
138 | 141 | QFETCH(DataContainer, inputData); |
|
139 | 142 | QFETCH(int, expectedSize); |
|
140 | 143 | |
|
141 | 144 | ArrayData<2> arrayData{inputData}; |
|
142 | 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 | 181 | QTEST_MAIN(TestTwoDimArrayData) |
|
146 | 182 | #include "TestTwoDimArrayData.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now