algorithm_empty_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 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 <array>
  7. #include <boost/core/lightweight_test.hpp>
  8. #include <boost/histogram/accumulators/weighted_mean.hpp>
  9. #include <boost/histogram/algorithm/empty.hpp>
  10. #include <boost/histogram/axis/integer.hpp>
  11. #include <unordered_map>
  12. #include <vector>
  13. #include "throw_exception.hpp"
  14. #include "utility_histogram.hpp"
  15. using namespace boost::histogram;
  16. using boost::histogram::algorithm::empty;
  17. template <typename Tag>
  18. void run_tests() {
  19. auto ax = axis::integer<>(0, 10);
  20. {
  21. auto h = make(Tag(), ax);
  22. BOOST_TEST(empty(h, coverage::all));
  23. BOOST_TEST(empty(h, coverage::inner));
  24. for (int i = -1; i < 11; ++i) {
  25. h.reset();
  26. h(i);
  27. BOOST_TEST(!empty(h, coverage::all));
  28. if (i == -1 || i == 10) {
  29. BOOST_TEST(empty(h, coverage::inner));
  30. } else {
  31. BOOST_TEST(!empty(h, coverage::inner));
  32. }
  33. }
  34. }
  35. {
  36. auto h = make_s(Tag(), std::vector<accumulators::weighted_mean<>>(),
  37. axis::integer<>(0, 10), axis::integer<>(0, 10));
  38. BOOST_TEST(empty(h, coverage::all));
  39. BOOST_TEST(empty(h, coverage::inner));
  40. h.reset();
  41. h(weight(2), -2, -4, sample(3));
  42. BOOST_TEST(!empty(h, coverage::all));
  43. BOOST_TEST(empty(h, coverage::inner));
  44. h.reset();
  45. h(weight(1), -4, 2, sample(2));
  46. BOOST_TEST(!empty(h, coverage::all));
  47. BOOST_TEST(empty(h, coverage::inner));
  48. h.reset();
  49. h(weight(3), 3, 5, sample(1));
  50. BOOST_TEST(!empty(h, coverage::all));
  51. BOOST_TEST(!empty(h, coverage::inner));
  52. }
  53. }
  54. int main() {
  55. run_tests<static_tag>();
  56. run_tests<dynamic_tag>();
  57. return boost::report_errors();
  58. }