@@ -1,362 +1,452 | |||||
1 | #include "Data/DataSeries.h" |
|
1 | #include "Data/DataSeries.h" | |
2 | #include "Data/ScalarSeries.h" |
|
2 | #include "Data/ScalarSeries.h" | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QtTest> |
|
5 | #include <QtTest> | |
6 |
|
6 | |||
7 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) |
|
7 | Q_DECLARE_METATYPE(std::shared_ptr<ScalarSeries>) | |
8 |
|
8 | |||
9 | class TestDataSeries : public QObject { |
|
9 | class TestDataSeries : public QObject { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 | private slots: |
|
11 | private slots: | |
12 | /// Input test data |
|
12 | /// Input test data | |
13 | /// @sa testCtor() |
|
13 | /// @sa testCtor() | |
14 | void testCtor_data(); |
|
14 | void testCtor_data(); | |
15 |
|
15 | |||
16 | /// Tests construction of a data series |
|
16 | /// Tests construction of a data series | |
17 | void testCtor(); |
|
17 | void testCtor(); | |
18 |
|
18 | |||
19 | /// Input test data |
|
19 | /// Input test data | |
20 | /// @sa testMerge() |
|
20 | /// @sa testMerge() | |
21 | void testMerge_data(); |
|
21 | void testMerge_data(); | |
22 |
|
22 | |||
23 | /// Tests merge of two data series |
|
23 | /// Tests merge of two data series | |
24 | void testMerge(); |
|
24 | void testMerge(); | |
25 |
|
25 | |||
26 | /// Input test data |
|
26 | /// Input test data | |
27 | /// @sa testMinXAxisData() |
|
27 | /// @sa testMinXAxisData() | |
28 | void testMinXAxisData_data(); |
|
28 | void testMinXAxisData_data(); | |
29 |
|
29 | |||
30 | /// Tests get min x-axis data of a data series |
|
30 | /// Tests get min x-axis data of a data series | |
31 | void testMinXAxisData(); |
|
31 | void testMinXAxisData(); | |
32 |
|
32 | |||
33 | /// Input test data |
|
33 | /// Input test data | |
34 | /// @sa testMaxXAxisData() |
|
34 | /// @sa testMaxXAxisData() | |
35 | void testMaxXAxisData_data(); |
|
35 | void testMaxXAxisData_data(); | |
36 |
|
36 | |||
37 | /// Tests get max x-axis data of a data series |
|
37 | /// Tests get max x-axis data of a data series | |
38 | void testMaxXAxisData(); |
|
38 | void testMaxXAxisData(); | |
39 |
|
39 | |||
40 | /// Input test data |
|
40 | /// Input test data | |
41 | /// @sa testXAxisRange() |
|
41 | /// @sa testXAxisRange() | |
42 | void testXAxisRange_data(); |
|
42 | void testXAxisRange_data(); | |
43 |
|
43 | |||
44 | /// Tests get x-axis range of a data series |
|
44 | /// Tests get x-axis range of a data series | |
45 | void testXAxisRange(); |
|
45 | void testXAxisRange(); | |
|
46 | ||||
|
47 | /// Input test data | |||
|
48 | /// @sa testValuesBounds() | |||
|
49 | void testValuesBounds_data(); | |||
|
50 | ||||
|
51 | /// Tests get values bounds of a data series | |||
|
52 | void testValuesBounds(); | |||
46 | }; |
|
53 | }; | |
47 |
|
54 | |||
48 | void TestDataSeries::testCtor_data() |
|
55 | void TestDataSeries::testCtor_data() | |
49 | { |
|
56 | { | |
50 | // ////////////// // |
|
57 | // ////////////// // | |
51 | // Test structure // |
|
58 | // Test structure // | |
52 | // ////////////// // |
|
59 | // ////////////// // | |
53 |
|
60 | |||
54 | // x-axis data |
|
61 | // x-axis data | |
55 | QTest::addColumn<QVector<double> >("xAxisData"); |
|
62 | QTest::addColumn<QVector<double> >("xAxisData"); | |
56 | // values data |
|
63 | // values data | |
57 | QTest::addColumn<QVector<double> >("valuesData"); |
|
64 | QTest::addColumn<QVector<double> >("valuesData"); | |
58 |
|
65 | |||
59 | // expected x-axis data |
|
66 | // expected x-axis data | |
60 | QTest::addColumn<QVector<double> >("expectedXAxisData"); |
|
67 | QTest::addColumn<QVector<double> >("expectedXAxisData"); | |
61 | // expected values data |
|
68 | // expected values data | |
62 | QTest::addColumn<QVector<double> >("expectedValuesData"); |
|
69 | QTest::addColumn<QVector<double> >("expectedValuesData"); | |
63 |
|
70 | |||
64 | // ////////// // |
|
71 | // ////////// // | |
65 | // Test cases // |
|
72 | // Test cases // | |
66 | // ////////// // |
|
73 | // ////////// // | |
67 |
|
74 | |||
68 | QTest::newRow("invalidData (different sizes of vectors)") |
|
75 | QTest::newRow("invalidData (different sizes of vectors)") | |
69 | << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.} |
|
76 | << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 200., 300.} | |
70 | << QVector<double>{} << QVector<double>{}; |
|
77 | << QVector<double>{} << QVector<double>{}; | |
71 |
|
78 | |||
72 | QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.} |
|
79 | QTest::newRow("sortedData") << QVector<double>{1., 2., 3., 4., 5.} | |
73 | << QVector<double>{100., 200., 300., 400., 500.} |
|
80 | << QVector<double>{100., 200., 300., 400., 500.} | |
74 | << QVector<double>{1., 2., 3., 4., 5.} |
|
81 | << QVector<double>{1., 2., 3., 4., 5.} | |
75 | << QVector<double>{100., 200., 300., 400., 500.}; |
|
82 | << QVector<double>{100., 200., 300., 400., 500.}; | |
76 |
|
83 | |||
77 | QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.} |
|
84 | QTest::newRow("unsortedData") << QVector<double>{5., 4., 3., 2., 1.} | |
78 | << QVector<double>{100., 200., 300., 400., 500.} |
|
85 | << QVector<double>{100., 200., 300., 400., 500.} | |
79 | << QVector<double>{1., 2., 3., 4., 5.} |
|
86 | << QVector<double>{1., 2., 3., 4., 5.} | |
80 | << QVector<double>{500., 400., 300., 200., 100.}; |
|
87 | << QVector<double>{500., 400., 300., 200., 100.}; | |
81 |
|
88 | |||
82 | QTest::newRow("unsortedData2") |
|
89 | QTest::newRow("unsortedData2") | |
83 | << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.} |
|
90 | << QVector<double>{1., 4., 3., 5., 2.} << QVector<double>{100., 200., 300., 400., 500.} | |
84 | << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.}; |
|
91 | << QVector<double>{1., 2., 3., 4., 5.} << QVector<double>{100., 500., 300., 200., 400.}; | |
85 | } |
|
92 | } | |
86 |
|
93 | |||
87 | void TestDataSeries::testCtor() |
|
94 | void TestDataSeries::testCtor() | |
88 | { |
|
95 | { | |
89 | // Creates series |
|
96 | // Creates series | |
90 | QFETCH(QVector<double>, xAxisData); |
|
97 | QFETCH(QVector<double>, xAxisData); | |
91 | QFETCH(QVector<double>, valuesData); |
|
98 | QFETCH(QVector<double>, valuesData); | |
92 |
|
99 | |||
93 | auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), |
|
100 | auto series = std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), | |
94 | Unit{}, Unit{}); |
|
101 | Unit{}, Unit{}); | |
95 |
|
102 | |||
96 | // Validates results : we check that the data series is sorted on its x-axis data |
|
103 | // Validates results : we check that the data series is sorted on its x-axis data | |
97 | QFETCH(QVector<double>, expectedXAxisData); |
|
104 | QFETCH(QVector<double>, expectedXAxisData); | |
98 | QFETCH(QVector<double>, expectedValuesData); |
|
105 | QFETCH(QVector<double>, expectedValuesData); | |
99 |
|
106 | |||
100 | auto seriesXAxisData = series->xAxisData()->data(); |
|
107 | auto seriesXAxisData = series->xAxisData()->data(); | |
101 | auto seriesValuesData = series->valuesData()->data(); |
|
108 | auto seriesValuesData = series->valuesData()->data(); | |
102 |
|
109 | |||
103 | QVERIFY( |
|
110 | QVERIFY( | |
104 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); |
|
111 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); | |
105 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), |
|
112 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), | |
106 | seriesValuesData.cbegin())); |
|
113 | seriesValuesData.cbegin())); | |
107 | } |
|
114 | } | |
108 |
|
115 | |||
109 | namespace { |
|
116 | namespace { | |
110 |
|
117 | |||
111 | std::shared_ptr<ScalarSeries> createSeries(QVector<double> xAxisData, QVector<double> valuesData) |
|
118 | std::shared_ptr<ScalarSeries> createSeries(QVector<double> xAxisData, QVector<double> valuesData) | |
112 | { |
|
119 | { | |
113 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, |
|
120 | return std::make_shared<ScalarSeries>(std::move(xAxisData), std::move(valuesData), Unit{}, | |
114 | Unit{}); |
|
121 | Unit{}); | |
115 | } |
|
122 | } | |
116 |
|
123 | |||
117 | } // namespace |
|
124 | } // namespace | |
118 |
|
125 | |||
119 | void TestDataSeries::testMerge_data() |
|
126 | void TestDataSeries::testMerge_data() | |
120 | { |
|
127 | { | |
121 | // ////////////// // |
|
128 | // ////////////// // | |
122 | // Test structure // |
|
129 | // Test structure // | |
123 | // ////////////// // |
|
130 | // ////////////// // | |
124 |
|
131 | |||
125 | // Data series to merge |
|
132 | // Data series to merge | |
126 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
133 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
127 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2"); |
|
134 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries2"); | |
128 |
|
135 | |||
129 | // Expected values in the first data series after merge |
|
136 | // Expected values in the first data series after merge | |
130 | QTest::addColumn<QVector<double> >("expectedXAxisData"); |
|
137 | QTest::addColumn<QVector<double> >("expectedXAxisData"); | |
131 | QTest::addColumn<QVector<double> >("expectedValuesData"); |
|
138 | QTest::addColumn<QVector<double> >("expectedValuesData"); | |
132 |
|
139 | |||
133 | // ////////// // |
|
140 | // ////////// // | |
134 | // Test cases // |
|
141 | // Test cases // | |
135 | // ////////// // |
|
142 | // ////////// // | |
136 |
|
143 | |||
137 | QTest::newRow("sortedMerge") |
|
144 | QTest::newRow("sortedMerge") | |
138 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
145 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
139 | << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) |
|
146 | << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) | |
140 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} |
|
147 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
141 | << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; |
|
148 | << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; | |
142 |
|
149 | |||
143 | QTest::newRow("unsortedMerge") |
|
150 | QTest::newRow("unsortedMerge") | |
144 | << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) |
|
151 | << createSeries({6., 7., 8., 9., 10.}, {600., 700., 800., 900., 1000.}) | |
145 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
152 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
146 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} |
|
153 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
147 | << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; |
|
154 | << QVector<double>{100., 200., 300., 400., 500., 600., 700., 800., 900., 1000.}; | |
148 |
|
155 | |||
149 | QTest::newRow("unsortedMerge2") |
|
156 | QTest::newRow("unsortedMerge2") | |
150 | << createSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.}) |
|
157 | << createSeries({1., 2., 8., 9., 10}, {100., 200., 300., 400., 500.}) | |
151 | << createSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.}) |
|
158 | << createSeries({3., 4., 5., 6., 7.}, {600., 700., 800., 900., 1000.}) | |
152 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} |
|
159 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
153 | << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.}; |
|
160 | << QVector<double>{100., 200., 600., 700., 800., 900., 1000., 300., 400., 500.}; | |
154 |
|
161 | |||
155 | QTest::newRow("unsortedMerge3") |
|
162 | QTest::newRow("unsortedMerge3") | |
156 | << createSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.}) |
|
163 | << createSeries({3., 5., 8., 7., 2}, {100., 200., 300., 400., 500.}) | |
157 | << createSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.}) |
|
164 | << createSeries({6., 4., 9., 10., 1.}, {600., 700., 800., 900., 1000.}) | |
158 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} |
|
165 | << QVector<double>{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} | |
159 | << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.}; |
|
166 | << QVector<double>{1000., 500., 100., 700., 200., 600., 400., 300., 800., 900.}; | |
160 | } |
|
167 | } | |
161 |
|
168 | |||
162 | void TestDataSeries::testMerge() |
|
169 | void TestDataSeries::testMerge() | |
163 | { |
|
170 | { | |
164 | // Merges series |
|
171 | // Merges series | |
165 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
172 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
166 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2); |
|
173 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries2); | |
167 |
|
174 | |||
168 | dataSeries->merge(dataSeries2.get()); |
|
175 | dataSeries->merge(dataSeries2.get()); | |
169 |
|
176 | |||
170 | // Validates results : we check that the merge is valid and the data series is sorted on its |
|
177 | // Validates results : we check that the merge is valid and the data series is sorted on its | |
171 | // x-axis data |
|
178 | // x-axis data | |
172 | QFETCH(QVector<double>, expectedXAxisData); |
|
179 | QFETCH(QVector<double>, expectedXAxisData); | |
173 | QFETCH(QVector<double>, expectedValuesData); |
|
180 | QFETCH(QVector<double>, expectedValuesData); | |
174 |
|
181 | |||
175 | auto seriesXAxisData = dataSeries->xAxisData()->data(); |
|
182 | auto seriesXAxisData = dataSeries->xAxisData()->data(); | |
176 | auto seriesValuesData = dataSeries->valuesData()->data(); |
|
183 | auto seriesValuesData = dataSeries->valuesData()->data(); | |
177 |
|
184 | |||
178 | QVERIFY( |
|
185 | QVERIFY( | |
179 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); |
|
186 | std::equal(expectedXAxisData.cbegin(), expectedXAxisData.cend(), seriesXAxisData.cbegin())); | |
180 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), |
|
187 | QVERIFY(std::equal(expectedValuesData.cbegin(), expectedValuesData.cend(), | |
181 | seriesValuesData.cbegin())); |
|
188 | seriesValuesData.cbegin())); | |
182 | } |
|
189 | } | |
183 |
|
190 | |||
184 | void TestDataSeries::testMinXAxisData_data() |
|
191 | void TestDataSeries::testMinXAxisData_data() | |
185 | { |
|
192 | { | |
186 | // ////////////// // |
|
193 | // ////////////// // | |
187 | // Test structure // |
|
194 | // Test structure // | |
188 | // ////////////// // |
|
195 | // ////////////// // | |
189 |
|
196 | |||
190 | // Data series to get min data |
|
197 | // Data series to get min data | |
191 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
198 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
192 |
|
199 | |||
193 | // Min data |
|
200 | // Min data | |
194 | QTest::addColumn<double>("min"); |
|
201 | QTest::addColumn<double>("min"); | |
195 |
|
202 | |||
196 | // Expected results |
|
203 | // Expected results | |
197 | QTest::addColumn<bool>( |
|
204 | QTest::addColumn<bool>( | |
198 | "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator) |
|
205 | "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator) | |
199 | QTest::addColumn<double>( |
|
206 | QTest::addColumn<double>( | |
200 | "expectedMin"); // Expected value when method doesn't return end iterator |
|
207 | "expectedMin"); // Expected value when method doesn't return end iterator | |
201 |
|
208 | |||
202 | // ////////// // |
|
209 | // ////////// // | |
203 | // Test cases // |
|
210 | // Test cases // | |
204 | // ////////// // |
|
211 | // ////////// // | |
205 |
|
212 | |||
206 | QTest::newRow("minData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
213 | QTest::newRow("minData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
207 | << 0. << true << 1.; |
|
214 | << 0. << true << 1.; | |
208 | QTest::newRow("minData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
215 | QTest::newRow("minData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
209 | << 1. << true << 1.; |
|
216 | << 1. << true << 1.; | |
210 | QTest::newRow("minData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
217 | QTest::newRow("minData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
211 | << 1.1 << true << 2.; |
|
218 | << 1.1 << true << 2.; | |
212 | QTest::newRow("minData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
219 | QTest::newRow("minData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
213 | << 5. << true << 5.; |
|
220 | << 5. << true << 5.; | |
214 | QTest::newRow("minData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
221 | QTest::newRow("minData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
215 | << 5.1 << false << std::numeric_limits<double>::quiet_NaN(); |
|
222 | << 5.1 << false << std::numeric_limits<double>::quiet_NaN(); | |
216 | QTest::newRow("minData6") << createSeries({}, {}) << 1.1 << false |
|
223 | QTest::newRow("minData6") << createSeries({}, {}) << 1.1 << false | |
217 | << std::numeric_limits<double>::quiet_NaN(); |
|
224 | << std::numeric_limits<double>::quiet_NaN(); | |
218 | } |
|
225 | } | |
219 |
|
226 | |||
220 | void TestDataSeries::testMinXAxisData() |
|
227 | void TestDataSeries::testMinXAxisData() | |
221 | { |
|
228 | { | |
222 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
229 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
223 | QFETCH(double, min); |
|
230 | QFETCH(double, min); | |
224 |
|
231 | |||
225 | QFETCH(bool, expectedOK); |
|
232 | QFETCH(bool, expectedOK); | |
226 | QFETCH(double, expectedMin); |
|
233 | QFETCH(double, expectedMin); | |
227 |
|
234 | |||
228 | auto it = dataSeries->minXAxisData(min); |
|
235 | auto it = dataSeries->minXAxisData(min); | |
229 |
|
236 | |||
230 | QCOMPARE(expectedOK, it != dataSeries->cend()); |
|
237 | QCOMPARE(expectedOK, it != dataSeries->cend()); | |
231 |
|
238 | |||
232 | // If the method doesn't return a end iterator, checks with expected value |
|
239 | // If the method doesn't return a end iterator, checks with expected value | |
233 | if (expectedOK) { |
|
240 | if (expectedOK) { | |
234 | QCOMPARE(expectedMin, it->x()); |
|
241 | QCOMPARE(expectedMin, it->x()); | |
235 | } |
|
242 | } | |
236 | } |
|
243 | } | |
237 |
|
244 | |||
238 | void TestDataSeries::testMaxXAxisData_data() |
|
245 | void TestDataSeries::testMaxXAxisData_data() | |
239 | { |
|
246 | { | |
240 | // ////////////// // |
|
247 | // ////////////// // | |
241 | // Test structure // |
|
248 | // Test structure // | |
242 | // ////////////// // |
|
249 | // ////////////// // | |
243 |
|
250 | |||
244 | // Data series to get max data |
|
251 | // Data series to get max data | |
245 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
252 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
246 |
|
253 | |||
247 | // Max data |
|
254 | // Max data | |
248 | QTest::addColumn<double>("max"); |
|
255 | QTest::addColumn<double>("max"); | |
249 |
|
256 | |||
250 | // Expected results |
|
257 | // Expected results | |
251 | QTest::addColumn<bool>( |
|
258 | QTest::addColumn<bool>( | |
252 | "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator) |
|
259 | "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator) | |
253 | QTest::addColumn<double>( |
|
260 | QTest::addColumn<double>( | |
254 | "expectedMax"); // Expected value when method doesn't return end iterator |
|
261 | "expectedMax"); // Expected value when method doesn't return end iterator | |
255 |
|
262 | |||
256 | // ////////// // |
|
263 | // ////////// // | |
257 | // Test cases // |
|
264 | // Test cases // | |
258 | // ////////// // |
|
265 | // ////////// // | |
259 |
|
266 | |||
260 | QTest::newRow("maxData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
267 | QTest::newRow("maxData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
261 | << 6. << true << 5.; |
|
268 | << 6. << true << 5.; | |
262 | QTest::newRow("maxData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
269 | QTest::newRow("maxData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
263 | << 5. << true << 5.; |
|
270 | << 5. << true << 5.; | |
264 | QTest::newRow("maxData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
271 | QTest::newRow("maxData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
265 | << 4.9 << true << 4.; |
|
272 | << 4.9 << true << 4.; | |
266 | QTest::newRow("maxData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
273 | QTest::newRow("maxData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
267 | << 1.1 << true << 1.; |
|
274 | << 1.1 << true << 1.; | |
268 | QTest::newRow("maxData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) |
|
275 | QTest::newRow("maxData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) | |
269 | << 1. << true << 1.; |
|
276 | << 1. << true << 1.; | |
270 | QTest::newRow("maxData6") << createSeries({}, {}) << 1.1 << false |
|
277 | QTest::newRow("maxData6") << createSeries({}, {}) << 1.1 << false | |
271 | << std::numeric_limits<double>::quiet_NaN(); |
|
278 | << std::numeric_limits<double>::quiet_NaN(); | |
272 | } |
|
279 | } | |
273 |
|
280 | |||
274 | void TestDataSeries::testMaxXAxisData() |
|
281 | void TestDataSeries::testMaxXAxisData() | |
275 | { |
|
282 | { | |
276 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
283 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
277 | QFETCH(double, max); |
|
284 | QFETCH(double, max); | |
278 |
|
285 | |||
279 | QFETCH(bool, expectedOK); |
|
286 | QFETCH(bool, expectedOK); | |
280 | QFETCH(double, expectedMax); |
|
287 | QFETCH(double, expectedMax); | |
281 |
|
288 | |||
282 | auto it = dataSeries->maxXAxisData(max); |
|
289 | auto it = dataSeries->maxXAxisData(max); | |
283 |
|
290 | |||
284 | QCOMPARE(expectedOK, it != dataSeries->cend()); |
|
291 | QCOMPARE(expectedOK, it != dataSeries->cend()); | |
285 |
|
292 | |||
286 | // If the method doesn't return a end iterator, checks with expected value |
|
293 | // If the method doesn't return a end iterator, checks with expected value | |
287 | if (expectedOK) { |
|
294 | if (expectedOK) { | |
288 | QCOMPARE(expectedMax, it->x()); |
|
295 | QCOMPARE(expectedMax, it->x()); | |
289 | } |
|
296 | } | |
290 | } |
|
297 | } | |
291 |
|
298 | |||
292 | void TestDataSeries::testXAxisRange_data() |
|
299 | void TestDataSeries::testXAxisRange_data() | |
293 | { |
|
300 | { | |
294 | // ////////////// // |
|
301 | // ////////////// // | |
295 | // Test structure // |
|
302 | // Test structure // | |
296 | // ////////////// // |
|
303 | // ////////////// // | |
297 |
|
304 | |||
298 | // Data series to get x-axis range |
|
305 | // Data series to get x-axis range | |
299 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
306 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
300 |
|
307 | |||
301 | // Min/max values |
|
308 | // Min/max values | |
302 | QTest::addColumn<double>("min"); |
|
309 | QTest::addColumn<double>("min"); | |
303 | QTest::addColumn<double>("max"); |
|
310 | QTest::addColumn<double>("max"); | |
304 |
|
311 | |||
305 | // Expected values |
|
312 | // Expected values | |
306 | QTest::addColumn<QVector<double> >("expectedXAxisData"); |
|
313 | QTest::addColumn<QVector<double> >("expectedXAxisData"); | |
307 | QTest::addColumn<QVector<double> >("expectedValuesData"); |
|
314 | QTest::addColumn<QVector<double> >("expectedValuesData"); | |
308 |
|
315 | |||
309 | // ////////// // |
|
316 | // ////////// // | |
310 | // Test cases // |
|
317 | // Test cases // | |
311 | // ////////// // |
|
318 | // ////////// // | |
312 |
|
319 | |||
313 | QTest::newRow("xAxisRange1") << createSeries({1., 2., 3., 4., 5.}, |
|
320 | QTest::newRow("xAxisRange1") << createSeries({1., 2., 3., 4., 5.}, | |
314 | {100., 200., 300., 400., 500.}) |
|
321 | {100., 200., 300., 400., 500.}) | |
315 | << -1. << 3.2 << QVector<double>{1., 2., 3.} |
|
322 | << -1. << 3.2 << QVector<double>{1., 2., 3.} | |
316 | << QVector<double>{100., 200., 300.}; |
|
323 | << QVector<double>{100., 200., 300.}; | |
317 | QTest::newRow("xAxisRange2") << createSeries({1., 2., 3., 4., 5.}, |
|
324 | QTest::newRow("xAxisRange2") << createSeries({1., 2., 3., 4., 5.}, | |
318 | {100., 200., 300., 400., 500.}) |
|
325 | {100., 200., 300., 400., 500.}) | |
319 | << 1. << 4. << QVector<double>{1., 2., 3., 4.} |
|
326 | << 1. << 4. << QVector<double>{1., 2., 3., 4.} | |
320 | << QVector<double>{100., 200., 300., 400.}; |
|
327 | << QVector<double>{100., 200., 300., 400.}; | |
321 | QTest::newRow("xAxisRange3") << createSeries({1., 2., 3., 4., 5.}, |
|
328 | QTest::newRow("xAxisRange3") << createSeries({1., 2., 3., 4., 5.}, | |
322 | {100., 200., 300., 400., 500.}) |
|
329 | {100., 200., 300., 400., 500.}) | |
323 | << 1. << 3.9 << QVector<double>{1., 2., 3.} |
|
330 | << 1. << 3.9 << QVector<double>{1., 2., 3.} | |
324 | << QVector<double>{100., 200., 300.}; |
|
331 | << QVector<double>{100., 200., 300.}; | |
325 | QTest::newRow("xAxisRange4") << createSeries({1., 2., 3., 4., 5.}, |
|
332 | QTest::newRow("xAxisRange4") << createSeries({1., 2., 3., 4., 5.}, | |
326 | {100., 200., 300., 400., 500.}) |
|
333 | {100., 200., 300., 400., 500.}) | |
327 | << 0. << 0.9 << QVector<double>{} << QVector<double>{}; |
|
334 | << 0. << 0.9 << QVector<double>{} << QVector<double>{}; | |
328 | QTest::newRow("xAxisRange5") << createSeries({1., 2., 3., 4., 5.}, |
|
335 | QTest::newRow("xAxisRange5") << createSeries({1., 2., 3., 4., 5.}, | |
329 | {100., 200., 300., 400., 500.}) |
|
336 | {100., 200., 300., 400., 500.}) | |
330 | << 0. << 1. << QVector<double>{1.} << QVector<double>{100.}; |
|
337 | << 0. << 1. << QVector<double>{1.} << QVector<double>{100.}; | |
331 | QTest::newRow("xAxisRange6") << createSeries({1., 2., 3., 4., 5.}, |
|
338 | QTest::newRow("xAxisRange6") << createSeries({1., 2., 3., 4., 5.}, | |
332 | {100., 200., 300., 400., 500.}) |
|
339 | {100., 200., 300., 400., 500.}) | |
333 | << 2.1 << 6. << QVector<double>{3., 4., 5.} |
|
340 | << 2.1 << 6. << QVector<double>{3., 4., 5.} | |
334 | << QVector<double>{300., 400., 500.}; |
|
341 | << QVector<double>{300., 400., 500.}; | |
335 | QTest::newRow("xAxisRange7") << createSeries({1., 2., 3., 4., 5.}, |
|
342 | QTest::newRow("xAxisRange7") << createSeries({1., 2., 3., 4., 5.}, | |
336 | {100., 200., 300., 400., 500.}) |
|
343 | {100., 200., 300., 400., 500.}) | |
337 | << 6. << 9. << QVector<double>{} << QVector<double>{}; |
|
344 | << 6. << 9. << QVector<double>{} << QVector<double>{}; | |
338 | QTest::newRow("xAxisRange8") << createSeries({1., 2., 3., 4., 5.}, |
|
345 | QTest::newRow("xAxisRange8") << createSeries({1., 2., 3., 4., 5.}, | |
339 | {100., 200., 300., 400., 500.}) |
|
346 | {100., 200., 300., 400., 500.}) | |
340 | << 5. << 9. << QVector<double>{5.} << QVector<double>{500.}; |
|
347 | << 5. << 9. << QVector<double>{5.} << QVector<double>{500.}; | |
341 | } |
|
348 | } | |
342 |
|
349 | |||
343 | void TestDataSeries::testXAxisRange() |
|
350 | void TestDataSeries::testXAxisRange() | |
344 | { |
|
351 | { | |
345 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
352 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
346 | QFETCH(double, min); |
|
353 | QFETCH(double, min); | |
347 | QFETCH(double, max); |
|
354 | QFETCH(double, max); | |
348 |
|
355 | |||
349 | QFETCH(QVector<double>, expectedXAxisData); |
|
356 | QFETCH(QVector<double>, expectedXAxisData); | |
350 | QFETCH(QVector<double>, expectedValuesData); |
|
357 | QFETCH(QVector<double>, expectedValuesData); | |
351 |
|
358 | |||
352 | auto bounds = dataSeries->xAxisRange(min, max); |
|
359 | auto bounds = dataSeries->xAxisRange(min, max); | |
353 | QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(), |
|
360 | QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(), | |
354 | expectedXAxisData.cend(), |
|
361 | expectedXAxisData.cend(), | |
355 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); |
|
362 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); | |
356 | QVERIFY(std::equal( |
|
363 | QVERIFY(std::equal( | |
357 | bounds.first, bounds.second, expectedValuesData.cbegin(), expectedValuesData.cend(), |
|
364 | bounds.first, bounds.second, expectedValuesData.cbegin(), expectedValuesData.cend(), | |
358 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); |
|
365 | [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; })); | |
359 | } |
|
366 | } | |
360 |
|
367 | |||
|
368 | void TestDataSeries::testValuesBounds_data() | |||
|
369 | { | |||
|
370 | // ////////////// // | |||
|
371 | // Test structure // | |||
|
372 | // ////////////// // | |||
|
373 | ||||
|
374 | // Data series to get values bounds | |||
|
375 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |||
|
376 | ||||
|
377 | // x-axis range | |||
|
378 | QTest::addColumn<double>("minXAxis"); | |||
|
379 | QTest::addColumn<double>("maxXAxis"); | |||
|
380 | ||||
|
381 | // Expected results | |||
|
382 | QTest::addColumn<bool>( | |||
|
383 | "expectedOK"); // Test is expected to be ok (i.e. method doesn't return end iterators) | |||
|
384 | QTest::addColumn<double>("expectedMinValue"); | |||
|
385 | QTest::addColumn<double>("expectedMaxValue"); | |||
|
386 | ||||
|
387 | // ////////// // | |||
|
388 | // Test cases // | |||
|
389 | // ////////// // | |||
|
390 | ||||
|
391 | QTest::newRow("valuesBounds1") | |||
|
392 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 6. << true | |||
|
393 | << 100. << 500.; | |||
|
394 | QTest::newRow("valuesBounds2") | |||
|
395 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 2. << 4. << true | |||
|
396 | << 200. << 400.; | |||
|
397 | QTest::newRow("valuesBounds3") | |||
|
398 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 0. << 0.5 << false | |||
|
399 | << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN(); | |||
|
400 | QTest::newRow("valuesBounds4") | |||
|
401 | << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) << 5.1 << 6. << false | |||
|
402 | << std::numeric_limits<double>::quiet_NaN() << std::numeric_limits<double>::quiet_NaN(); | |||
|
403 | QTest::newRow("valuesBounds5") | |||
|
404 | << createSeries({1.}, {100.}) << 0. << 2. << true << 100. << 100.; | |||
|
405 | QTest::newRow("valuesBounds6") | |||
|
406 | << createSeries({}, {}) << 0. << 2. << false << std::numeric_limits<double>::quiet_NaN() | |||
|
407 | << std::numeric_limits<double>::quiet_NaN(); | |||
|
408 | ||||
|
409 | // Tests with NaN values: NaN values are not included in min/max search | |||
|
410 | QTest::newRow("valuesBounds7") | |||
|
411 | << createSeries({1., 2., 3., 4., 5.}, | |||
|
412 | {std::numeric_limits<double>::quiet_NaN(), 200., 300., 400., | |||
|
413 | std::numeric_limits<double>::quiet_NaN()}) | |||
|
414 | << 0. << 6. << true << 200. << 400.; | |||
|
415 | QTest::newRow("valuesBounds8") | |||
|
416 | << createSeries( | |||
|
417 | {1., 2., 3., 4., 5.}, | |||
|
418 | {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), | |||
|
419 | std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), | |||
|
420 | std::numeric_limits<double>::quiet_NaN()}) | |||
|
421 | << 0. << 6. << true << std::numeric_limits<double>::quiet_NaN() | |||
|
422 | << std::numeric_limits<double>::quiet_NaN(); | |||
|
423 | } | |||
|
424 | ||||
|
425 | void TestDataSeries::testValuesBounds() | |||
|
426 | { | |||
|
427 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |||
|
428 | QFETCH(double, minXAxis); | |||
|
429 | QFETCH(double, maxXAxis); | |||
|
430 | ||||
|
431 | QFETCH(bool, expectedOK); | |||
|
432 | QFETCH(double, expectedMinValue); | |||
|
433 | QFETCH(double, expectedMaxValue); | |||
|
434 | ||||
|
435 | auto minMaxIts = dataSeries->valuesBounds(minXAxis, maxXAxis); | |||
|
436 | auto end = dataSeries->cend(); | |||
|
437 | ||||
|
438 | // Checks iterators with expected result | |||
|
439 | QCOMPARE(expectedOK, minMaxIts.first != end && minMaxIts.second != end); | |||
|
440 | ||||
|
441 | if (expectedOK) { | |||
|
442 | auto compare = [](const auto &v1, const auto &v2) { | |||
|
443 | return (std::isnan(v1) && std::isnan(v2)) || v1 == v2; | |||
|
444 | }; | |||
|
445 | ||||
|
446 | QVERIFY(compare(expectedMinValue, minMaxIts.first->minValue())); | |||
|
447 | QVERIFY(compare(expectedMaxValue, minMaxIts.second->maxValue())); | |||
|
448 | } | |||
|
449 | } | |||
|
450 | ||||
361 | QTEST_MAIN(TestDataSeries) |
|
451 | QTEST_MAIN(TestDataSeries) | |
362 | #include "TestDataSeries.moc" |
|
452 | #include "TestDataSeries.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now