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