boost_accumulators_support_test.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018-2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/accumulators/accumulators.hpp>
  7. #include <boost/accumulators/statistics/mean.hpp>
  8. #include <boost/accumulators/statistics/stats.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <boost/histogram/axis/integer.hpp>
  11. #include "throw_exception.hpp"
  12. #include <boost/histogram/make_histogram.hpp>
  13. #include <boost/histogram/storage_adaptor.hpp>
  14. namespace ba = boost::accumulators;
  15. int main() {
  16. using namespace boost::histogram;
  17. // mean
  18. {
  19. using mean = ba::accumulator_set<double, ba::stats<ba::tag::mean>>;
  20. auto h = make_histogram_with(dense_storage<mean>(), axis::integer<>(0, 2));
  21. h(0, sample(1));
  22. h(0, sample(2));
  23. h(0, sample(3));
  24. h(1, sample(2));
  25. h(1, sample(3));
  26. BOOST_TEST_EQ(ba::count(h[0]), 3);
  27. BOOST_TEST_EQ(ba::mean(h[0]), 2);
  28. BOOST_TEST_EQ(ba::count(h[1]), 2);
  29. BOOST_TEST_EQ(ba::mean(h[1]), 2.5);
  30. BOOST_TEST_EQ(ba::count(h[2]), 0);
  31. auto h2 = h; // copy ok
  32. BOOST_TEST_EQ(ba::count(h2[0]), 3);
  33. BOOST_TEST_EQ(ba::mean(h2[0]), 2);
  34. BOOST_TEST_EQ(ba::count(h2[1]), 2);
  35. BOOST_TEST_EQ(ba::mean(h2[1]), 2.5);
  36. BOOST_TEST_EQ(ba::count(h2[2]), 0);
  37. }
  38. return boost::report_errors();
  39. }