axis_option_test.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <boost/core/lightweight_test.hpp>
  7. #include <boost/histogram/axis/option.hpp>
  8. #include <iostream>
  9. using namespace boost::histogram::axis;
  10. template <unsigned N, unsigned M>
  11. bool operator==(option::bitset<N>, option::bitset<M>) {
  12. return N == M;
  13. }
  14. template <unsigned N>
  15. std::ostream& operator<<(std::ostream& os, option::bitset<N>) {
  16. os << "underflow " << static_cast<bool>(N & option::underflow) << " "
  17. << "overflow " << static_cast<bool>(N & option::overflow) << " "
  18. << "circular " << static_cast<bool>(N & option::circular) << " "
  19. << "growth " << static_cast<bool>(N & option::growth);
  20. return os;
  21. }
  22. int main() {
  23. using namespace option;
  24. using uoflow = decltype(underflow | overflow);
  25. constexpr auto uoflow_growth = uoflow{} | growth;
  26. BOOST_TEST_EQ(uoflow::value, underflow | overflow);
  27. BOOST_TEST_EQ(underflow | overflow, overflow | underflow);
  28. BOOST_TEST(underflow.test(underflow));
  29. BOOST_TEST_NOT(underflow.test(overflow));
  30. BOOST_TEST_NOT(underflow.test(underflow | overflow));
  31. BOOST_TEST(uoflow::test(underflow));
  32. BOOST_TEST(uoflow::test(overflow));
  33. BOOST_TEST_NOT(uoflow::test(circular));
  34. BOOST_TEST_NOT(uoflow::test(growth));
  35. BOOST_TEST(uoflow_growth.test(underflow));
  36. BOOST_TEST(uoflow_growth.test(overflow));
  37. BOOST_TEST(uoflow_growth.test(growth));
  38. BOOST_TEST_NOT(uoflow_growth.test(circular));
  39. BOOST_TEST_EQ(uoflow_growth & uoflow_growth, uoflow_growth);
  40. BOOST_TEST_EQ(uoflow_growth & growth, growth);
  41. BOOST_TEST_EQ(uoflow_growth & uoflow{}, uoflow::value);
  42. BOOST_TEST_EQ(uoflow_growth - growth, uoflow{});
  43. BOOST_TEST_EQ(uoflow_growth - uoflow{}, growth);
  44. BOOST_TEST_EQ(uoflow_growth - underflow, growth | overflow);
  45. return boost::report_errors();
  46. }