histogram_serialization_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/assert.hpp>
  7. #include <boost/core/lightweight_test.hpp>
  8. #include <boost/histogram/axis.hpp>
  9. #include <boost/histogram/axis/ostream.hpp>
  10. #include <boost/histogram/ostream.hpp>
  11. #include <boost/histogram/serialization.hpp>
  12. #include <cmath>
  13. #include <string>
  14. #include "throw_exception.hpp"
  15. #include "utility_histogram.hpp"
  16. #include "utility_serialization.hpp"
  17. using namespace boost::histogram;
  18. template <typename Tag>
  19. void run_tests(const std::string& filename) {
  20. // histogram_serialization
  21. namespace tr = axis::transform;
  22. using def = use_default;
  23. using axis::option::none_t;
  24. auto a =
  25. make(Tag(), axis::regular<double, def, def, none_t>(1, -1, 1, "reg"),
  26. axis::circular<float, def, none_t>(1, 0.0, 1.0, "cir"),
  27. axis::regular<double, tr::log, def, none_t>(1, 1, std::exp(2), "reg-log"),
  28. axis::regular<double, tr::pow, std::vector<int>, axis::option::overflow_t>(
  29. tr::pow(0.5), 1, 1, 100, {1, 2, 3}),
  30. axis::variable<double, def, none_t>({1.5, 2.5}, "var"),
  31. axis::category<int, def, none_t>{3, 1},
  32. axis::integer<int, axis::null_type, none_t>(1, 2));
  33. a(0.5, 0.2, 2, 20, 2.2, 1, 1);
  34. print_xml(filename, a);
  35. auto b = decltype(a)();
  36. BOOST_TEST_NE(a, b);
  37. load_xml(filename, b);
  38. BOOST_TEST_EQ(a, b);
  39. }
  40. int main(int argc, char** argv) {
  41. BOOST_ASSERT(argc == 2);
  42. run_tests<static_tag>(join(argv[1], "histogram_serialization_test_static.xml"));
  43. run_tests<dynamic_tag>(join(argv[1], "histogram_serialization_test_dynamic.xml"));
  44. return boost::report_errors();
  45. }