##// END OF EJS Templates
Shows min x-axis data in Variable widget (1)...
Alexandre Leroux -
r561:72b3a7366e6c
parent child
Show More
@@ -191,6 +191,14 public:
191 191 std::make_unique<dataseries_detail::IteratorValue<Dim> >(*this, false)}};
192 192 }
193 193
194 /// @sa IDataSeries::minData()
195 DataSeriesIterator minData(double minXAxisData) const override
196 {
197 return std::lower_bound(
198 cbegin(), cend(), minXAxisData,
199 [](const auto &itValue, const auto &value) { return itValue.x() < value; });
200 }
201
194 202 std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min, double max) const override
195 203 {
196 204 if (min > max) {
@@ -70,6 +70,10 public:
70 70 virtual DataSeriesIterator cbegin() const = 0;
71 71 virtual DataSeriesIterator cend() const = 0;
72 72
73 /// @return the iterator to the first entry of the data series whose x-axis data is greater than
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;
76
73 77 virtual std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min,
74 78 double max) const = 0;
75 79
@@ -24,6 +24,12 private slots:
24 24 void testMerge();
25 25
26 26 /// Input test data
27 /// @sa testMinData()
28 void testMinData_data();
29
30 /// Tests get min data of a data series
31 void testMinData();
32
27 33 /// @sa testSubdata()
28 34 void testSubdata_data();
29 35
@@ -167,6 +173,59 void TestDataSeries::testMerge()
167 173 seriesValuesData.cbegin()));
168 174 }
169 175
176 void TestDataSeries::testMinData_data()
177 {
178 // ////////////// //
179 // Test structure //
180 // ////////////// //
181
182 // Data series to get min data
183 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
184
185 // Min data
186 QTest::addColumn<double>("min");
187
188 // Expected results
189 QTest::addColumn<bool>(
190 "expectedOK"); // if true, expects to have a result (i.e. the iterator != end iterator)
191 QTest::addColumn<double>(
192 "expectedMin"); // Expected value when method doesn't return end iterator
193
194 // ////////// //
195 // Test cases //
196 // ////////// //
197
198 QTest::newRow("minData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
199 << 0. << true << 1.;
200 QTest::newRow("minData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
201 << 1. << true << 1.;
202 QTest::newRow("minData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
203 << 1.1 << true << 2.;
204 QTest::newRow("minData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
205 << 5. << true << 5.;
206 QTest::newRow("minData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
207 << 5.1 << false << std::numeric_limits<double>::quiet_NaN();
208 QTest::newRow("minData6") << createSeries({}, {}) << 1.1 << false
209 << std::numeric_limits<double>::quiet_NaN();
210 }
211
212 void TestDataSeries::testMinData()
213 {
214 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
215 QFETCH(double, min);
216
217 QFETCH(bool, expectedOK);
218 QFETCH(double, expectedMin);
219
220 auto it = dataSeries->minData(min);
221
222 QCOMPARE(expectedOK, it != dataSeries->cend());
223
224 // If the method doesn't return a end iterator, checks with expected value
225 if (expectedOK) {
226 QCOMPARE(expectedMin, it->x());
227 }
228 }
170 229 void TestDataSeries::testSubdata_data()
171 230 {
172 231 // ////////////// //
General Comments 0
You need to be logged in to leave comments. Login now