// 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 #include #include #include #include #include #include #include "std_ostream.hpp" #include "throw_exception.hpp" using namespace boost::histogram; namespace tr = axis::transform; // tests requires a C++17 compatible compiler #define TEST BOOST_TEST_TRAIT_SAME int main() { using axis::null_type; { using axis::regular; BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0, 1.0)), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1)), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f)), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0, 1, 0)), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(1, 0.0f, 1.0f, "x")), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1)), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0.0f, 1.0f, "x")), regular); BOOST_TEST_TRAIT_SAME(decltype(regular(tr::sqrt(), 1, 0, 1, 0)), regular); } { using axis::integer; BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2)), integer); BOOST_TEST_TRAIT_SAME(decltype(integer(1l, 2l)), integer); BOOST_TEST_TRAIT_SAME(decltype(integer(1.0, 2.0)), integer); BOOST_TEST_TRAIT_SAME(decltype(integer(1.0f, 2.0f)), integer); BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, "foo")), integer); BOOST_TEST_TRAIT_SAME(decltype(integer(1, 2, 0)), integer); } { using axis::variable; BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0f, 1.0f}), variable); BOOST_TEST_TRAIT_SAME(decltype(variable{-1, 0, 1, 2}), variable); BOOST_TEST_TRAIT_SAME(decltype(variable{-1.0, 1.0}), variable); BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 0, 1}, "foo")), variable); BOOST_TEST_TRAIT_SAME(decltype(variable({-1, 1}, 0)), variable); BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector{{-1, 1}})), variable); BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector{{-1.0f, 1.0f}})), variable); BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector{{-1, 1}}, "foo")), variable); BOOST_TEST_TRAIT_SAME(decltype(variable(std::vector{{-1, 1}}, 0)), variable); } { using axis::category; BOOST_TEST_TRAIT_SAME(decltype(category{1, 2}), category); BOOST_TEST_TRAIT_SAME(decltype(category{"x", "y"}), category); BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, "foo")), category); BOOST_TEST_TRAIT_SAME(decltype(category({1, 2}, 0)), category); } { auto h = histogram(axis::regular(3, -1, 1), axis::integer(0, 4)); BOOST_TEST_TRAIT_SAME(decltype(h), histogram, axis::integer>>); BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1)); BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4)); } { auto h = histogram(std::tuple(axis::regular(3, -1, 1), axis::integer(0, 4)), weight_storage()); BOOST_TEST_TRAIT_SAME(decltype(h), histogram, axis::integer>, weight_storage>); BOOST_TEST_EQ(h.axis(0), axis::regular(3, -1, 1)); BOOST_TEST_EQ(h.axis(1), axis::integer(0, 4)); } { auto a0 = axis::regular(5, 0, 5); auto a1 = axis::regular(3, -1, 1); auto axes = {a0, a1}; auto h = histogram(axes); BOOST_TEST_TRAIT_SAME( decltype(h), histogram>>); BOOST_TEST_EQ(h.rank(), 2); BOOST_TEST_EQ(h.axis(0), a0); BOOST_TEST_EQ(h.axis(1), a1); } { auto a0 = axis::regular(5, 0, 5); auto a1 = axis::regular(3, -1, 1); auto axes = {a0, a1}; auto h = histogram(axes, weight_storage()); BOOST_TEST_TRAIT_SAME( decltype(h), histogram>, weight_storage>); BOOST_TEST_EQ(h.rank(), 2); BOOST_TEST_EQ(h.axis(0), a0); BOOST_TEST_EQ(h.axis(1), a1); } { auto a0 = axis::regular(5, 0, 5); auto a1 = axis::regular(3, -1, 1); auto axes = std::vector{{a0, a1}}; auto h = histogram(axes); BOOST_TEST_TRAIT_SAME( decltype(h), histogram>>); BOOST_TEST_EQ(h.rank(), 2); BOOST_TEST_EQ(h.axis(0), a0); BOOST_TEST_EQ(h.axis(1), a1); } return boost::report_errors(); }