From 8d255634386d11fe8fb36f79702cedc779ed0a61 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Wed, 4 Jul 2018 21:34:34 +0200 Subject: [PATCH] increase test coverage, simplify testing of python stuff, add support for tests which intentionally trigger an assert --- build/CMakeLists.txt | 12 +++- build/get_python_library.py | 8 ++- include/boost/histogram/detail/utility.hpp | 9 ++- include/boost/histogram/dynamic_histogram.hpp | 16 +++-- include/boost/histogram/static_histogram.hpp | 25 ++++---- src/python/axis.cpp | 4 +- src/python/histogram.cpp | 32 ++++++---- src/python/module.cpp | 7 ++- test/fail_histogram_add_dynamic_test.cpp | 8 +++ test/fail_histogram_add_static_test.cpp | 8 +++ test/fail_histogram_dynamic_bin_0_test.cpp | 7 +++ test/fail_histogram_dynamic_bin_1_test.cpp | 7 +++ test/fail_histogram_dynamic_bin_2_test.cpp | 9 +++ test/fail_histogram_dynamic_bin_3_test.cpp | 9 +++ test/fail_histogram_dynamic_bin_4_test.cpp | 9 +++ test/fail_histogram_static_bin_0_test.cpp | 7 +++ test/fail_histogram_static_bin_1_test.cpp | 9 +++ test/histogram_test.cpp | 7 --- test/pass_on_fail.py | 12 ++++ test/python_suite_test.py | 59 +++++++++++++------ test/weight_counter_test.cpp | 13 +--- 21 files changed, 190 insertions(+), 87 deletions(-) create mode 100644 test/fail_histogram_add_dynamic_test.cpp create mode 100644 test/fail_histogram_add_static_test.cpp create mode 100644 test/fail_histogram_dynamic_bin_0_test.cpp create mode 100644 test/fail_histogram_dynamic_bin_1_test.cpp create mode 100644 test/fail_histogram_dynamic_bin_2_test.cpp create mode 100644 test/fail_histogram_dynamic_bin_3_test.cpp create mode 100644 test/fail_histogram_dynamic_bin_4_test.cpp create mode 100644 test/fail_histogram_static_bin_0_test.cpp create mode 100644 test/fail_histogram_static_bin_1_test.cpp create mode 100644 test/pass_on_fail.py diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 0b2c2043..194058c9 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -147,8 +147,7 @@ if(BUILD_PYTHON) file(READ ${SRC} SRC_CONTENT) if (BUILD_NUMPY OR (NOT BUILD_NUMPY AND NOT SRC_CONTENT MATCHES "^import numpy|\nimport numpy")) - configure_file(${SRC} ${TESTNAME}.py) - add_test(${TESTNAME} ${PYTHON_EXECUTABLE} ${TESTNAME}.py) + add_test(${TESTNAME} ${PYTHON_EXECUTABLE} ${SRC}) endif() endif() endforeach() @@ -176,7 +175,14 @@ foreach(SRC IN ITEMS ${TEST_SOURCES}) else() target_link_libraries(${BASENAME} ${LIBRARIES}) endif() - add_test(${BASENAME} ${BASENAME}) + if (BASENAME MATCHES "fail") + if (DEFINED PYTHON_EXECUTABLE) + add_test(NAME ${BASENAME} COMMAND ${PYTHON_EXECUTABLE} + ../test/pass_on_fail.py ${BASENAME}) + endif() + else() + add_test(${BASENAME} ${BASENAME}) + endif() endif() endif() endforeach() diff --git a/build/get_python_library.py b/build/get_python_library.py index da331729..04c070c3 100644 --- a/build/get_python_library.py +++ b/build/get_python_library.py @@ -9,5 +9,9 @@ getvar = sysconfig.get_config_var libname = "python" + pyver -lib = glob.glob(pj(getvar('LIBPL'), "*" + libname + ".*"))[0] -sys.stdout.write(lib) \ No newline at end of file +for ext in ('so', 'dylib', 'dll'): + lib = glob.glob(pj(getvar('LIBPL'), "*" + libname + "." + ext)) + if lib: + assert len(lib) == 1 + sys.stdout.write(lib[0]) + break diff --git a/include/boost/histogram/detail/utility.hpp b/include/boost/histogram/detail/utility.hpp index a463f1f8..dfcc3933 100644 --- a/include/boost/histogram/detail/utility.hpp +++ b/include/boost/histogram/detail/utility.hpp @@ -70,11 +70,10 @@ struct index_mapper { s1 *= ni; ++bi; } - std::sort(dims.begin(), dims.end(), [](const dim &a, const dim &b) { - if (a.stride1 == b.stride1) - return 0; - return a.stride1 < b.stride1 ? -1 : 1; - }); + std::sort(dims.begin(), dims.end(), + [](const dim &a, const dim &b) { + return a.stride1 < b.stride1; + }); nfirst = s1; } diff --git a/include/boost/histogram/dynamic_histogram.hpp b/include/boost/histogram/dynamic_histogram.hpp index 7888f556..5534fa78 100644 --- a/include/boost/histogram/dynamic_histogram.hpp +++ b/include/boost/histogram/dynamic_histogram.hpp @@ -124,7 +124,7 @@ public: template histogram &operator+=(const histogram &rhs) { if (!detail::axes_equal(axes_, rhs.axes_)) - throw std::logic_error("axes of histograms differ"); + throw std::invalid_argument("axes of histograms differ"); storage_ += rhs.storage_; return *this; } @@ -190,7 +190,7 @@ public: std::size_t idx = 0, stride = 1; lin<0>(idx, stride, static_cast(ts)...); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } @@ -214,15 +214,13 @@ public: /// Return axis \a i any_axis_type &axis(unsigned i = 0) { - if (i >= dim()) - throw std::out_of_range("axis index out of range"); + BOOST_ASSERT_MSG(i < dim(), "axis index out of range"); return axes_[i]; } /// Return axis \a i (const version) const any_axis_type &axis(unsigned i = 0) const { - if (i >= dim()) - throw std::out_of_range("axis index out of range"); + BOOST_ASSERT_MSG(i < dim(), "axis index out of range"); return axes_[i]; } @@ -325,7 +323,7 @@ private: std::size_t idx = 0, stride = 1; lin_iter(idx, stride, std::begin(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } @@ -336,7 +334,7 @@ private: std::size_t idx = 0, stride = 1; lin_get(mpl::int_::value>(), idx, stride, std::forward(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } @@ -347,7 +345,7 @@ private: std::size_t idx = 0, stride = 1; lin<0>(idx, stride, detail::indirect_int_cast(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } diff --git a/include/boost/histogram/static_histogram.hpp b/include/boost/histogram/static_histogram.hpp index 4d5344e8..2b0aa57e 100644 --- a/include/boost/histogram/static_histogram.hpp +++ b/include/boost/histogram/static_histogram.hpp @@ -119,23 +119,22 @@ public: return detail::axes_equal(axes_, rhs.axes_) && storage_ == rhs.storage_; } - template - bool operator!=(const histogram &rhs) const noexcept { + template + bool operator!=(const histogram &rhs) const noexcept { return !operator==(rhs); } template histogram &operator+=(const histogram &rhs) { - if (!detail::axes_equal(axes_, rhs.axes_)) - throw std::logic_error("axes of histograms differ"); + BOOST_ASSERT_MSG(detail::axes_equal(axes_, rhs.axes_), "axes of histograms differ"); storage_ += rhs.storage_; return *this; } - template - histogram &operator+=(const histogram &rhs) { + template + histogram &operator+=(const histogram &rhs) { if (!detail::axes_equal(axes_, rhs.axes_)) - throw std::logic_error("axes of histograms differ"); + throw std::invalid_argument("axes of histograms differ"); storage_ += rhs.storage_; return *this; } @@ -192,7 +191,7 @@ public: std::size_t idx = 0, stride = 1; lin<0>(idx, stride, static_cast(indices)...); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } @@ -333,7 +332,7 @@ private: std::size_t idx = 0, stride = 1; lin_iter(mpl::int_(), idx, stride, std::begin(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } @@ -344,18 +343,16 @@ private: std::size_t idx = 0, stride = 1; lin_get(mpl::int_(), idx, stride, std::forward(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } template const_reference bin_impl(detail::no_container_tag, T&&t) const { - static_assert(axes_size::value == 1, - "bin argument does not match histogram dimension"); std::size_t idx = 0, stride = 1; - lin<0>(idx, stride, static_cast(t)); + lin<0>(idx, stride, detail::indirect_int_cast(t)); if (stride == 0) - throw std::out_of_range("invalid index"); + throw std::out_of_range("bin index out of range"); return storage_[idx]; } diff --git a/src/python/axis.cpp b/src/python/axis.cpp index 9d95306e..7d35dd78 100644 --- a/src/python/axis.cpp +++ b/src/python/axis.cpp @@ -44,7 +44,7 @@ struct generic_iterator { } return iterable[idx++]; } - bp::object self() { return bp::object(*this); } + generic_iterator& self() { return *this; } bp::object iterable; unsigned idx = 0; unsigned size = 0; @@ -271,7 +271,7 @@ void register_axis_types() { docstring_options dopt(true, true, false); class_("generic_iterator", init()) - .def("__iter__", &generic_iterator::self) + .def("__iter__", &generic_iterator::self, return_internal_reference<>()) .def("__next__", &generic_iterator::next) // Python3 .def("next", &generic_iterator::next) // Python2 ; diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index cdff4ffa..6d347d35 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -384,19 +384,7 @@ std::string element_repr(const pyhistogram::element_type& e) { void register_histogram() { bp::docstring_options dopt(true, true, false); - bp::class_( - "element", "Holds value and variance of bin count.", bp::init()) - .add_property("value", element_value) - .add_property("variance", element_variance) - .def("__getitem__", element_getitem) - .def("__len__", element_len) - .def(bp::self + bp::self) - .def(bp::self += bp::self) - .def(bp::self += double()) - .def("__repr__", element_repr) - ; - - bp::class_>( + bp::scope s = bp::class_>( "histogram", "N-dimensional histogram for real-valued data.", bp::no_init) .def("__init__", bp::raw_function(histogram_init), ":param axis args: axis objects" @@ -430,6 +418,7 @@ void register_histogram() { .def("__repr__", histogram_repr, ":return: string representation of the histogram") .def(bp::self == bp::self) + .def(bp::self != bp::self) .def(bp::self += bp::self) .def(bp::self *= double()) .def(bp::self * double()) @@ -437,4 +426,21 @@ void register_histogram() { .def(bp::self + bp::self) .def_pickle(bh::serialization_suite()) ; + + bp::class_( + "element", "Holds value and variance of bin count.", + bp::init()) + .add_property("value", element_value) + .add_property("variance", element_variance) + .def("__getitem__", element_getitem) + .def("__len__", element_len) + .def(bp::self == bp::self) + .def(bp::self != bp::self) + .def(bp::self += bp::self) + .def(bp::self += double()) + .def(bp::self + bp::self) + .def(bp::self + double()) + .def(double() + bp::self) + .def("__repr__", element_repr) + ; } diff --git a/src/python/module.cpp b/src/python/module.cpp index eef2c407..edf440cc 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -8,7 +8,7 @@ #include #include #ifdef HAVE_NUMPY -#include +# include #endif void register_axis_types(); @@ -16,10 +16,13 @@ void register_histogram(); BOOST_PYTHON_MODULE(histogram) { using namespace boost::python; + scope current; #ifdef HAVE_NUMPY numpy::initialize(); + current.attr("HAVE_NUMPY") = true; +#else + current.attr("HAVE_NUMPY") = false; #endif - scope current; object axis_module = object( borrowed(PyImport_AddModule("histogram.axis")) ); diff --git a/test/fail_histogram_add_dynamic_test.cpp b/test/fail_histogram_add_dynamic_test.cpp new file mode 100644 index 00000000..070666ba --- /dev/null +++ b/test/fail_histogram_add_dynamic_test.cpp @@ -0,0 +1,8 @@ +#include + +using namespace boost::histogram; +int main() { + auto a = make_dynamic_histogram(axis::integer<>(0, 2)); + auto b = make_dynamic_histogram(axis::integer<>(0, 3)); + a += b; +} diff --git a/test/fail_histogram_add_static_test.cpp b/test/fail_histogram_add_static_test.cpp new file mode 100644 index 00000000..cff1ed26 --- /dev/null +++ b/test/fail_histogram_add_static_test.cpp @@ -0,0 +1,8 @@ +#include + +using namespace boost::histogram; +int main() { + auto a = make_static_histogram(axis::integer<>(0, 2)); + auto b = make_static_histogram(axis::integer<>(0, 3)); + a += b; +} diff --git a/test/fail_histogram_dynamic_bin_0_test.cpp b/test/fail_histogram_dynamic_bin_0_test.cpp new file mode 100644 index 00000000..ee90f141 --- /dev/null +++ b/test/fail_histogram_dynamic_bin_0_test.cpp @@ -0,0 +1,7 @@ +#include + +using namespace boost::histogram; +int main() { + auto h = make_dynamic_histogram(axis::integer<>(0, 2)); + h.bin(0, 0); +} diff --git a/test/fail_histogram_dynamic_bin_1_test.cpp b/test/fail_histogram_dynamic_bin_1_test.cpp new file mode 100644 index 00000000..7c72f1fe --- /dev/null +++ b/test/fail_histogram_dynamic_bin_1_test.cpp @@ -0,0 +1,7 @@ +#include + +using namespace boost::histogram; +int main() { + auto h = make_dynamic_histogram(axis::integer<>(0, 2)); + h.bin(-2); +} diff --git a/test/fail_histogram_dynamic_bin_2_test.cpp b/test/fail_histogram_dynamic_bin_2_test.cpp new file mode 100644 index 00000000..cc54df6e --- /dev/null +++ b/test/fail_histogram_dynamic_bin_2_test.cpp @@ -0,0 +1,9 @@ +#include +#include + +using namespace boost::histogram; +int main() { + auto h = make_dynamic_histogram(axis::integer<>(0, 2), + axis::integer<>(0, 2)); + h.bin(std::make_pair(-2, 0)); +} diff --git a/test/fail_histogram_dynamic_bin_3_test.cpp b/test/fail_histogram_dynamic_bin_3_test.cpp new file mode 100644 index 00000000..8cf3ea63 --- /dev/null +++ b/test/fail_histogram_dynamic_bin_3_test.cpp @@ -0,0 +1,9 @@ +#include +#include + +using namespace boost::histogram; +int main() { + auto h = make_dynamic_histogram(axis::integer<>(0, 2), + axis::integer<>(0, 2)); + h.bin(std::vector({-2, 0})); +} diff --git a/test/fail_histogram_dynamic_bin_4_test.cpp b/test/fail_histogram_dynamic_bin_4_test.cpp new file mode 100644 index 00000000..cc12fc77 --- /dev/null +++ b/test/fail_histogram_dynamic_bin_4_test.cpp @@ -0,0 +1,9 @@ +#include +#include + +using namespace boost::histogram; +int main() { + auto h = make_dynamic_histogram(axis::integer<>(0, 2)); + struct non_convertible_to_int {}; + h.bin(non_convertible_to_int{}); +} diff --git a/test/fail_histogram_static_bin_0_test.cpp b/test/fail_histogram_static_bin_0_test.cpp new file mode 100644 index 00000000..57a90cd2 --- /dev/null +++ b/test/fail_histogram_static_bin_0_test.cpp @@ -0,0 +1,7 @@ +#include + +using namespace boost::histogram; +int main() { + auto h = make_static_histogram(axis::integer<>(0, 2)); + h.bin(std::vector({0, 0})); +} diff --git a/test/fail_histogram_static_bin_1_test.cpp b/test/fail_histogram_static_bin_1_test.cpp new file mode 100644 index 00000000..69380894 --- /dev/null +++ b/test/fail_histogram_static_bin_1_test.cpp @@ -0,0 +1,9 @@ +#include +#include + +using namespace boost::histogram; +int main() { + auto h = make_static_histogram(axis::integer<>(0, 2), + axis::integer<>(0, 2)); + h.bin(std::vector(-2, 0)); +} diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 8a75e786..50b84124 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -510,13 +510,6 @@ template void run_tests() { BOOST_TEST_EQ(d.bin(3), 0); } - // bad_add - { - auto a = make_histogram(Type(), axis::integer<>(0, 2)); - auto b = make_histogram(Type(), axis::integer<>(0, 3)); - BOOST_TEST_THROWS(a += b, std::logic_error); - } - // functional programming { auto v = std::vector{0, 1, 2}; diff --git a/test/pass_on_fail.py b/test/pass_on_fail.py new file mode 100644 index 00000000..80f492f0 --- /dev/null +++ b/test/pass_on_fail.py @@ -0,0 +1,12 @@ +import subprocess as subp +import sys +import os + +args = sys.argv[1:] + +if not os.path.isabs(args[0]): + args[0] = os.path.abspath(args[0]) + +exit_code = subp.call(args) + +sys.exit(not exit_code) diff --git a/test/python_suite_test.py b/test/python_suite_test.py index 8f9b6a17..1b4e23e6 100644 --- a/test/python_suite_test.py +++ b/test/python_suite_test.py @@ -8,27 +8,23 @@ import unittest from math import pi -from histogram import histogram, element +from histogram import HAVE_NUMPY +from histogram import histogram from histogram.axis import (regular, regular_log, regular_sqrt, regular_cos, regular_pow, circular, variable, category, integer) import pickle -import os import sys if sys.version_info.major == 3: from io import BytesIO else: from StringIO import StringIO as BytesIO - -ON = True -OFF = False -have_numpy = @BUILD_NUMPY@ # noqa -if have_numpy: +if HAVE_NUMPY: import numpy def hsum(h): - result = element(0, 0) + result = histogram.element(0, 0) for x in h: result += x return result @@ -394,6 +390,31 @@ class test_category(unittest.TestCase): self.assertEqual([x for x in category(*c)], c) +class test_histogram_element(unittest.TestCase): + + def test_basic(self): + elem = histogram.element(1, 2) + self.assertEqual(elem.value, 1) + self.assertEqual(elem.variance, 2) + self.assertEqual(len(elem), 2) + self.assertEqual(elem[0], 1) + self.assertEqual(elem[1], 2) + self.assertEqual(tuple(elem), (1, 2)) + + def test_ops(self): + a = histogram.element(1, 2) + b = histogram.element(2, 1) + self.assertNotEqual(a, b) + self.assertEqual(a + b, histogram.element(3, 3)) + self.assertEqual(a + 1, histogram.element(2, 3)) + self.assertEqual(1 + a, histogram.element(2, 3)) + self.assertEqual(a + 2, histogram.element(3, 4)) + + def test_repr(self): + elem = histogram.element(1, 2) + self.assertEqual(str(elem), "histogram.element(1, 2)") + + class test_histogram(unittest.TestCase): def test_init(self): @@ -537,7 +558,7 @@ class test_histogram(unittest.TestCase): def test_add_2d_bad(self): a = histogram(integer(-1, 1)) b = histogram(regular(3, -1, 1)) - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): a += b def test_add_2d_w(self): @@ -628,7 +649,7 @@ class test_histogram(unittest.TestCase): self.assertNotEqual((h + h).bin(0).variance, (2 * h).bin(0).variance) self.assertNotEqual((h + h).bin(0).variance, (h * 2).bin(0).variance) h2 = histogram(regular(2, 0, 2)) - with self.assertRaises(RuntimeError): + with self.assertRaises(ValueError): h + h2 def test_reduce_to(self): @@ -705,7 +726,7 @@ class test_histogram(unittest.TestCase): self.assertEqual(hsum(a).value, hsum(b).value) self.assertEqual(a, b) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_0(self): a = histogram(integer(0, 3, uoflow=False)) a(0) @@ -732,7 +753,7 @@ class test_histogram(unittest.TestCase): # view does not follow underlying switch in word size self.assertFalse(numpy.all(c == v)) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_1(self): a = histogram(integer(0, 3)) for i in range(10): @@ -743,7 +764,7 @@ class test_histogram(unittest.TestCase): self.assertTrue(numpy.all(c == numpy.array(((0, 30, 0, 0, 0), (0, 90, 0, 0, 0))))) self.assertTrue(numpy.all(v == c)) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_2(self): a = histogram(integer(0, 2, uoflow=False), integer(0, 3, uoflow=False), @@ -770,7 +791,7 @@ class test_histogram(unittest.TestCase): self.assertTrue(numpy.all(c == r)) self.assertTrue(numpy.all(v == r)) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_3(self): a = histogram(integer(0, 2), integer(0, 3), @@ -796,7 +817,7 @@ class test_histogram(unittest.TestCase): self.assertTrue(numpy.all(c == r)) self.assertTrue(numpy.all(v == r)) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_4(self): a = histogram(integer(0, 2, uoflow=False), integer(0, 4, uoflow=False)) @@ -809,7 +830,7 @@ class test_histogram(unittest.TestCase): self.assertEqual(b1.shape, (0,)) self.assertEqual(numpy.sum(b1), 0) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_5(self): a = histogram(integer(0, 3, uoflow=False), integer(0, 2, uoflow=False)) @@ -835,7 +856,7 @@ class test_histogram(unittest.TestCase): self.assertEqual(a1[1, 1], 4) self.assertEqual(a1[2, 1], 5) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_numpy_conversion_6(self): a = integer(0, 2) b = regular(2, 0, 2) @@ -851,7 +872,7 @@ class test_histogram(unittest.TestCase): ref = numpy.array((1, 2)) self.assertTrue(numpy.all(numpy.array(e) == ref)) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_fill_with_numpy_array_0(self): def ar(*args): return numpy.array(args, dtype=float) @@ -886,7 +907,7 @@ class test_histogram(unittest.TestCase): self.assertEqual(a.bin(1).value, 2) self.assertEqual(a.bin(2).value, 3) - @unittest.skipUnless(have_numpy, "requires build with numpy-support") + @unittest.skipUnless(HAVE_NUMPY, "requires build with numpy-support") def test_fill_with_numpy_array_1(self): def ar(*args): return numpy.array(args, dtype=float) diff --git a/test/weight_counter_test.cpp b/test/weight_counter_test.cpp index ced45d00..9aee6c5b 100644 --- a/test/weight_counter_test.cpp +++ b/test/weight_counter_test.cpp @@ -6,28 +6,19 @@ #include #include +#include #include #include using namespace boost::histogram; using wcount = weight_counter; -namespace boost { -namespace histogram { -template -std::ostream &operator<<(std::ostream &os, const weight_counter &w) { - os << "[" << w.value() << ", " << w.variance() << "]"; - return os; -} -} // namespace histogram -} // namespace boost - int main() { { wcount w(1); std::ostringstream os; os << w; - BOOST_TEST_EQ(os.str(), std::string("[1, 1]")); + BOOST_TEST_EQ(os.str(), std::string("weight_counter(1, 1)")); BOOST_TEST_EQ(w, wcount(1)); BOOST_TEST_NE(w, wcount(0));