From 107feaf646298bbfa541e28b6bd13d03c3deed79 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 26 Oct 2018 01:24:43 +0200 Subject: [PATCH] test for quantity transform --- include/boost/histogram/axis/regular.hpp | 12 ++++++-- .../histogram/storage/adaptive_storage.hpp | 4 +++ test/axis_test.cpp | 28 +++++++++---------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/include/boost/histogram/axis/regular.hpp b/include/boost/histogram/axis/regular.hpp index 29ac4bd5..1f1f364e 100644 --- a/include/boost/histogram/axis/regular.hpp +++ b/include/boost/histogram/axis/regular.hpp @@ -47,10 +47,10 @@ struct sqrt : identity { template struct pow { using U = mp11::mp_if, double, T>; - U power = 1; + U power = 1.0; - pow() = default; pow(U p) : power(p) {} + pow() = default; U forward(U v) const { return std::pow(v, power); } U inverse(U v) const { return std::pow(v, 1.0 / power); } @@ -59,6 +59,14 @@ struct pow { template void serialize(Archive&, unsigned); }; + +template +struct unit { + using T = typename Q::value_type; + using U = typename Q::unit_type; + T forward(Q x) const { return x / U(); } + Q inverse(T x) const { return x * U(); } +}; } // namespace transform /** Axis for equidistant intervals on the real line. diff --git a/include/boost/histogram/storage/adaptive_storage.hpp b/include/boost/histogram/storage/adaptive_storage.hpp index 53af8bda..b0128697 100644 --- a/include/boost/histogram/storage/adaptive_storage.hpp +++ b/include/boost/histogram/storage/adaptive_storage.hpp @@ -15,7 +15,11 @@ #include #include #include +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-parameter" +// warning-ignore required in Boost-1.66 for cpp_int.hpp:822 #include +#pragma clang diagnostic pop #include #include #include diff --git a/test/axis_test.cpp b/test/axis_test.cpp index ebfeb755..08107f59 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -150,21 +150,21 @@ int main() { using namespace boost::units::si; using Q = quantity; - // axis::regular> b(2, 0 * meter, 2 * meter); - // BOOST_TEST_EQ(b[-1].lower() / meter, -std::numeric_limits::infinity()); - // BOOST_TEST_IS_CLOSE(b[0].lower() / meter, 0.0, 1e-9); - // BOOST_TEST_IS_CLOSE(b[1].lower() / meter, 1.0, 1e-9); - // BOOST_TEST_IS_CLOSE(b[2].lower() / meter, 2.0, 1e-9); - // BOOST_TEST_EQ(b[2].upper() / meter, std::numeric_limits::infinity()); + axis::regular> b(2, 0 * meter, 2 * meter); + BOOST_TEST_EQ(b[-1].lower() / meter, -std::numeric_limits::infinity()); + BOOST_TEST_IS_CLOSE(b[0].lower() / meter, 0.0, 1e-9); + BOOST_TEST_IS_CLOSE(b[1].lower() / meter, 1.0, 1e-9); + BOOST_TEST_IS_CLOSE(b[2].lower() / meter, 2.0, 1e-9); + BOOST_TEST_EQ(b[2].upper() / meter, std::numeric_limits::infinity()); - // BOOST_TEST_EQ(b(-1 * meter), -1); // produces NaN in conversion - // BOOST_TEST_EQ(b(0 * meter), 0); - // BOOST_TEST_EQ(b(0.99 * meter), 0); - // BOOST_TEST_EQ(b(1 * meter), 1); - // BOOST_TEST_EQ(b(1.99 * meter), 1); - // BOOST_TEST_EQ(b(2 * meter), 2); - // BOOST_TEST_EQ(b(100 * meter), 2); - // BOOST_TEST_EQ(b(std::numeric_limits::infinity() * meter), 2); + BOOST_TEST_EQ(b(-1 * meter), -1); // produces NaN in conversion + BOOST_TEST_EQ(b(0 * meter), 0); + BOOST_TEST_EQ(b(0.99 * meter), 0); + BOOST_TEST_EQ(b(1 * meter), 1); + BOOST_TEST_EQ(b(1.99 * meter), 1); + BOOST_TEST_EQ(b(2 * meter), 2); + BOOST_TEST_EQ(b(100 * meter), 2); + BOOST_TEST_EQ(b(std::numeric_limits::infinity() * meter), 2); } // axis::circular