##// END OF EJS Templates
Shows min/max x-axis data in Variable widget (2)...
Alexandre Leroux -
r562:c613c4935e08
parent child
Show More
@@ -199,6 +199,17 public:
199 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
199 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
200 }
200 }
201
201
202 /// @sa IDataSeries::maxData()
203 DataSeriesIterator maxData(double maxXAxisData) const override
204 {
205 // Gets the first element that greater than max value
206 auto it = std::upper_bound(
207 cbegin(), cend(), maxXAxisData,
208 [](const auto &value, const auto &itValue) { return value < itValue.x(); });
209
210 return it == cbegin() ? cend() : --it;
211 }
212
202 std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min, double max) const override
213 std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min, double max) const override
203 {
214 {
204 if (min > max) {
215 if (min > max) {
@@ -74,6 +74,10 public:
74 /// or equal to the value passed in parameter, or the end iterator if there is no matching value
74 /// or equal to the value passed in parameter, or the end iterator if there is no matching value
75 virtual DataSeriesIterator minData(double minXAxisData) const = 0;
75 virtual DataSeriesIterator minData(double minXAxisData) const = 0;
76
76
77 /// @return the iterator to the last entry of the data series whose x-axis data is less than or
78 /// equal to the value passed in parameter, or the end iterator if there is no matching value
79 virtual DataSeriesIterator maxData(double maxXAxisData) const = 0;
80
77 virtual std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min,
81 virtual std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min,
78 double max) const = 0;
82 double max) const = 0;
79
83
@@ -30,6 +30,14 private slots:
30 /// Tests get min data of a data series
30 /// Tests get min data of a data series
31 void testMinData();
31 void testMinData();
32
32
33 /// Input test data
34 /// @sa testMaxData()
35 void testMaxData_data();
36
37 /// Tests get max data of a data series
38 void testMaxData();
39
40 /// Input test data
33 /// @sa testSubdata()
41 /// @sa testSubdata()
34 void testSubdata_data();
42 void testSubdata_data();
35
43
@@ -226,6 +234,61 void TestDataSeries::testMinData()
226 QCOMPARE(expectedMin, it->x());
234 QCOMPARE(expectedMin, it->x());
227 }
235 }
228 }
236 }
237
238 void TestDataSeries::testMaxData_data()
239 {
240 // ////////////// //
241 // Test structure //
242 // ////////////// //
243
244 // Data series to get max data
245 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
246
247 // Max data
248 QTest::addColumn<double>("max");
249
250 // Expected results
251 QTest::addColumn<bool>(
252 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
253 QTest::addColumn<double>(
254 "expectedMax"); // Expected value when method doesn't return end iterator
255
256 // ////////// //
257 // Test cases //
258 // ////////// //
259
260 QTest::newRow("maxData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
261 << 6. << true << 5.;
262 QTest::newRow("maxData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
263 << 5. << true << 5.;
264 QTest::newRow("maxData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
265 << 4.9 << true << 4.;
266 QTest::newRow("maxData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
267 << 1.1 << true << 1.;
268 QTest::newRow("maxData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
269 << 1. << true << 1.;
270 QTest::newRow("maxData6") << createSeries({}, {}) << 1.1 << false
271 << std::numeric_limits<double>::quiet_NaN();
272 }
273
274 void TestDataSeries::testMaxData()
275 {
276 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
277 QFETCH(double, max);
278
279 QFETCH(bool, expectedOK);
280 QFETCH(double, expectedMax);
281
282 auto it = dataSeries->maxData(max);
283
284 QCOMPARE(expectedOK, it != dataSeries->cend());
285
286 // If the method doesn't return a end iterator, checks with expected value
287 if (expectedOK) {
288 QCOMPARE(expectedMax, it->x());
289 }
290 }
291
229 void TestDataSeries::testSubdata_data()
292 void TestDataSeries::testSubdata_data()
230 {
293 {
231 // ////////////// //
294 // ////////////// //
General Comments 0
You need to be logged in to leave comments. Login now