@@ -10,6 +10,20 | |||
|
10 | 10 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) |
|
11 | 11 | Q_DECLARE_METATYPE(std::shared_ptr<VectorSeries>) |
|
12 | 12 | |
|
13 | namespace { | |
|
14 | ||
|
15 | void validateRange(DataSeriesIterator first, DataSeriesIterator last, const QVector<double> &xData, | |
|
16 | const QVector<double> &valuesData) | |
|
17 | { | |
|
18 | QVERIFY(std::equal(first, last, xData.cbegin(), xData.cend(), | |
|
19 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); | |
|
20 | QVERIFY(std::equal( | |
|
21 | first, last, valuesData.cbegin(), valuesData.cend(), | |
|
22 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); | |
|
23 | } | |
|
24 | ||
|
25 | } // namespace | |
|
26 | ||
|
13 | 27 | class TestDataSeries : public QObject { |
|
14 | 28 | Q_OBJECT |
|
15 | 29 | private: |
@@ -164,13 +178,7 void TestDataSeries::testCtor() | |||
|
164 | 178 | QFETCH(QVector<double>, expectedXAxisData); |
|
165 | 179 | QFETCH(QVector<double>, expectedValuesData); |
|
166 | 180 | |
|
167 | auto seriesXAxisData = series->xAxisData()->data(); | |
|
168 | auto seriesValuesData = series->valuesData()->data(); | |
|
169 | ||
|
170 | QVERIFY( | |
|
171 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); | |
|
172 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), | |
|
173 | seriesValuesData.cbegin())); | |
|
181 | validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedValuesData); | |
|
174 | 182 | } |
|
175 | 183 | |
|
176 | 184 | namespace { |
@@ -250,13 +258,7 void TestDataSeries::testMerge() | |||
|
250 | 258 | QFETCH(QVector<double>, expectedXAxisData); |
|
251 | 259 | QFETCH(QVector<double>, expectedValuesData); |
|
252 | 260 | |
|
253 | auto seriesXAxisData = dataSeries->xAxisData()->data(); | |
|
254 | auto seriesValuesData = dataSeries->valuesData()->data(); | |
|
255 | ||
|
256 | QVERIFY( | |
|
257 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); | |
|
258 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), | |
|
259 | seriesValuesData.cbegin())); | |
|
261 | validateRange(dataSeries->cbegin(), dataSeries->cend(), expectedXAxisData, expectedValuesData); | |
|
260 | 262 | } |
|
261 | 263 | |
|
262 | 264 | void TestDataSeries::testMinXAxisData_data() |
@@ -438,12 +440,7 void TestDataSeries::testXAxisRange() | |||
|
438 | 440 | QFETCH(QVector<double>, expectedValuesData); |
|
439 | 441 | |
|
440 | 442 | auto bounds = dataSeries->xAxisRange(min, max); |
|
441 |
|
|
|
442 | expectedXAxisData.cend(), | |
|
443 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); | |
|
444 | QVERIFY(std::equal( | |
|
445 | bounds.first, bounds.second, expectedValuesData.cbegin(), expectedValuesData.cend(), | |
|
446 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); | |
|
443 | validateRange(bounds.first, bounds.second, expectedXAxisData, expectedValuesData); | |
|
447 | 444 | } |
|
448 | 445 | |
|
449 | 446 | void TestDataSeries::testValuesBoundsScalar_data() |
@@ -2,6 +2,17 | |||
|
2 | 2 | #include <QObject> |
|
3 | 3 | #include <QtTest> |
|
4 | 4 | |
|
5 | namespace { | |
|
6 | ||
|
7 | void verifyArrayData(const ArrayData<1> &arrayData, const QVector<double> &expectedData) | |
|
8 | { | |
|
9 | QVERIFY(std::equal( | |
|
10 | arrayData.cbegin(), arrayData.cend(), expectedData.cbegin(), expectedData.cend(), | |
|
11 | [](const auto &it, const auto &expectedData) { return it.at(0) == expectedData; })); | |
|
12 | } | |
|
13 | ||
|
14 | } // namespace | |
|
15 | ||
|
5 | 16 | class TestOneDimArrayData : public QObject { |
|
6 | 17 | Q_OBJECT |
|
7 | 18 | private slots: |
@@ -9,10 +20,6 private slots: | |||
|
9 | 20 | void testData_data(); |
|
10 | 21 | void testData(); |
|
11 | 22 | |
|
12 | /// Tests @sa ArrayData::data(int componentIndex) | |
|
13 | void testDataByComponentIndex_data(); | |
|
14 | void testDataByComponentIndex(); | |
|
15 | ||
|
16 | 23 | /// Tests @sa ArrayData::add() |
|
17 | 24 | void testAdd_data(); |
|
18 | 25 | void testAdd(); |
@@ -51,32 +58,7 void TestOneDimArrayData::testData() | |||
|
51 | 58 | QFETCH(QVector<double>, expectedData); |
|
52 | 59 | |
|
53 | 60 | ArrayData<1> arrayData{inputData}; |
|
54 |
|
|
|
55 | } | |
|
56 | ||
|
57 | void TestOneDimArrayData::testDataByComponentIndex_data() | |
|
58 | { | |
|
59 | // Test structure | |
|
60 | QTest::addColumn<QVector<double> >("inputData"); // array data's input | |
|
61 | QTest::addColumn<int>("componentIndex"); // component index to test | |
|
62 | QTest::addColumn<QVector<double> >("expectedData"); // expected data | |
|
63 | ||
|
64 | // Test cases | |
|
65 | QTest::newRow("validIndex") << QVector<double>{1., 2., 3., 4., 5.} << 0 | |
|
66 | << QVector<double>{1., 2., 3., 4., 5.}; | |
|
67 | QTest::newRow("invalidIndex1") << QVector<double>{1., 2., 3., 4., 5.} << -1 | |
|
68 | << QVector<double>{}; | |
|
69 | QTest::newRow("invalidIndex2") << QVector<double>{1., 2., 3., 4., 5.} << 1 << QVector<double>{}; | |
|
70 | } | |
|
71 | ||
|
72 | void TestOneDimArrayData::testDataByComponentIndex() | |
|
73 | { | |
|
74 | QFETCH(QVector<double>, inputData); | |
|
75 | QFETCH(int, componentIndex); | |
|
76 | QFETCH(QVector<double>, expectedData); | |
|
77 | ||
|
78 | ArrayData<1> arrayData{inputData}; | |
|
79 | QVERIFY(arrayData.data(componentIndex) == expectedData); | |
|
61 | verifyArrayData(arrayData, expectedData); | |
|
80 | 62 | } |
|
81 | 63 | |
|
82 | 64 | void TestOneDimArrayData::testAdd_data() |
@@ -107,7 +89,7 void TestOneDimArrayData::testAdd() | |||
|
107 | 89 | ArrayData<1> other{otherData}; |
|
108 | 90 | |
|
109 | 91 | arrayData.add(other, prepend); |
|
110 |
|
|
|
92 | verifyArrayData(arrayData, expectedData); | |
|
111 | 93 | } |
|
112 | 94 | |
|
113 | 95 | void TestOneDimArrayData::testAt_data() |
@@ -147,7 +129,7 void TestOneDimArrayData::testClear() | |||
|
147 | 129 | |
|
148 | 130 | ArrayData<1> arrayData{inputData}; |
|
149 | 131 | arrayData.clear(); |
|
150 |
|
|
|
132 | verifyArrayData(arrayData, QVector<double>{}); | |
|
151 | 133 | } |
|
152 | 134 | |
|
153 | 135 | void TestOneDimArrayData::testSize_data() |
@@ -192,7 +174,7 void TestOneDimArrayData::testSort() | |||
|
192 | 174 | ArrayData<1> arrayData{inputData}; |
|
193 | 175 | auto sortedArrayData = arrayData.sort(sortPermutation); |
|
194 | 176 | QVERIFY(sortedArrayData != nullptr); |
|
195 |
|
|
|
177 | verifyArrayData(*sortedArrayData, expectedData); | |
|
196 | 178 | } |
|
197 | 179 | |
|
198 | 180 | QTEST_MAIN(TestOneDimArrayData) |
@@ -2,15 +2,55 | |||
|
2 | 2 | #include <QObject> |
|
3 | 3 | #include <QtTest> |
|
4 | 4 | |
|
5 |
using |
|
|
5 | using Container = QVector<QVector<double> >; | |
|
6 | using InputData = QPair<QVector<double>, int>; | |
|
7 | ||
|
8 | namespace { | |
|
9 | ||
|
10 | InputData flatten(const Container &container) | |
|
11 | { | |
|
12 | if (container.isEmpty()) { | |
|
13 | return {}; | |
|
14 | } | |
|
15 | ||
|
16 | // We assume here that each component of the container have the same size | |
|
17 | auto containerSize = container.size(); | |
|
18 | auto componentSize = container.first().size(); | |
|
19 | ||
|
20 | auto result = QVector<double>{}; | |
|
21 | result.reserve(componentSize * containerSize); | |
|
22 | ||
|
23 | for (auto i = 0; i < componentSize; ++i) { | |
|
24 | for (auto j = 0; j < containerSize; ++j) { | |
|
25 | result.append(container.at(j).at(i)); | |
|
26 | } | |
|
27 | } | |
|
28 | ||
|
29 | return {result, containerSize}; | |
|
30 | } | |
|
31 | ||
|
32 | void verifyArrayData(const ArrayData<2> &arrayData, const Container &expectedData) | |
|
33 | { | |
|
34 | auto verifyComponent = [&arrayData](const auto &componentData, const auto &equalFun) { | |
|
35 | QVERIFY(std::equal(arrayData.cbegin(), arrayData.cend(), componentData.cbegin(), | |
|
36 | componentData.cend(), | |
|
37 | [&equalFun](const auto &dataSeriesIt, const auto &expectedValue) { | |
|
38 | return equalFun(dataSeriesIt, expectedValue); | |
|
39 | })); | |
|
40 | }; | |
|
41 | ||
|
42 | for (auto i = 0; i < expectedData.size(); ++i) { | |
|
43 | verifyComponent(expectedData.at(i), [i](const auto &seriesIt, const auto &value) { | |
|
44 | return seriesIt.at(i) == value; | |
|
45 | }); | |
|
46 | } | |
|
47 | } | |
|
48 | ||
|
49 | } // namespace | |
|
6 | 50 | |
|
7 | 51 | class TestTwoDimArrayData : public QObject { |
|
8 | 52 | Q_OBJECT |
|
9 | 53 | private slots: |
|
10 | /// Tests @sa ArrayData::data(int componentIndex) | |
|
11 | void testDataByComponentIndex_data(); | |
|
12 | void testDataByComponentIndex(); | |
|
13 | ||
|
14 | 54 | /// Tests @sa ArrayData ctor |
|
15 | 55 | void testCtor_data(); |
|
16 | 56 | void testCtor(); |
@@ -32,192 +72,167 private slots: | |||
|
32 | 72 | void testSort(); |
|
33 | 73 | }; |
|
34 | 74 | |
|
35 | void TestTwoDimArrayData::testDataByComponentIndex_data() | |
|
36 | { | |
|
37 | // Test structure | |
|
38 | QTest::addColumn<DataContainer>("inputData"); // array data's input | |
|
39 | QTest::addColumn<int>("componentIndex"); // component index to test | |
|
40 | QTest::addColumn<QVector<double> >("expectedData"); // expected data | |
|
41 | ||
|
42 | // Test cases | |
|
43 | auto inputData | |
|
44 | = DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; | |
|
45 | ||
|
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.}; | |
|
48 | QTest::newRow("validIndex3") << inputData << 2 << QVector<double>{11., 12., 13., 14., 15.}; | |
|
49 | QTest::newRow("invalidIndex1") << inputData << -1 << QVector<double>{}; | |
|
50 | QTest::newRow("invalidIndex2") << inputData << 3 << QVector<double>{}; | |
|
51 | } | |
|
52 | ||
|
53 | void TestTwoDimArrayData::testDataByComponentIndex() | |
|
54 | { | |
|
55 | QFETCH(DataContainer, inputData); | |
|
56 | QFETCH(int, componentIndex); | |
|
57 | QFETCH(QVector<double>, expectedData); | |
|
58 | ||
|
59 | ArrayData<2> arrayData{inputData}; | |
|
60 | QVERIFY(arrayData.data(componentIndex) == expectedData); | |
|
61 | } | |
|
62 | ||
|
63 | 75 | void TestTwoDimArrayData::testCtor_data() |
|
64 | 76 | { |
|
65 | 77 | // Test structure |
|
66 |
QTest::addColumn<Data |
|
|
67 |
QTest::addColumn<bool>("success"); |
|
|
68 |
QTest::addColumn< |
|
|
78 | QTest::addColumn<InputData>("inputData"); // array data's input | |
|
79 | QTest::addColumn<bool>("success"); // array data has been successfully constructed | |
|
80 | QTest::addColumn<Container>("expectedData"); // expected array data (when success) | |
|
69 | 81 | |
|
70 | 82 | // Test cases |
|
71 | QTest::newRow("validInput") | |
|
72 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}} | |
|
73 | << true | |
|
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") | |
|
76 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8.}, {11., 12.}} << true | |
|
77 | << DataContainer{{}, {}, {}}; | |
|
78 | QTest::newRow("invalidInput (less than tow components") << DataContainer{{1., 2., 3., 4., 5.}} | |
|
79 | << false << DataContainer{{}, {}, {}}; | |
|
83 | QTest::newRow("validInput") << flatten(Container{{1., 2., 3., 4., 5.}, | |
|
84 | {6., 7., 8., 9., 10.}, | |
|
85 | {11., 12., 13., 14., 15.}}) | |
|
86 | << true << Container{{1., 2., 3., 4., 5.}, | |
|
87 | {6., 7., 8., 9., 10.}, | |
|
88 | {11., 12., 13., 14., 15.}}; | |
|
89 | QTest::newRow("invalidInput (invalid data size") | |
|
90 | << InputData{{1., 2., 3., 4., 5., 6., 7.}, 3} << false << Container{{}, {}, {}}; | |
|
91 | QTest::newRow("invalidInput (less than two components") | |
|
92 | << flatten(Container{{1., 2., 3., 4., 5.}}) << false << Container{{}, {}, {}}; | |
|
80 | 93 | } |
|
81 | 94 | |
|
82 | 95 | void TestTwoDimArrayData::testCtor() |
|
83 | 96 | { |
|
84 |
QFETCH(Data |
|
|
97 | QFETCH(InputData, inputData); | |
|
85 | 98 | QFETCH(bool, success); |
|
86 | 99 | |
|
87 | 100 | if (success) { |
|
88 |
QFETCH( |
|
|
89 | ||
|
90 | ArrayData<2> arrayData{inputData}; | |
|
101 | QFETCH(Container, expectedData); | |
|
91 | 102 | |
|
92 | for (auto i = 0; i < expectedData.size(); ++i) { | |
|
93 |
|
|
|
94 | } | |
|
103 | ArrayData<2> arrayData{inputData.first, inputData.second}; | |
|
104 | verifyArrayData(arrayData, expectedData); | |
|
95 | 105 | } |
|
96 | 106 | else { |
|
97 |
QVERIFY_EXCEPTION_THROWN(ArrayData<2> |
|
|
107 | QVERIFY_EXCEPTION_THROWN(ArrayData<2>(inputData.first, inputData.second), | |
|
108 | std::invalid_argument); | |
|
98 | 109 | } |
|
99 | 110 | } |
|
100 | 111 | |
|
101 | 112 | void TestTwoDimArrayData::testAdd_data() |
|
102 | 113 | { |
|
103 | 114 | // Test structure |
|
104 |
QTest::addColumn<Data |
|
|
105 |
QTest::addColumn<Data |
|
|
106 |
QTest::addColumn<bool>("prepend"); |
|
|
107 |
QTest::addColumn< |
|
|
115 | QTest::addColumn<InputData>("inputData"); // array's data input | |
|
116 | QTest::addColumn<InputData>("otherData"); // array data's input to merge with | |
|
117 | QTest::addColumn<bool>("prepend"); // prepend or append merge | |
|
118 | QTest::addColumn<Container>("expectedData"); // expected data after merge | |
|
108 | 119 | |
|
109 | 120 | // Test cases |
|
110 | auto inputData | |
|
111 |
|
|
|
121 | auto inputData = flatten( | |
|
122 | Container{{1., 2., 3., 4., 5.}, {11., 12., 13., 14., 15.}, {21., 22., 23., 24., 25.}}); | |
|
112 | 123 | |
|
113 |
auto vectorContainer = |
|
|
114 |
auto tensorContainer = |
|
|
115 |
{ |
|
|
124 | auto vectorContainer = flatten(Container{{6., 7., 8.}, {16., 17., 18.}, {26., 27., 28}}); | |
|
125 | auto tensorContainer = flatten(Container{{6., 7., 8.}, | |
|
126 | {16., 17., 18.}, | |
|
127 | {26., 27., 28}, | |
|
128 | {36., 37., 38.}, | |
|
129 | {46., 47., 48.}, | |
|
130 | {56., 57., 58}}); | |
|
116 | 131 | |
|
117 | 132 | QTest::newRow("appendMerge") << inputData << vectorContainer << false |
|
118 |
<< |
|
|
119 |
|
|
|
120 |
|
|
|
133 | << Container{{1., 2., 3., 4., 5., 6., 7., 8.}, | |
|
134 | {11., 12., 13., 14., 15., 16., 17., 18.}, | |
|
135 | {21., 22., 23., 24., 25., 26., 27., 28}}; | |
|
121 | 136 | QTest::newRow("prependMerge") << inputData << vectorContainer << true |
|
122 |
<< |
|
|
123 |
|
|
|
124 |
|
|
|
125 |
QTest::newRow("invalidMerge") << inputData << tensorContainer << false |
|
|
137 | << Container{{6., 7., 8., 1., 2., 3., 4., 5.}, | |
|
138 | {16., 17., 18., 11., 12., 13., 14., 15.}, | |
|
139 | {26., 27., 28, 21., 22., 23., 24., 25.}}; | |
|
140 | QTest::newRow("invalidMerge") << inputData << tensorContainer << false | |
|
141 | << Container{{1., 2., 3., 4., 5.}, | |
|
142 | {11., 12., 13., 14., 15.}, | |
|
143 | {21., 22., 23., 24., 25.}}; | |
|
126 | 144 | } |
|
127 | 145 | |
|
128 | 146 | void TestTwoDimArrayData::testAdd() |
|
129 | 147 | { |
|
130 |
QFETCH(Data |
|
|
131 |
QFETCH(Data |
|
|
148 | QFETCH(InputData, inputData); | |
|
149 | QFETCH(InputData, otherData); | |
|
132 | 150 | QFETCH(bool, prepend); |
|
133 |
QFETCH( |
|
|
151 | QFETCH(Container, expectedData); | |
|
134 | 152 | |
|
135 | ArrayData<2> arrayData{inputData}; | |
|
136 | ArrayData<2> other{otherData}; | |
|
153 | ArrayData<2> arrayData{inputData.first, inputData.second}; | |
|
154 | ArrayData<2> other{otherData.first, otherData.second}; | |
|
137 | 155 | |
|
138 | 156 | arrayData.add(other, prepend); |
|
139 | 157 | |
|
140 | for (auto i = 0; i < expectedData.size(); ++i) { | |
|
141 | QVERIFY(arrayData.data(i) == expectedData.at(i)); | |
|
142 | } | |
|
158 | verifyArrayData(arrayData, expectedData); | |
|
143 | 159 | } |
|
144 | 160 | |
|
145 | 161 | void TestTwoDimArrayData::testClear_data() |
|
146 | 162 | { |
|
147 | 163 | // Test structure |
|
148 |
QTest::addColumn<Data |
|
|
164 | QTest::addColumn<InputData>("inputData"); // array data's input | |
|
149 | 165 | |
|
150 | 166 | // Test cases |
|
151 |
QTest::newRow("data1") << |
|
|
152 | {1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}; | |
|
167 | QTest::newRow("data1") << flatten( | |
|
168 | Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}); | |
|
153 | 169 | } |
|
154 | 170 | |
|
155 | 171 | void TestTwoDimArrayData::testClear() |
|
156 | 172 | { |
|
157 |
QFETCH(Data |
|
|
173 | QFETCH(InputData, inputData); | |
|
158 | 174 | |
|
159 | ArrayData<2> arrayData{inputData}; | |
|
175 | ArrayData<2> arrayData{inputData.first, inputData.second}; | |
|
160 | 176 | arrayData.clear(); |
|
161 | 177 | |
|
162 | for (auto i = 0; i < inputData.size(); ++i) { | |
|
163 | QVERIFY(arrayData.data(i) == QVector<double>{}); | |
|
164 | } | |
|
178 | auto emptyData = Container(inputData.second, QVector<double>{}); | |
|
179 | verifyArrayData(arrayData, emptyData); | |
|
165 | 180 | } |
|
166 | 181 | |
|
167 | 182 | void TestTwoDimArrayData::testSize_data() |
|
168 | 183 | { |
|
169 | 184 | // Test structure |
|
170 |
QTest::addColumn< |
|
|
171 |
QTest::addColumn<int>("expectedSize"); |
|
|
185 | QTest::addColumn<InputData>("inputData"); // array data's input | |
|
186 | QTest::addColumn<int>("expectedSize"); // expected array data size | |
|
172 | 187 | |
|
173 | 188 | // Test cases |
|
174 |
QTest::newRow("data1") << |
|
|
175 |
QTest::newRow("data2") << |
|
|
176 | {6., 7., 8., 9., 10.}, | |
|
177 | {11., 12., 13., 14., 15.}} | |
|
189 | QTest::newRow("data1") << flatten(Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}}) << 5; | |
|
190 | QTest::newRow("data2") << flatten(Container{{1., 2., 3., 4., 5.}, | |
|
191 | {6., 7., 8., 9., 10.}, | |
|
192 | {11., 12., 13., 14., 15.}}) | |
|
178 | 193 | << 5; |
|
179 | 194 | } |
|
180 | 195 | |
|
181 | 196 | void TestTwoDimArrayData::testSize() |
|
182 | 197 | { |
|
183 |
QFETCH(Data |
|
|
198 | QFETCH(InputData, inputData); | |
|
184 | 199 | QFETCH(int, expectedSize); |
|
185 | 200 | |
|
186 | ArrayData<2> arrayData{inputData}; | |
|
201 | ArrayData<2> arrayData{inputData.first, inputData.second}; | |
|
187 | 202 | QVERIFY(arrayData.size() == expectedSize); |
|
188 | 203 | } |
|
189 | 204 | |
|
190 | 205 | void TestTwoDimArrayData::testSort_data() |
|
191 | 206 | { |
|
192 | 207 | // Test structure |
|
193 |
QTest::addColumn<Data |
|
|
208 | QTest::addColumn<InputData>("inputData"); // array data's input | |
|
194 | 209 | QTest::addColumn<std::vector<int> >("sortPermutation"); // permutation used to sort data |
|
195 |
QTest::addColumn< |
|
|
210 | QTest::addColumn<Container>("expectedData"); // expected data after sorting | |
|
196 | 211 | |
|
197 | 212 | // Test cases |
|
198 | 213 | QTest::newRow("data1") |
|
199 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}} | |
|
214 | << flatten( | |
|
215 | Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}) | |
|
200 | 216 | << std::vector<int>{0, 2, 3, 1, 4} |
|
201 |
<< |
|
|
217 | << Container{{1., 3., 4., 2., 5.}, {6., 8., 9., 7., 10.}, {11., 13., 14., 12., 15.}}; | |
|
202 | 218 | QTest::newRow("data2") |
|
203 | << DataContainer{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}} | |
|
219 | << flatten( | |
|
220 | Container{{1., 2., 3., 4., 5.}, {6., 7., 8., 9., 10.}, {11., 12., 13., 14., 15.}}) | |
|
204 | 221 | << std::vector<int>{2, 4, 3, 0, 1} |
|
205 |
<< |
|
|
222 | << Container{{3., 5., 4., 1., 2.}, {8., 10., 9., 6., 7.}, {13., 15., 14., 11., 12.}}; | |
|
206 | 223 | } |
|
207 | 224 | |
|
208 | 225 | void TestTwoDimArrayData::testSort() |
|
209 | 226 | { |
|
210 |
QFETCH(Data |
|
|
227 | QFETCH(InputData, inputData); | |
|
211 | 228 | QFETCH(std::vector<int>, sortPermutation); |
|
212 |
QFETCH( |
|
|
229 | QFETCH(Container, expectedData); | |
|
213 | 230 | |
|
214 | ArrayData<2> arrayData{inputData}; | |
|
231 | ArrayData<2> arrayData{inputData.first, inputData.second}; | |
|
215 | 232 | auto sortedArrayData = arrayData.sort(sortPermutation); |
|
216 | 233 | QVERIFY(sortedArrayData != nullptr); |
|
217 | 234 | |
|
218 | for (auto i = 0; i < expectedData.size(); ++i) { | |
|
219 | QVERIFY(sortedArrayData->data(i) == expectedData.at(i)); | |
|
220 | } | |
|
235 | verifyArrayData(*sortedArrayData, expectedData); | |
|
221 | 236 | } |
|
222 | 237 | |
|
223 | 238 | QTEST_MAIN(TestTwoDimArrayData) |
@@ -17,51 +17,6 QDateTime dateTime(int year, int month, int day, int hours, int minutes, int sec | |||
|
17 | 17 | return QDateTime{{year, month, day}, {hours, minutes, seconds}, Qt::UTC}; |
|
18 | 18 | } |
|
19 | 19 | |
|
20 | /// Compares two vectors that can potentially contain NaN values | |
|
21 | bool compareVectors(const QVector<double> &v1, const QVector<double> &v2) | |
|
22 | { | |
|
23 | if (v1.size() != v2.size()) { | |
|
24 | return false; | |
|
25 | } | |
|
26 | ||
|
27 | auto result = true; | |
|
28 | auto v2It = v2.cbegin(); | |
|
29 | for (auto v1It = v1.cbegin(), v1End = v1.cend(); v1It != v1End && result; ++v1It, ++v2It) { | |
|
30 | auto v1Value = *v1It; | |
|
31 | auto v2Value = *v2It; | |
|
32 | ||
|
33 | // If v1 is NaN, v2 has to be NaN too | |
|
34 | result = std::isnan(v1Value) ? std::isnan(v2Value) : (v1Value == v2Value); | |
|
35 | } | |
|
36 | ||
|
37 | return result; | |
|
38 | } | |
|
39 | ||
|
40 | bool compareVectors(const QVector<QVector<double> > &v1, const QVector<QVector<double> > &v2) | |
|
41 | { | |
|
42 | if (v1.size() != v2.size()) { | |
|
43 | return false; | |
|
44 | } | |
|
45 | ||
|
46 | auto result = true; | |
|
47 | for (auto i = 0; i < v1.size() && result; ++i) { | |
|
48 | result &= compareVectors(v1.at(i), v2.at(i)); | |
|
49 | } | |
|
50 | ||
|
51 | return result; | |
|
52 | } | |
|
53 | ||
|
54 | QVector<QVector<double> > valuesData(const ArrayData<1> &arrayData) | |
|
55 | { | |
|
56 | return QVector<QVector<double> >{arrayData.data()}; | |
|
57 | } | |
|
58 | ||
|
59 | QVector<QVector<double> > valuesData(const ArrayData<2> &arrayData) | |
|
60 | { | |
|
61 | return arrayData.data(); | |
|
62 | } | |
|
63 | ||
|
64 | ||
|
65 | 20 | QString inputFilePath(const QString &inputFileName) |
|
66 | 21 | { |
|
67 | 22 | return QFileInfo{TESTS_RESOURCES_PATH, inputFileName}.absoluteFilePath(); |
@@ -106,10 +61,26 struct ExpectedResults { | |||
|
106 | 61 | QVERIFY(dataSeries->xAxisUnit() == m_XAxisUnit); |
|
107 | 62 | QVERIFY(dataSeries->valuesUnit() == m_ValuesUnit); |
|
108 | 63 | |
|
109 | // Checks values : as the vectors can potentially contain NaN values, we must use a | |
|
110 | // custom vector comparison method | |
|
111 | QVERIFY(compareVectors(dataSeries->xAxisData()->data(), m_XAxisData)); | |
|
112 | QVERIFY(compareVectors(valuesData(*dataSeries->valuesData()), m_ValuesData)); | |
|
64 | auto verifyRange = [dataSeries](const auto &expectedData, const auto &equalFun) { | |
|
65 | QVERIFY(std::equal(dataSeries->cbegin(), dataSeries->cend(), expectedData.cbegin(), | |
|
66 | expectedData.cend(), | |
|
67 | [&equalFun](const auto &dataSeriesIt, const auto &expectedX) { | |
|
68 | return equalFun(dataSeriesIt, expectedX); | |
|
69 | })); | |
|
70 | }; | |
|
71 | ||
|
72 | // Checks x-axis data | |
|
73 | verifyRange(m_XAxisData, [](const auto &seriesIt, const auto &value) { | |
|
74 | return seriesIt.x() == value; | |
|
75 | }); | |
|
76 | ||
|
77 | // Checks values data of each component | |
|
78 | for (auto i = 0; i < m_ValuesData.size(); ++i) { | |
|
79 | verifyRange(m_ValuesData.at(i), [i](const auto &seriesIt, const auto &value) { | |
|
80 | auto itValue = seriesIt.value(i); | |
|
81 | return (std::isnan(itValue) && std::isnan(value)) || seriesIt.value(i) == value; | |
|
82 | }); | |
|
83 | } | |
|
113 | 84 | } |
|
114 | 85 | else { |
|
115 | 86 | QVERIFY(results == nullptr); |
General Comments 0
You need to be logged in to leave comments.
Login now