mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
increase test coverage
This commit is contained in:
parent
def0a28413
commit
ddaa9c490f
@ -7,6 +7,7 @@
|
||||
#include <boost/serialization/access.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
@ -109,7 +110,8 @@ public:
|
||||
polar_axis& operator=(const polar_axis&);
|
||||
|
||||
inline int index(double x) const {
|
||||
const double z = (x - start_) / 6.283185307179586;
|
||||
using namespace boost::math::double_constants;
|
||||
const double z = (x - start_) / two_pi;
|
||||
const int i = int(floor(z * bins())) % bins();
|
||||
return i + (i < 0) * bins();
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/assign/std/vector.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
using namespace boost::assign;
|
||||
using namespace boost::histogram;
|
||||
@ -21,6 +24,18 @@ BOOST_AUTO_TEST_CASE(regular_axis_operators) {
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(polar_axis_operators) {
|
||||
using namespace boost::math::double_constants;
|
||||
polar_axis a(4);
|
||||
BOOST_CHECK_EQUAL(a[-1], a[a.bins() - 1] - two_pi);
|
||||
polar_axis b;
|
||||
BOOST_CHECK_NE(a, b);
|
||||
b = a;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
b = b;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(variable_axis_operators) {
|
||||
std::vector<double> x;
|
||||
x += -1, 0, 1;
|
||||
@ -34,3 +49,38 @@ BOOST_AUTO_TEST_CASE(variable_axis_operators) {
|
||||
b = b;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(category_axis_operators) {
|
||||
category_axis a("A;B;C");
|
||||
category_axis b;
|
||||
BOOST_CHECK_NE(a, b);
|
||||
b = a;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
b = b;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(integer_axis_operators) {
|
||||
integer_axis a(-1, 1);
|
||||
integer_axis b;
|
||||
BOOST_CHECK_NE(a, b);
|
||||
b = a;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
b = b;
|
||||
BOOST_CHECK_EQUAL(a, b);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(stream_operator) {
|
||||
std::vector<double> x;
|
||||
x += -1, 0, 1;
|
||||
std::vector<axis_type> axes;
|
||||
axes.push_back(regular_axis(2, -1, 1));
|
||||
axes.push_back(polar_axis(4));
|
||||
axes.push_back(variable_axis(x));
|
||||
axes.push_back(category_axis("A;B;C"));
|
||||
axes.push_back(integer_axis(-1, 1));
|
||||
std::ostringstream os;
|
||||
BOOST_FOREACH(const axis_type& a, axes)
|
||||
os << a;
|
||||
BOOST_CHECK(!os.str().empty());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user