fixing a bug and adding a test for it

This commit is contained in:
Hans Dembinski
2016-09-14 17:34:07 +02:00
parent 4d4a5f93c3
commit 75889f405d
2 changed files with 3 additions and 4 deletions

View File

@@ -122,10 +122,7 @@ public:
inline int index(double x) const
{
const double z = (x - min_) / delta_;
const int i = static_cast<int>(z);
if (i > bins())
return bins();
return z >= 0.0 ? i : -1;
return z < 0.0 ? -1 : (z > bins() ? bins() : static_cast<int>(z));
}
double operator[](int idx) const

View File

@@ -32,6 +32,8 @@ BOOST_AUTO_TEST_CASE(regular_axis_operators) {
BOOST_CHECK_EQUAL(a.index(0.99), 2);
BOOST_CHECK_EQUAL(a.index(1.0), 3);
BOOST_CHECK_EQUAL(a.index(10.), 3);
BOOST_CHECK_EQUAL(a.index(std::numeric_limits<double>::infinity()), 3);
BOOST_CHECK_EQUAL(a.index(-std::numeric_limits<double>::infinity()), -1);
}
BOOST_AUTO_TEST_CASE(polar_axis_operators) {