From aecfab98bbe2ed9fed0cbb115f9765269148bce1 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Thu, 27 Apr 2017 14:30:10 +0200 Subject: [PATCH] test and fix mixed assignment --- .../boost/histogram/detail/axis_visitor.hpp | 8 ++--- test/axis_test.cpp | 5 +++ test/histogram_test.cpp | 33 +++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/boost/histogram/detail/axis_visitor.hpp b/include/boost/histogram/detail/axis_visitor.hpp index 415fba35..dea20a87 100644 --- a/include/boost/histogram/detail/axis_visitor.hpp +++ b/include/boost/histogram/detail/axis_visitor.hpp @@ -116,7 +116,7 @@ template struct fusion_assign_axis { template struct fusion_assign_axis2 { mutable Iterator iter; fusion_assign_axis2(Iterator it) : iter(it) {} - template void operator()(const T &t) const { *(iter++) == t; } + template void operator()(const T &t) const { *(iter++) = t; } }; struct field_count : public static_visitor { @@ -148,7 +148,7 @@ inline bool axes_equal_impl(mpl::false_, mpl::false_, const A &a, const B &b) { template inline bool axes_equal_impl(mpl::false_, mpl::true_, const A &a, const B &b) { - if (a.size() != fusion::size(b)) + if (a.size() != static_cast(fusion::size(b))) return false; fusion_cmp_axis cmp(a.begin()); fusion::for_each(b, cmp); @@ -188,13 +188,13 @@ inline void axes_assign_impl(mpl::false_, mpl::false_, A &a, const B &b) { template inline void axes_assign_impl(mpl::false_, mpl::true_, A &a, const B &b) { a.resize(fusion::size(b)); - fusion::for_each(b, fusion_assign_axis2(b.begin())); + fusion::for_each(b, fusion_assign_axis2(a.begin())); } template inline void axes_assign_impl(mpl::true_, mpl::false_, A &a, const B &b) { BOOST_ASSERT_MSG( - fusion::size(a) == b.size(), + static_cast(fusion::size(a)) == b.size(), "cannot assign to static axes vector: number of axes does not match"); fusion::for_each(a, fusion_assign_axis(b.begin())); diff --git a/test/axis_test.cpp b/test/axis_test.cpp index f5ec9c60..fbb09572 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -344,6 +344,11 @@ int main() { detail::axes_assign(fusion_vector1, std_vector1); BOOST_TEST(detail::axes_equal(fusion_vector1, std_vector1)); + decltype(std_vector1) std_vector3; + BOOST_TEST_NOT(detail::axes_equal(std_vector3, fusion_vector1)); + detail::axes_assign(std_vector3, fusion_vector1); + BOOST_TEST(detail::axes_equal(std_vector3, fusion_vector1)); + auto fusion_vector2 = boost::fusion::make_vector(regular_axis<>{2, -1, 1}, variable_axis<>{-1, 0, 1}, category_axis{"A", "B"}); diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 6c5539d0..51890977 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -545,6 +545,37 @@ void run_tests() { } } +template +void run_mixed_tests() { + + // compare + { + auto a = make_histogram>( + T1{}, regular_axis<>{3, 0, 3}, integer_axis(0, 1)); + auto b = make_histogram>( + T2{}, regular_axis<>{3, 0, 3}, integer_axis(0, 1)); + BOOST_TEST_EQ(a, b); + auto b2 = make_histogram>( + T2{}, integer_axis{0, 3}, integer_axis(0, 1)); + BOOST_TEST_NE(a, b2); + auto b3 = make_histogram>( + T2{}, regular_axis<>(3, 0, 4), integer_axis(0, 1)); + BOOST_TEST_NE(a, b3); + } + + // copy_assign + { + auto a = make_histogram>( + T1{}, regular_axis<>{3, 0, 3}, integer_axis(0, 1)); + auto b = make_histogram>( + T2{}, regular_axis<>{3, 0, 3}, integer_axis(0, 1)); + a.fill(1, 1); + BOOST_TEST_NE(a, b); + b = a; + BOOST_TEST_EQ(a, b); + } +} + int main() { // common interface @@ -563,6 +594,8 @@ int main() { BOOST_TEST_EQ(h.axis(1), v[1]); } + run_mixed_tests(); + run_mixed_tests(); return boost::report_errors(); }