// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2015, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html #ifndef BOOST_TEST_MODULE #define BOOST_TEST_MODULE test_math_abs #endif #include #include #include #include #include "number_types.hpp" // important: the include above must precede the include below, // otherwise the test will fail for the custom number type: // custom_with_global_sqrt #include #include #ifdef HAVE_TTMATH # include #endif namespace bg = boost::geometry; namespace bgm = boost::geometry::math; template bool eq(T const& l, T const& r) { return !(l < r || r < l); } BOOST_AUTO_TEST_CASE( test_math_abs ) { { float p1 = bgm::pi(); double p2 = bgm::pi(); long double p3 = bgm::pi(); BOOST_CHECK(bgm::abs(p1) == p1); BOOST_CHECK(bgm::abs(p2) == p2); BOOST_CHECK(bgm::abs(p3) == p3); float n1 = -p1; double n2 = -p2; long double n3 = -p3; BOOST_CHECK(bgm::abs(n1) == p1); BOOST_CHECK(bgm::abs(n2) == p2); BOOST_CHECK(bgm::abs(n3) == p3); } { number_types::custom p1(bgm::pi()); number_types::custom_with_global_sqrt p2(bgm::pi()); custom_global p3(bgm::pi()); custom_raw p4(bgm::pi()); BOOST_CHECK(eq(bgm::abs(p1), p1)); BOOST_CHECK(eq(bgm::abs(p2), p2)); BOOST_CHECK(eq(bgm::abs(p3), p3)); BOOST_CHECK(eq(bgm::abs(p4), p4)); number_types::custom n1 = -p1; number_types::custom_with_global_sqrt n2 = -p2; custom_global n3 = -p3; custom_raw n4 = -p4; BOOST_CHECK(eq(bgm::abs(n1), p1)); BOOST_CHECK(eq(bgm::abs(n2), p2)); BOOST_CHECK(eq(bgm::abs(n3), p3)); BOOST_CHECK(eq(bgm::abs(n4), p4)); } #ifdef HAVE_TTMATH { ttmath_big p1 = bgm::pi(); ttmath::Big<1, 4> p1 = bgm::pi >(); BOOST_CHECK(bgm::abs(p1) == p1); BOOST_CHECK(bgm::abs(p2) == p2); ttmath_big n1 = -p1; ttmath::Big<1, 4> n2 = -p2; BOOST_CHECK(bgm::abs(n1) == p1); BOOST_CHECK(bgm::abs(n2) == p2); } #endif }