// Copyright 2018 Hans Dembinski // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include "throw_exception.hpp" #include #include #include "utility_histogram.hpp" using namespace boost::histogram; using boost::histogram::algorithm::sum; template void run_tests() { auto ax = axis::integer<>(0, 100); auto h1 = make(Tag(), ax); for (unsigned i = 0; i < 100; ++i) h1(i); BOOST_TEST_EQ(sum(h1), 100); auto h2 = make_s(Tag(), std::vector(), ax, ax); for (unsigned i = 0; i < 100; ++i) for (unsigned j = 0; j < 100; ++j) h2(i, j); BOOST_TEST_EQ(sum(h2), 10000); auto h3 = make_s(Tag(), std::array(), ax); for (unsigned i = 0; i < 100; ++i) h3(i); BOOST_TEST_EQ(sum(h3), 100); auto h4 = make_s(Tag(), std::unordered_map(), ax); for (unsigned i = 0; i < 100; ++i) h4(i); BOOST_TEST_EQ(sum(h4), 100); auto h5 = make_s(Tag(), std::vector>(), axis::integer<>(0, 1), axis::integer(2, 4)); h5(weight(2), 0, 2); h5(-1, 2); h5(1, 3); const auto v = algorithm::sum(h5); BOOST_TEST_EQ(v.value(), 4); BOOST_TEST_EQ(v.variance(), 6); } int main() { run_tests(); run_tests(); return boost::report_errors(); }