##// END OF EJS Templates
Fixes subData() method and adds unit tests
Alexandre Leroux -
r550:70ca5d366d01
parent child
Show More
@@ -208,11 +208,11 public:
208 208
209 209 auto lowerIt
210 210 = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) {
211 return itValue.x() == value;
211 return itValue.x() < value;
212 212 });
213 213 auto upperIt
214 214 = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) {
215 return itValue.x() == value;
215 return value < itValue.x();
216 216 });
217 217
218 218 return std::make_pair(lowerIt, upperIt);
@@ -22,6 +22,13 private slots:
22 22
23 23 /// Tests merge of two data series
24 24 void testMerge();
25
26 /// Input test data
27 /// @sa testSubdata()
28 void testSubdata_data();
29
30 /// Tests get subdata of two data series
31 void testSubdata();
25 32 };
26 33
27 34 void TestDataSeries::testCtor_data()
@@ -160,5 +167,66 void TestDataSeries::testMerge()
160 167 seriesValuesData.cbegin()));
161 168 }
162 169
170 void TestDataSeries::testSubdata_data()
171 {
172 // ////////////// //
173 // Test structure //
174 // ////////////// //
175
176 // Data series to get subdata
177 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
178
179 // Min/max values
180 QTest::addColumn<double>("min");
181 QTest::addColumn<double>("max");
182
183 // Expected values after subdata
184 QTest::addColumn<QVector<double> >("expectedXAxisData");
185 QTest::addColumn<QVector<double> >("expectedValuesData");
186
187 // ////////// //
188 // Test cases //
189 // ////////// //
190
191 QTest::newRow("subData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
192 << -1. << 3.2 << QVector<double>{1., 2., 3.}
193 << QVector<double>{100., 200., 300.};
194 QTest::newRow("subData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
195 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
196 << QVector<double>{100., 200., 300., 400.};
197 QTest::newRow("subData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
198 << 1. << 3.9 << QVector<double>{1., 2., 3.}
199 << QVector<double>{100., 200., 300.};
200 QTest::newRow("subData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
201 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
202 QTest::newRow("subData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
203 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
204 QTest::newRow("subData6") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
205 << 2.1 << 6. << QVector<double>{3., 4., 5.}
206 << QVector<double>{300., 400., 500.};
207 QTest::newRow("subData7") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
208 << 6. << 9. << QVector<double>{} << QVector<double>{};
209 QTest::newRow("subData8") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
210 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
211 }
212
213 void TestDataSeries::testSubdata()
214 {
215 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
216 QFETCH(double, min);
217 QFETCH(double, max);
218
219 QFETCH(QVector<double>, expectedXAxisData);
220 QFETCH(QVector<double>, expectedValuesData);
221
222 auto bounds = dataSeries->subData(min, max);
223 QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(),
224 expectedXAxisData.cend(),
225 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
226 QVERIFY(std::equal(
227 bounds.first, bounds.second, expectedValuesData.cbegin(), expectedValuesData.cend(),
228 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
229 }
230
163 231 QTEST_MAIN(TestDataSeries)
164 232 #include "TestDataSeries.moc"
General Comments 0
You need to be logged in to leave comments. Login now