diff options
Diffstat (limited to 'src/boost/libs/geometry/test/util')
-rw-r--r-- | src/boost/libs/geometry/test/util/Jamfile.v2 | 29 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/calculation_type.cpp | 208 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/compress_variant.cpp | 77 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/for_each_coordinate.cpp | 84 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/is_implemented.cpp | 88 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/math_abs.cpp | 102 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/math_equals.cpp | 79 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/math_sqrt.cpp | 153 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/number_types.hpp | 187 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/promote_integral.cpp | 547 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/range.cpp | 244 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/rational.cpp | 61 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/select_most_precise.cpp | 78 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/transform_variant.cpp | 68 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/util/write_dsv.cpp | 73 |
15 files changed, 2078 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/util/Jamfile.v2 b/src/boost/libs/geometry/test/util/Jamfile.v2 new file mode 100644 index 00000000..39ef14af --- /dev/null +++ b/src/boost/libs/geometry/test/util/Jamfile.v2 @@ -0,0 +1,29 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2014, 2015. +# Modifications copyright (c) 2014-2015, Oracle and/or its affiliates. +# +# Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle +# Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle +# +# Use, modification and distribution is subject to 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) + +test-suite boost-geometry-util + : + [ run calculation_type.cpp : : : : util_calculation_type ] + [ run for_each_coordinate.cpp : : : : util_for_each_coordinate ] + [ run math_abs.cpp : : : : util_math_abs ] + [ run math_equals.cpp : : : : util_math_equals ] + [ run math_sqrt.cpp : : : : util_math_sqrt ] + [ run promote_integral.cpp : : : : util_promote_integral ] + [ run range.cpp : : : : util_range ] + [ run rational.cpp : : : : util_rational ] + [ run select_most_precise.cpp : : : : util_select_most_precise ] + [ run write_dsv.cpp : : : : util_write_dsv ] + ; diff --git a/src/boost/libs/geometry/test/util/calculation_type.cpp b/src/boost/libs/geometry/test/util/calculation_type.cpp new file mode 100644 index 00000000..6e026676 --- /dev/null +++ b/src/boost/libs/geometry/test/util/calculation_type.cpp @@ -0,0 +1,208 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2012 Bruno Lalande, Paris, France. +// Copyright (c) 2012 Mateusz Loskot, London, UK. + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/util/calculation_type.hpp> + +template <typename G1, typename G2> +inline std::string helper() +{ + std::string result; + result += typeid(typename bg::coordinate_type<G1>::type).name(); + result += "/"; + result += typeid(typename bg::coordinate_type<G2>::type).name(); + return result; +} + +template <typename G1, typename G2, typename G3> +inline std::string helper3() +{ + std::string result; + result += typeid(typename bg::coordinate_type<G1>::type).name(); + result += "/"; + result += typeid(typename bg::coordinate_type<G2>::type).name(); + result += "/"; + result += typeid(typename bg::coordinate_type<G3>::type).name(); + return result; +} + +template +< + typename G1, + typename G2, + typename DefaultFP, + typename DefaultInt, + typename ExpectedType +> +void test() +{ + typedef typename bg::util::calculation_type::geometric::binary + < + G1, + G2, + void, + DefaultFP, + DefaultInt + >::type type; + + std::string const caption = helper<G1, G2>(); + + BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value), + "Failure, types do not agree;" + << " input: " << caption + << " defaults: " << typeid(DefaultFP).name() + << "/" << typeid(DefaultInt).name() + << " expected: " << typeid(ExpectedType).name() + << " detected: " << typeid(type).name() + ); +} + +template +< + typename G1, + typename G2, + typename CalculationType, + typename ExpectedType +> +void test_with_calculation_type() +{ + typedef typename bg::util::calculation_type::geometric::binary + < + G1, + G2, + CalculationType, + double, + int + >::type type; + + std::string const caption = helper<G1, G2>(); + + BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value), + "Failure, types do not agree;" + << " input: " << caption + << " calculation type: " << typeid(CalculationType).name() + << " expected: " << typeid(ExpectedType).name() + << " detected: " << typeid(type).name() + ); +} + +template +< + typename Geometry, + typename DefaultFP, + typename DefaultInt, + typename ExpectedType +> +void test_unary() +{ + typedef typename bg::util::calculation_type::geometric::unary + < + Geometry, + void, + DefaultFP, + DefaultInt + >::type type; + + BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value), + "Failure, types do not agree;" + << " input: " << typeid(typename bg::coordinate_type<Geometry>::type).name() + << " defaults: " << typeid(DefaultFP).name() + << "/" << typeid(DefaultInt).name() + << " expected: " << typeid(ExpectedType).name() + << " detected: " << typeid(type).name() + ); +} + + +template +< + typename G1, + typename G2, + typename G3, + typename DefaultFP, + typename DefaultInt, + typename ExpectedType +> +void test_ternary() +{ + typedef typename bg::util::calculation_type::geometric::ternary + < + G1, + G2, + G3, + void, + DefaultFP, + DefaultInt + >::type type; + + std::string const caption = helper3<G1, G2, G3>(); + + BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value), + "Failure, types do not agree;" + << " input: " << caption + << " defaults: " << typeid(DefaultFP).name() + << "/" << typeid(DefaultInt).name() + << " expected: " << typeid(ExpectedType).name() + << " detected: " << typeid(type).name() + ); +} + + +struct user_defined {}; + +int test_main(int, char* []) +{ + using namespace boost::geometry; + typedef model::point<double, 2, cs::cartesian> d; + typedef model::point<float, 2, cs::cartesian> f; + typedef model::point<int, 2, cs::cartesian> i; + typedef model::point<char, 2, cs::cartesian> c; + typedef model::point<short int, 2, cs::cartesian> s; + typedef model::point<boost::long_long_type, 2, cs::cartesian> ll; + typedef model::point<user_defined, 2, cs::cartesian> u; + + // Calculation type "void" so + test<f, f, double, int, double>(); + test<d, d, double, int, double>(); + test<f, d, double, int, double>(); + + // FP/int mixed + test<i, f, double, int, double>(); + test<s, f, double, short int, double>(); + + // integers + test<s, s, double, short int, short int>(); + test<i, i, double, int, int>(); + test<c, i, double, int, int>(); + test<c, c, double, char, char>(); + test<c, c, double, int, int>(); + test<i, i, double, boost::long_long_type, boost::long_long_type>(); + + // Even if we specify "int" as default-calculation-type, it should never go downwards. + // So it will select "long long" + test<ll, ll, double, int, boost::long_long_type>(); + + // user defined + test<u, i, double, char, user_defined>(); + test<u, d, double, double, user_defined>(); + + test_with_calculation_type<i, i, double, double>(); + test_with_calculation_type<u, u, double, double>(); + + test_unary<i, double, int, int>(); + test_unary<u, double, double, user_defined>(); + test_ternary<u, u, u, double, double, user_defined>(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/compress_variant.cpp b/src/boost/libs/geometry/test/util/compress_variant.cpp new file mode 100644 index 00000000..ab7a61ca --- /dev/null +++ b/src/boost/libs/geometry/test/util/compress_variant.cpp @@ -0,0 +1,77 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <boost/test/included/test_exec_monitor.hpp> +#include <boost/geometry/util/compress_variant.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/variant/variant.hpp> + + +template <typename ExpectedTypes, BOOST_VARIANT_ENUM_PARAMS(typename T)> +void check_variant_types(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>) +{ + BOOST_MPL_ASSERT(( + boost::mpl::equal< + typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types, + ExpectedTypes + > + )); +} + +template <typename Variant, typename ExpectedTypes> +void test_variant_result() +{ + check_variant_types<ExpectedTypes>(typename boost::geometry::compress_variant<Variant>::type()); +} + +template <typename Variant, typename ExpectedType> +void test_single_type_result() +{ + BOOST_MPL_ASSERT(( + boost::is_same< + typename boost::geometry::compress_variant<Variant>::type, + ExpectedType + > + )); +} + + +int test_main(int, char* []) +{ + test_variant_result< + boost::variant<int, float, double>, + boost::mpl::vector<int, float, double> + >(); + + test_variant_result< + boost::variant<int, float, double, int, int, float, double, double, float>, + boost::mpl::vector<int, double, float> + >(); + + test_single_type_result< + boost::variant<int>, + int + >(); + + test_single_type_result< + boost::variant<double, double, double, double, double>, + double + >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/for_each_coordinate.cpp b/src/boost/libs/geometry/test/util/for_each_coordinate.cpp new file mode 100644 index 00000000..140d6f6c --- /dev/null +++ b/src/boost/libs/geometry/test/util/for_each_coordinate.cpp @@ -0,0 +1,84 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <sstream> + +#include <geometry_test_common.hpp> + + +#include <boost/geometry/util/for_each_coordinate.hpp> + +#include <boost/geometry/algorithms/assign.hpp> + + +#include <boost/geometry/geometries/point.hpp> +#include <boost/geometry/geometries/adapted/c_array.hpp> +#include <boost/geometry/geometries/adapted/boost_tuple.hpp> +#include <test_common/test_point.hpp> + +BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) +BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) + + +struct test_operation +{ + template <typename P, int I> + static void apply(P& p) + { + bg::set<I>(p, bg::get<I>(p) * 10); + } +}; + +struct get_operation +{ + std::string s; + + template <typename P, int I> + inline void apply(P const& p) + { + std::ostringstream out; + out << bg::get<I>(p); + s += out.str(); + } +}; + + +template <typename P> +void test_all() +{ + P p; + bg::assign_values(p, 1, 2, 3); + bg::for_each_coordinate(p, test_operation()); + BOOST_CHECK(bg::get<0>(p) == 10); + BOOST_CHECK(bg::get<1>(p) == 20); + BOOST_CHECK(bg::get<2>(p) == 30); + + P const& cp = p; + get_operation op; + op = bg::for_each_coordinate(cp, op); + BOOST_CHECK(op.s == std::string("102030")); +} + +int test_main(int, char* []) +{ + test_all<int[3]>(); + test_all<float[3]>(); + test_all<double[3]>(); + test_all<test::test_point>(); + test_all<bg::model::point<int, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<float, 3, bg::cs::cartesian> >(); + test_all<bg::model::point<double, 3, bg::cs::cartesian> >(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/is_implemented.cpp b/src/boost/libs/geometry/test/util/is_implemented.cpp new file mode 100644 index 00000000..3eed994b --- /dev/null +++ b/src/boost/libs/geometry/test/util/is_implemented.cpp @@ -0,0 +1,88 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2014 Samuel Debionne, Grenoble, France. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <boost/geometry/core/reverse_dispatch.hpp> +#include <boost/geometry/core/tag_cast.hpp> + +#include <boost/geometry/geometries/point_xy.hpp> +#include <boost/geometry/strategies/tags.hpp> + +#include <boost/geometry/algorithms/not_implemented.hpp> + +#include <boost/geometry/util/is_implemented.hpp> + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/bool.hpp> + + +namespace boost { namespace geometry +{ + +namespace strategy { namespace services +{ + + +template <typename Strategy> struct tag +{ + + typedef not_implemented type; + +}; + +}} // namespace strategy::services + + +template +< + typename Geometry1, typename Geometry2, + typename Strategy, + typename Tag1 = typename tag_cast<typename tag<Geometry1>::type, multi_tag>::type, + typename Tag2 = typename tag_cast<typename tag<Geometry2>::type, multi_tag>::type, + typename StrategyTag = typename strategy::services::tag<Strategy>::type, + bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value +> +struct algorithm_archetype + : not_implemented<> +{}; + + +struct strategy_archetype +{ + template <typename Geometry1, typename Geometry2> + static void apply(Geometry1, Geometry2) {} +}; + + +}} // namespace boost::geometry + + +int test_main(int, char* []) +{ + typedef bg::model::d2::point_xy<double> point_type; + + BOOST_MPL_ASSERT(( + boost::is_same< + bg::util::is_implemented2 + < + point_type, point_type, + bg::algorithm_archetype<point_type, point_type, bg::strategy_archetype> + >::type, + boost::mpl::false_ + > + )); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/math_abs.cpp b/src/boost/libs/geometry/test/util/math_abs.cpp new file mode 100644 index 00000000..c1cfbf51 --- /dev/null +++ b/src/boost/libs/geometry/test/util/math_abs.cpp @@ -0,0 +1,102 @@ +// 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 <cmath> +#include <iostream> + +#include <boost/test/included/unit_test.hpp> + +#include <boost/config.hpp> + +#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 <boost/geometry/util/math.hpp> +#include <boost/geometry/algorithms/not_implemented.hpp> + +#ifdef HAVE_TTMATH +# include <boost/geometry/extensions/contrib/ttmath_stub.hpp> +#endif + +namespace bg = boost::geometry; +namespace bgm = boost::geometry::math; + +template <typename T> +bool eq(T const& l, T const& r) +{ + return !(l < r || r < l); +} + +BOOST_AUTO_TEST_CASE( test_math_abs ) +{ + { + float p1 = bgm::pi<float>(); + double p2 = bgm::pi<double>(); + long double p3 = bgm::pi<long double>(); + + 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<double> p1(bgm::pi<double>()); + number_types::custom_with_global_sqrt<double> p2(bgm::pi<double>()); + custom_global<double> p3(bgm::pi<double>()); + custom_raw<double> p4(bgm::pi<double>()); + + 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<double> n1 = -p1; + number_types::custom_with_global_sqrt<double> n2 = -p2; + custom_global<double> n3 = -p3; + custom_raw<double> 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>(); + ttmath::Big<1, 4> p1 = bgm::pi<ttmath::Big<1, 4> >(); + + 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 +} + diff --git a/src/boost/libs/geometry/test/util/math_equals.cpp b/src/boost/libs/geometry/test/util/math_equals.cpp new file mode 100644 index 00000000..0f26f695 --- /dev/null +++ b/src/boost/libs/geometry/test/util/math_equals.cpp @@ -0,0 +1,79 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2015 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <limits> +#include <boost/geometry/util/condition.hpp> +#include <boost/geometry/util/math.hpp> + +namespace bgm = bg::math; + +template <typename T> +void test_all() +{ + BOOST_CHECK(bgm::equals(0, 0)); + BOOST_CHECK(bgm::equals(1, 1)); + BOOST_CHECK(bgm::equals(123456, 123456)); + + T eps = std::numeric_limits<T>::epsilon(); + if ( eps > 0 ) + { + BOOST_CHECK(bgm::equals(0, 0+eps)); + BOOST_CHECK(bgm::equals(0+eps, 0)); + BOOST_CHECK(bgm::equals(1, 1+eps)); + BOOST_CHECK(bgm::equals(1+eps, 1)); + BOOST_CHECK(bgm::equals(12345+eps, 12345)); + } + + if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_infinity)) + { + T inf = std::numeric_limits<T>::infinity(); + BOOST_CHECK(!bgm::equals(0, inf)); + BOOST_CHECK(!bgm::equals(0, -inf)); + BOOST_CHECK(!bgm::equals(1, inf)); + BOOST_CHECK(!bgm::equals(1, -inf)); + BOOST_CHECK(!bgm::equals(12345, inf)); + BOOST_CHECK(!bgm::equals(12345, -inf)); + BOOST_CHECK(!bgm::equals(inf, 0)); + BOOST_CHECK(!bgm::equals(-inf, 0)); + BOOST_CHECK(!bgm::equals(inf, 1)); + BOOST_CHECK(!bgm::equals(-inf, 1)); + BOOST_CHECK(!bgm::equals(inf, 12345)); + BOOST_CHECK(!bgm::equals(-inf, 12345)); + BOOST_CHECK(bgm::equals(inf, inf)); + BOOST_CHECK(bgm::equals(-inf, -inf)); + BOOST_CHECK(!bgm::equals(inf, -inf)); + BOOST_CHECK(!bgm::equals(-inf, inf)); + } + + if (BOOST_GEOMETRY_CONDITION(std::numeric_limits<T>::has_quiet_NaN)) + { + T nan = std::numeric_limits<T>::quiet_NaN(); + BOOST_CHECK(!bgm::equals(0, nan)); + BOOST_CHECK(!bgm::equals(nan, 0)); + BOOST_CHECK(!bgm::equals(nan, nan)); + BOOST_CHECK(!bgm::equals(1, nan)); + BOOST_CHECK(!bgm::equals(nan, 1)); + BOOST_CHECK(!bgm::equals(12345, nan)); + BOOST_CHECK(!bgm::equals(nan, 12345)); + } +} + +int test_main(int, char* []) +{ + test_all<int>(); + test_all<float>(); + test_all<double>(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/math_sqrt.cpp b/src/boost/libs/geometry/test/util/math_sqrt.cpp new file mode 100644 index 00000000..2ca4834a --- /dev/null +++ b/src/boost/libs/geometry/test/util/math_sqrt.cpp @@ -0,0 +1,153 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2014, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, 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_sqrt +#endif + +#include <cmath> +#include <iostream> + +#include <boost/test/included/unit_test.hpp> + +#include <boost/config.hpp> +#include <boost/type_traits/is_fundamental.hpp> + +#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 <boost/geometry/util/math.hpp> +#include <boost/geometry/algorithms/not_implemented.hpp> + +#ifdef HAVE_TTMATH +# include <boost/geometry/extensions/contrib/ttmath_stub.hpp> +#endif + +namespace bg = boost::geometry; + + + + +// call BOOST_CHECK +template <typename Argument, bool IsFundamental /* true */> +struct check +{ + template <typename Result> + static inline void apply(Argument const& arg, Result const& result) + { + BOOST_CHECK_CLOSE(static_cast<double>(bg::math::sqrt(arg)), + static_cast<double>(result), + 0.00001); + } +}; + + +template <typename Argument> +struct check<Argument, false> +{ + template <typename Result> + static inline void apply(Argument const& arg, Result const& result) + { + Result const tol(0.00001); + BOOST_CHECK( bg::math::abs(bg::math::sqrt(arg) - result) < tol ); + } +}; + + + + + + +// test sqrt return type and value +template +< + typename Argument, + typename ExpectedResult, + typename Result = typename bg::math::detail::square_root + < + Argument + >::return_type, + bool IsFundamental = boost::is_fundamental<Argument>::value +> +struct check_sqrt + : bg::not_implemented<Argument, Result, ExpectedResult> +{}; + + +template <typename Argument, typename Result, bool IsFundamental> +struct check_sqrt<Argument, Result, Result, IsFundamental> +{ + static inline void apply(Argument const& arg, Result const& result) + { +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "testing: " << typeid(Result).name() + << " sqrt(" << typeid(Argument).name() + << ")" << std::endl; +#endif + check<Argument, IsFundamental>::apply(arg, result); + } +}; + + + + + + +// test cases +BOOST_AUTO_TEST_CASE( test_math_sqrt_fundamental ) +{ + static const double sqrt2 = std::sqrt(2.0); + static const long double sqrt2L = std::sqrt(2.0L); + static const float sqrt2F = std::sqrt(2.0F); + + check_sqrt<float, float>::apply(2.0F, sqrt2F); + check_sqrt<double, double>::apply(2.0, sqrt2); + check_sqrt<long double, long double>::apply(2.0L, sqrt2L); + + check_sqrt<char, double>::apply(2, sqrt2); + check_sqrt<signed char, double>::apply(2, sqrt2); + check_sqrt<short, double>::apply(2, sqrt2); + check_sqrt<int, double>::apply(2, sqrt2); + check_sqrt<long, double>::apply(2L, sqrt2); +#if !defined(BOOST_NO_LONG_LONG) + check_sqrt<long long, double>::apply(2LL, sqrt2); +#endif +#ifdef BOOST_HAS_LONG_LONG + check_sqrt + < + boost::long_long_type, double + >::apply(boost::long_long_type(2), sqrt2); +#endif +} + + +BOOST_AUTO_TEST_CASE( test_math_sqrt_custom ) +{ + typedef number_types::custom<double> custom1; + typedef custom_global<double> custom2; + typedef number_types::custom_with_global_sqrt<double> custom3; + + static const double sqrt2 = std::sqrt(2.0); + + check_sqrt<custom1, custom1>::apply(custom1(2.0), custom1(sqrt2)); + check_sqrt<custom2, custom2>::apply(custom2(2.0), custom2(sqrt2)); + check_sqrt<custom3, custom3>::apply(custom3(2.0), custom3(sqrt2)); + +#ifdef HAVE_TTMATH + typedef ttmath_big custom4; + typedef ttmath::Big<1, 4> custom5; + + check_sqrt<custom4, custom4>::apply(custom4(2.0), custom4(sqrt2)); + check_sqrt<custom5, custom5>::apply(custom5(2.0), custom5(sqrt2)); +#endif +} diff --git a/src/boost/libs/geometry/test/util/number_types.hpp b/src/boost/libs/geometry/test/util/number_types.hpp new file mode 100644 index 00000000..815dc956 --- /dev/null +++ b/src/boost/libs/geometry/test/util/number_types.hpp @@ -0,0 +1,187 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2014-2015 Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle +// 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_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP +#define BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP + +#include <cmath> + + +// define a custom number type and its sqrt in own namespace +namespace number_types +{ + +template <typename T> +struct custom +{ + typedef custom<T> self; + + T m_value; + + custom() : m_value(0) {} + explicit custom(T const& value) : m_value(value) {} + + bool operator<(self const& other) const + { + return m_value < other.m_value; + } + + self operator-() const + { + return self(-m_value); + } + + self operator-(self const& other) const + { + return self(m_value - other.m_value); + } +}; + +template <typename T> +inline custom<T> sqrt(custom<T> const& c) +{ + return custom<T>(std::sqrt(c.m_value)); +} + +template <typename T> +inline custom<T> fabs(custom<T> const& c) +{ + return custom<T>(c.m_value < T(0) ? c.m_value : -c.m_value); +} + +} // namespace number_types + + + + + + +// define a custom number type with sqrt in global namespace +namespace number_types +{ + +template <typename T> +struct custom_with_global_sqrt +{ + typedef custom_with_global_sqrt<T> self; + + T m_value; + + custom_with_global_sqrt() : m_value(0) {} + explicit custom_with_global_sqrt(T const& value) : m_value(value) {} + + bool operator<(self const& other) const + { + return m_value < other.m_value; + } + + self operator-() const + { + return self(-m_value); + } + + self operator-(self const& other) const + { + return self(m_value - other.m_value); + } +}; + +} // namespace number_types + +template <typename T> +inline number_types::custom_with_global_sqrt<T> +sqrt(number_types::custom_with_global_sqrt<T> const& c) +{ + return number_types::custom_with_global_sqrt<T>(std::sqrt(c.m_value)); +} + +template <typename T> +inline number_types::custom_with_global_sqrt<T> +fabs(number_types::custom_with_global_sqrt<T> const& c) +{ + return number_types::custom_with_global_sqrt<T> + (c.m_value < T(0) ? c.m_value : -c.m_value); +} + + + + + + +// define a custom number type and its sqrt in global namespace +template <typename T> +struct custom_global +{ + typedef custom_global<T> self; + + T m_value; + + custom_global() : m_value(0) {} + explicit custom_global(T const& value) : m_value(value) {} + + bool operator<(self const& other) const + { + return m_value < other.m_value; + } + + self operator-() const + { + return self(-m_value); + } + + self operator-(self const& other) const + { + return self(m_value - other.m_value); + } +}; + +template <typename T> +inline custom_global<T> sqrt(custom_global<T> const& c) +{ + return custom_global<T>(std::sqrt(c.m_value)); +} + +template <typename T> +inline custom_global<T> fabs(custom_global<T> const& c) +{ + return custom_global<T>(c.m_value < T(0) ? c.m_value : -c.m_value); +} + + + +// custom number type without functions definition +template <typename T> +struct custom_raw +{ + typedef custom_raw<T> self; + + T m_value; + + custom_raw() : m_value(0) {} + explicit custom_raw(T const& value) : m_value(value) {} + + bool operator<(self const& other) const + { + return m_value < other.m_value; + } + + self operator-() const + { + return self(-m_value); + } + + self operator-(self const& other) const + { + return self(m_value - other.m_value); + } +}; + +#endif // BOOST_GEOMETRY_TEST_UTIL_NUMBER_TYPES_HPP diff --git a/src/boost/libs/geometry/test/util/promote_integral.cpp b/src/boost/libs/geometry/test/util/promote_integral.cpp new file mode 100644 index 00000000..92d1b8ce --- /dev/null +++ b/src/boost/libs/geometry/test/util/promote_integral.cpp @@ -0,0 +1,547 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2015, Oracle and/or its affiliates. + +// Contributed and/or modified by Menelaos Karavelas, 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_promote_integral +#endif + +#include <climits> +#include <cstddef> +#include <algorithm> +#include <limits> +#include <iostream> +#include <string> +#include <sstream> + +#include <boost/test/included/unit_test.hpp> + +#include <boost/config.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/type_traits/is_unsigned.hpp> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/util/condition.hpp> +#include <boost/geometry/util/promote_integral.hpp> + +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) +#include <boost/multiprecision/cpp_int.hpp> +#endif + +#if defined(BOOST_GEOMETRY_TEST_DEBUG) +#if defined(BOOST_HAS_INT128) && defined(BOOST_GEOMETRY_ENABLE_INT128) +void print_uint128_t(std::ostream& os, boost::uint128_type i) +{ + if (i == 0) + { + os << "0"; + return; + } + + std::stringstream stream; + while (i > 0) + { + stream << static_cast<int>(i % 10); + i /= 10; + } + std::string str = stream.str(); + std::reverse(str.begin(), str.end()); + os << str; +} + +std::ostream& operator<<(std::ostream& os, boost::int128_type i) +{ + if (i < 0) + { + os << "-"; + print_uint128_t(os, static_cast<boost::uint128_type>(-i)); + } + else + { + print_uint128_t(os, static_cast<boost::uint128_type>(i)); + } + return os; +} + +std::ostream& operator<<(std::ostream& os, boost::uint128_type i) +{ + print_uint128_t(os, i); + return os; +} +#endif // BOOST_HAS_INT128 && BOOST_GEOMETRY_ENABLE_INT128 +#endif // BOOST_GEOMETRY_TEST_DEBUG + +namespace bg = boost::geometry; + +template +< + typename T, + bool Signed = boost::is_fundamental<T>::type::value + && ! boost::is_unsigned<T>::type::value +> +struct absolute_value +{ + static inline T apply(T const& t) + { + return t < 0 ? -t : t; + } +}; + +template <typename T> +struct absolute_value<T, false> +{ + static inline T apply(T const& t) + { + return t; + } +}; + + + +template +< + typename Integral, + typename Promoted, + bool Signed = ! boost::is_unsigned<Promoted>::type::value +> +struct test_max_values +{ + static inline void apply() + { + Promoted min_value = (std::numeric_limits<Integral>::min)(); + min_value *= min_value; + BOOST_CHECK(absolute_value<Promoted>::apply(min_value) == min_value); + Promoted max_value = (std::numeric_limits<Integral>::max)(); + max_value *= max_value; + BOOST_CHECK(absolute_value<Promoted>::apply(max_value) == max_value); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "integral min_value^2: " << min_value << std::endl; + std::cout << "promoted max_value: " + << (std::numeric_limits<Promoted>::max)() << std::endl; +#endif + } +}; + +template <typename Integral, typename Promoted> +struct test_max_values<Integral, Promoted, false> +{ + static inline void apply() + { + Promoted max_value = (std::numeric_limits<Integral>::max)(); + Promoted max_value_sqr = max_value * max_value; + BOOST_CHECK(max_value_sqr < (std::numeric_limits<Promoted>::max)() + && + max_value_sqr > max_value); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "integral max_value^2: " << max_value_sqr << std::endl; + std::cout << "promoted max_value: " + << (std::numeric_limits<Promoted>::max)() << std::endl; +#endif + } +}; + + +// helper function that returns the bit size of a type +template +< + typename T, + bool IsFundamental = boost::is_fundamental<T>::type::value +> +struct bit_size_impl : boost::mpl::size_t<0> +{}; + +template <typename T> +struct bit_size_impl<T, true> : bg::detail::promote_integral::bit_size<T>::type +{}; + +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) +template +< + typename Backend, + boost::multiprecision::expression_template_option ExpressionTemplates +> +struct bit_size_impl + < + boost::multiprecision::number<Backend, ExpressionTemplates>, + false + > : bg::detail::promote_integral::bit_size + < + boost::multiprecision::number<Backend, ExpressionTemplates> + > +{}; +#endif + + +template <typename T> +std::size_t bit_size() +{ + return bit_size_impl<T>::type::value; +} + +template <bool PromoteUnsignedToUnsigned> +struct test_promote_integral +{ + template <typename Type, typename ExpectedPromotedType> + static inline void apply(std::string const& case_id) + { + typedef typename bg::promote_integral + < + Type, PromoteUnsignedToUnsigned + >::type promoted_integral_type; + + bool const same_types = boost::is_same + < + promoted_integral_type, ExpectedPromotedType + >::type::value; + + BOOST_CHECK_MESSAGE(same_types, + "case ID: " << case_id + << "input type: " << typeid(Type).name() + << "; detected: " + << typeid(promoted_integral_type).name() + << "; expected: " + << typeid(ExpectedPromotedType).name()); + + if (BOOST_GEOMETRY_CONDITION((! boost::is_same + < + Type, promoted_integral_type + >::type::value))) + { + test_max_values<Type, promoted_integral_type>::apply(); + } + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "case ID: " << case_id << std::endl + << "type : " << typeid(Type).name() + << ", sizeof (bits): " << bit_size<Type>() + << ", min value: " + << (std::numeric_limits<Type>::min)() + << ", max value: " + << (std::numeric_limits<Type>::max)() + << std::endl; + std::cout << "detected promoted type : " + << typeid(promoted_integral_type).name() + << ", sizeof (bits): " << bit_size<promoted_integral_type>() + << ", min value: " + << (std::numeric_limits<promoted_integral_type>::min)() + << ", max value: " + << (std::numeric_limits<promoted_integral_type>::max)() + << std::endl; + std::cout << "expected promoted type : " + << typeid(ExpectedPromotedType).name() + << ", sizeof (bits): " << bit_size<ExpectedPromotedType>() + << ", min value: " + << (std::numeric_limits<ExpectedPromotedType>::min)() + << ", max value: " + << (std::numeric_limits<ExpectedPromotedType>::max)() + << std::endl; + std::cout << std::endl; +#endif + } +}; + +template +< + typename T, + bool PromoteUnsignedToUnsigned = false, + bool IsSigned = ! boost::is_unsigned<T>::type::value +> +struct test_promotion +{ + static inline void apply(std::string case_id) + { +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "*** " + << (IsSigned ? "signed" : "unsigned") + << " -> signed ***" << std::endl; +#endif + + typedef test_promote_integral<PromoteUnsignedToUnsigned> tester; + + case_id += (PromoteUnsignedToUnsigned ? "-t" : "-f"); + + std::size_t min_size = 2 * bit_size<T>() - 1; + if (BOOST_GEOMETRY_CONDITION(! IsSigned)) + { + min_size += 2; + } + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "min size: " << min_size << std::endl; +#endif + + if (bit_size<short>() >= min_size) + { + tester::template apply<T, short>(case_id); + } + else if (bit_size<int>() >= min_size) + { + tester::template apply<T, int>(case_id); + } + else if (bit_size<long>() >= min_size) + { + tester::template apply<T, long>(case_id); + } +#if defined(BOOST_HAS_LONG_LONG) + else if (bit_size<boost::long_long_type>() >= min_size) + { + tester::template apply<T, boost::long_long_type>(case_id); + } +#endif +#if defined(BOOST_HAS_INT128) && defined(BOOST_GEOMETRY_ENABLE_INT128) + else if (bit_size<boost::int128_type>() >= min_size) + { + tester::template apply<T, boost::int128_type>(case_id); + } +#endif + else + { +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) + namespace bm = boost::multiprecision; + typedef bm::number + < + bm::cpp_int_backend + < + 2 * CHAR_BIT * sizeof(T) + (IsSigned ? -1 : 1), + 2 * CHAR_BIT * sizeof(T) + (IsSigned ? -1 : 1), + bm::signed_magnitude, + bm::unchecked, + void + > + > multiprecision_integer_type; + + tester::template apply<T, multiprecision_integer_type>(case_id); +#else + tester::template apply<T, T>(case_id); +#endif + } + } +}; + +template <typename T> +struct test_promotion<T, true, false> +{ + static inline void apply(std::string case_id) + { +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "*** unsigned -> unsigned ***" << std::endl; +#endif + case_id += "-t"; + + typedef test_promote_integral<true> tester; + + std::size_t min_size = 2 * bit_size<T>(); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "min size: " << min_size << std::endl; +#endif + + if (bit_size<unsigned short>() >= min_size) + { + tester::apply<T, unsigned short>(case_id); + } + else if (bit_size<unsigned int>() >= min_size) + { + tester::apply<T, unsigned int>(case_id); + } + else if (bit_size<unsigned long>() >= min_size) + { + tester::apply<T, unsigned long>(case_id); + } + else if (bit_size<std::size_t>() >= min_size) + { + tester::apply<T, std::size_t>(case_id); + } +#if defined(BOOST_HAS_LONG_LONG) + else if (bit_size<boost::ulong_long_type>() >= min_size) + { + tester::template apply<T, boost::ulong_long_type>(case_id); + } +#endif +#if defined(BOOST_HAS_INT128) && defined(BOOST_GEOMETRY_ENABLE_INT128) + else if (bit_size<boost::uint128_type>() >= min_size) + { + tester::template apply<T, boost::uint128_type>(case_id); + } +#endif + else + { +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) + namespace bm = boost::multiprecision; + typedef bm::number + < + bm::cpp_int_backend + < + 2 * CHAR_BIT * sizeof(T), + 2 * CHAR_BIT * sizeof(T), + bm::unsigned_magnitude, + bm::unchecked, + void + > + > multiprecision_integer_type; + + tester::apply<T, multiprecision_integer_type>(case_id); +#else + tester::apply<T, T>(case_id); +#endif + } + } +}; + + + +BOOST_AUTO_TEST_CASE( test_char ) +{ + test_promotion<char>::apply("char"); + test_promotion<char, true>::apply("char"); + test_promotion<signed char>::apply("schar"); + test_promotion<signed char, true>::apply("schar"); + test_promotion<unsigned char>::apply("uchar"); + test_promotion<unsigned char, true>::apply("uchar"); +} + +BOOST_AUTO_TEST_CASE( test_short ) +{ + test_promotion<short>::apply("short"); + test_promotion<short, true>::apply("short"); + test_promotion<unsigned short>::apply("ushort"); + test_promotion<unsigned short, true>::apply("ushort"); +} + +BOOST_AUTO_TEST_CASE( test_int ) +{ + test_promotion<int>::apply("int"); + test_promotion<int, true>::apply("int"); + test_promotion<unsigned int>::apply("uint"); + test_promotion<unsigned int, true>::apply("uint"); +} + +BOOST_AUTO_TEST_CASE( test_long ) +{ + test_promotion<long>::apply("long"); + test_promotion<long, true>::apply("long"); + test_promotion<unsigned long>::apply("ulong"); + test_promotion<unsigned long, true>::apply("ulong"); +} + +BOOST_AUTO_TEST_CASE( test_std_size_t ) +{ + test_promotion<std::size_t>::apply("size_t"); + test_promotion<std::size_t, true>::apply("size_t"); +} + +#ifdef BOOST_HAS_LONG_LONG +BOOST_AUTO_TEST_CASE( test_long_long ) +{ + test_promotion<boost::long_long_type>::apply("long long"); + test_promotion<boost::long_long_type, true>::apply("long long"); + test_promotion<boost::ulong_long_type>::apply("ulong long"); + test_promotion<boost::ulong_long_type, true>::apply("ulong long"); +} +#endif + +#if defined(BOOST_HAS_INT128) && defined(BOOST_GEOMETRY_ENABLE_INT128) +BOOST_AUTO_TEST_CASE( test_int128 ) +{ + test_promotion<boost::int128_type>::apply("int128_t"); + test_promotion<boost::int128_type, true>::apply("int128_t"); + test_promotion<boost::uint128_type>::apply("uint128_t"); + test_promotion<boost::uint128_type, true>::apply("uint128_t"); +} +#endif + +#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER) +BOOST_AUTO_TEST_CASE( test_user_types ) +{ + namespace bm = boost::multiprecision; + typedef bm::number + < + bm::cpp_int_backend + < + 17, + 17, + bm::signed_magnitude, + bm::unchecked, + void + > + > user_signed_type1; + + typedef bm::number + < + bm::cpp_int_backend + < + 17, + 17, + bm::unsigned_magnitude, + bm::unchecked, + void + > + > user_unsigned_type1; + + typedef bm::number + < + bm::cpp_int_backend + < + 500, + 500, + bm::signed_magnitude, + bm::unchecked, + void + > + > user_signed_type2; + + typedef bm::number + < + bm::cpp_int_backend + < + 500, + 500, + bm::unsigned_magnitude, + bm::unchecked, + void + > + > user_unsigned_type2; + + // for user defined number types we do not do any promotion + typedef test_promote_integral<true> tester1; + typedef test_promote_integral<false> tester2; + tester1::apply<user_signed_type1, user_signed_type1>("u1s"); + tester1::apply<user_signed_type2, user_signed_type2>("u2s"); + tester1::apply<user_unsigned_type1, user_unsigned_type1>("u1u"); + tester1::apply<user_unsigned_type2, user_unsigned_type2>("u2u"); + + tester2::apply<user_signed_type1, user_signed_type1>("u1s"); + tester2::apply<user_signed_type2, user_signed_type2>("u2s"); + tester2::apply<user_unsigned_type1, user_unsigned_type1>("u1u"); + tester2::apply<user_unsigned_type2, user_unsigned_type2>("u1u"); +} +#endif + +BOOST_AUTO_TEST_CASE( test_floating_point ) +{ + typedef test_promote_integral<true> tester1; + typedef test_promote_integral<false> tester2; + + // for floating-point types we do not do any promotion + tester1::apply<float, float>("fp-f"); + tester1::apply<double, double>("fp-d"); + tester1::apply<long double, long double>("fp-ld"); + + tester2::apply<float, float>("fp-f"); + tester2::apply<double, double>("fp-d"); + tester2::apply<long double, long double>("fp-ld"); + +#ifdef HAVE_TTMATH + tester1::apply<ttmath_big, ttmath_big>("fp-tt"); + tester2::apply<ttmath_big, ttmath_big>("fp-tt"); +#endif +} diff --git a/src/boost/libs/geometry/test/util/range.cpp b/src/boost/libs/geometry/test/util/range.cpp new file mode 100644 index 00000000..56cfdfb1 --- /dev/null +++ b/src/boost/libs/geometry/test/util/range.cpp @@ -0,0 +1,244 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2014-2015 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <iterator> +#include <vector> + +#include <boost/range/iterator_range.hpp> + +#include <boost/geometry/util/range.hpp> + +namespace bgt { + +template <bool MutableIterator> +struct beginner +{ + template <typename Range> + typename boost::range_iterator<Range>::type + operator()(Range & rng) + { + return boost::begin(rng); + } +}; +template <> +struct beginner<false> +{ + template <typename Range> + typename boost::range_iterator<Range const>::type + operator()(Range & rng) + { + return boost::const_begin(rng); + } +}; + +template <bool MutableIterator> +struct ender +{ + template <typename Range> + typename boost::range_iterator<Range>::type + operator()(Range & rng) + { + return boost::end(rng); + } +}; +template <> +struct ender<false> +{ + template <typename Range> + typename boost::range_iterator<Range const>::type + operator()(Range & rng) + { + return boost::const_end(rng); + } +}; + +struct NonMovable +{ + NonMovable(int ii = 0) : i(ii) {} + NonMovable(NonMovable const& ii) : i(ii.i) {} + NonMovable & operator=(NonMovable const& ii) { i = ii.i; return *this; } + bool operator==(NonMovable const& ii) const { return i == ii.i; } + int i; +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +private: + NonMovable(NonMovable && ii); + NonMovable & operator=(NonMovable && ii); +#endif +}; + +struct CopyableAndMovable +{ + CopyableAndMovable(int ii = 0) : i(ii) {} + CopyableAndMovable(CopyableAndMovable const& ii) : i(ii.i) {} + CopyableAndMovable & operator=(CopyableAndMovable const& ii) { i = ii.i; return *this; } + bool operator==(CopyableAndMovable const& ii) const { return i == ii.i; } + int i; +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + CopyableAndMovable(CopyableAndMovable && ii) : i(std::move(ii.i)) {} + CopyableAndMovable & operator=(CopyableAndMovable && ii) { i = std::move(ii.i); return *this; } +#endif +}; + +} // namespace bgt + +namespace bgr = bg::range; + +template <typename T, bool MutableIterator> +void test_all() +{ + bgt::beginner<MutableIterator> begin; + bgt::ender<MutableIterator> end; + + std::vector<T> v; + for (int i = 0 ; i < 20 ; ++i) + { + bgr::push_back(v, i); + } + + for (int i = 0 ; i < 20 ; ++i) + { + BOOST_CHECK(bgr::at(v, i) == i); + } + + { + std::vector<T> w; + std::copy(v.begin(), v.end(), bgr::back_inserter(w)); + BOOST_CHECK(v.size() == w.size() && std::equal(v.begin(), v.end(), w.begin())); + } + + BOOST_CHECK(bgr::front(v) == 0); + BOOST_CHECK(bgr::back(v) == 19); + + BOOST_CHECK(boost::size(v) == 20); // [0,19] + bgr::resize(v, 15); + BOOST_CHECK(boost::size(v) == 15); // [0,14] + BOOST_CHECK(bgr::back(v) == 14); + + bgr::pop_back(v); + BOOST_CHECK(boost::size(v) == 14); // [0,13] + BOOST_CHECK(bgr::back(v) == 13); + + typename std::vector<T>::iterator + it = bgr::erase(v, end(v) - 1); + BOOST_CHECK(boost::size(v) == 13); // [0,12] + BOOST_CHECK(bgr::back(v) == 12); + BOOST_CHECK(it == end(v)); + + it = bgr::erase(v, end(v) - 3, end(v)); + BOOST_CHECK(boost::size(v) == 10); // [0,9] + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == end(v)); + + it = bgr::erase(v, begin(v) + 2); + BOOST_CHECK(boost::size(v) == 9); // {0,1,3..9} + BOOST_CHECK(bgr::at(v, 1) == 1); + BOOST_CHECK(bgr::at(v, 2) == 3); + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == bgr::pos(v, 2)); + + it = bgr::erase(v, begin(v) + 2, begin(v) + 2); + BOOST_CHECK(boost::size(v) == 9); // {0,1,3..9} + BOOST_CHECK(bgr::at(v, 1) == 1); + BOOST_CHECK(bgr::at(v, 2) == 3); + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == bgr::pos(v, 2)); + + it = bgr::erase(v, begin(v) + 2, begin(v) + 5); + BOOST_CHECK(boost::size(v) == 6); // {0,1,6..9} + BOOST_CHECK(bgr::at(v, 1) == 1); + BOOST_CHECK(bgr::at(v, 2) == 6); + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == bgr::pos(v, 2)); + + it = bgr::erase(v, begin(v)); + BOOST_CHECK(boost::size(v) == 5); // {1,6..9} + BOOST_CHECK(bgr::at(v, 0) == 1); + BOOST_CHECK(bgr::at(v, 1) == 6); + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == bgr::pos(v, 0)); + + it = bgr::erase(v, begin(v), begin(v) + 3); + BOOST_CHECK(boost::size(v) == 2); // {8,9} + BOOST_CHECK(bgr::at(v, 0) == 8); + BOOST_CHECK(bgr::at(v, 1) == 9); + BOOST_CHECK(bgr::back(v) == 9); + BOOST_CHECK(it == bgr::pos(v, 0)); + + it = bgr::erase(v, begin(v), end(v)); + BOOST_CHECK(boost::size(v) == 0); + BOOST_CHECK(it == end(v)); +} + +void test_detail() +{ + int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + bgr::detail::copy_or_move(arr + 1, arr + 10, arr); + BOOST_CHECK(arr[0] == 1); + + std::vector<int> v(10, 0); + bgr::detail::copy_or_move(v.begin() + 1, v.begin() + 10, v.begin()); + BOOST_CHECK(boost::size(v) == 10); + bgr::erase(v, v.begin() + 1); + BOOST_CHECK(boost::size(v) == 9); + + bgt::NonMovable * arr2[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + bgt::NonMovable foo; + arr2[1] = &foo; + bgr::detail::copy_or_move(arr2 + 1, arr2 + 10, arr2); + BOOST_CHECK(arr2[0] == &foo); + + // Storing pointers in a std::vector is not possible in MinGW C++98 +#if __cplusplus >= 201103L + std::vector<bgt::NonMovable*> v2(10, (bgt::NonMovable*)NULL); + bgr::detail::copy_or_move(v2.begin() + 1, v2.begin() + 10, v2.begin()); + BOOST_CHECK(boost::size(v2) == 10); + bgr::erase(v2, v2.begin() + 1); + BOOST_CHECK(boost::size(v2) == 9); +#endif +} + +template <class Iterator> +void test_pointers() +{ + int arr[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + boost::iterator_range<Iterator> r1(arr, arr + 10); + std::pair<Iterator, Iterator> r2(arr, arr + 10); + + BOOST_CHECK(bgr::front(r1) == 0); + BOOST_CHECK(bgr::front(r2) == 0); + BOOST_CHECK(bgr::back(r1) == 9); + BOOST_CHECK(bgr::back(r2) == 9); + BOOST_CHECK(bgr::at(r1, 5) == 5); + BOOST_CHECK(bgr::at(r2, 5) == 5); +} + +int test_main(int, char* []) +{ + test_all<int, true>(); + test_all<int, false>(); + // Storing non-movable elements in a std::vector is not possible in some implementations of STD lib +#ifdef BOOST_GEOMETRY_TEST_NONMOVABLE_ELEMENTS + test_all<bgt::NonMovable, true>(); + test_all<bgt::NonMovable, false>(); +#endif + test_all<bgt::CopyableAndMovable, true>(); + test_all<bgt::CopyableAndMovable, false>(); + + test_detail(); + test_pointers<int*>(); + test_pointers<int const*>(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/rational.cpp b/src/boost/libs/geometry/test/util/rational.cpp new file mode 100644 index 00000000..8ec47eb9 --- /dev/null +++ b/src/boost/libs/geometry/test/util/rational.cpp @@ -0,0 +1,61 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/io/wkt/wkt.hpp> +#include <boost/geometry/util/rational.hpp> + +void test_coordinate_cast(std::string const& s, int expected_nom, int expected_denom) +{ + boost::rational<int> a = bg::detail::coordinate_cast<boost::rational<int> >::apply(s); + BOOST_CHECK_EQUAL(a.numerator(), expected_nom); + BOOST_CHECK_EQUAL(a.denominator(), expected_denom); +} + + +void test_wkt(std::string const& wkt, std::string const expected_wkt) +{ + bg::model::point<boost::rational<int>, 2, bg::cs::cartesian> p; + bg::read_wkt(wkt, p); + std::ostringstream out; + out << bg::wkt(p); + + BOOST_CHECK_EQUAL(out.str(), expected_wkt); +} + +int test_main(int, char* []) +{ + test_coordinate_cast("0", 0, 1); + test_coordinate_cast("1", 1, 1); + test_coordinate_cast("-1", -1, 1); + test_coordinate_cast("-0.5", -1, 2); + test_coordinate_cast("-1.5", -3, 2); + test_coordinate_cast("0.5", 1, 2); + test_coordinate_cast("1.5", 3, 2); + test_coordinate_cast("2.12345", 42469, 20000); + test_coordinate_cast("1.", 1, 1); + + test_coordinate_cast("3/2", 3, 2); + test_coordinate_cast("-3/2", -3, 2); + + test_wkt("POINT(1.5 2.75)", "POINT(3/2 11/4)"); + test_wkt("POINT(3/2 11/4)", "POINT(3/2 11/4)"); + test_wkt("POINT(-1.5 2.75)", "POINT(-3/2 11/4)"); + test_wkt("POINT(-3/2 11/4)", "POINT(-3/2 11/4)"); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/select_most_precise.cpp b/src/boost/libs/geometry/test/util/select_most_precise.cpp new file mode 100644 index 00000000..3ec2dec7 --- /dev/null +++ b/src/boost/libs/geometry/test/util/select_most_precise.cpp @@ -0,0 +1,78 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <geometry_test_common.hpp> + +#include <boost/geometry/util/select_most_precise.hpp> + + +struct user_defined {}; + +template <typename T1, typename T2, typename ExpectedType> +void test() +{ + typedef typename bg::select_most_precise<T1, T2>::type type; + bool is_same = boost::is_same<type, ExpectedType>::type::value; + + BOOST_CHECK_MESSAGE(is_same, + "The most precise of types " << + "T1: {" << typeid(T1).name() << " | s: " << sizeof(T1) << "}" << + " and " << + "T2: {" << typeid(T2).name() << " | s: " << sizeof(T2) << "}" << + " does not match " << + "ExpectedType: {" << typeid(ExpectedType).name() << " | s: " << sizeof(ExpectedType) << "}"); +} + +int test_main(int, char* []) +{ + // fp only + test<float, float, float>(); + test<float, double, double>(); + test<double, float, double>(); + test<double, double, double>(); + + // integer only + test<int, int, int>(); + test<int, short int, int>(); + test<short int, int, int>(); + test<short int, short int, short int>(); + + // int/fp + test<double, int, double>(); + test<int, double, double>(); + test<long double, long double, long double>(); + test<float, int, float>(); + test<int, float, float>(); + + if ( sizeof(long double) > sizeof(double) ) + { + // This cannot be done for MSVC because double/long double is the same + // This is also true for Android + test<double, long double, long double>(); + test<long double, double, long double>(); + } + + // with any other non-integer/float class + test<int, user_defined, user_defined>(); + test<user_defined, int, user_defined>(); + test<long double, user_defined, user_defined>(); + test<user_defined, long double, user_defined>(); + test<user_defined, user_defined, user_defined>(); + + // should not compile + //test<void, void, void>(); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/transform_variant.cpp b/src/boost/libs/geometry/test/util/transform_variant.cpp new file mode 100644 index 00000000..4594e591 --- /dev/null +++ b/src/boost/libs/geometry/test/util/transform_variant.cpp @@ -0,0 +1,68 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <boost/test/included/test_exec_monitor.hpp> +#include <boost/geometry/util/transform_variant.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/type_traits.hpp> +#include <boost/variant/variant.hpp> + +using boost::mpl::placeholders::_; + + +template <typename ExpectedTypes, BOOST_VARIANT_ENUM_PARAMS(typename T)> +void check(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>) +{ + BOOST_MPL_ASSERT(( + boost::mpl::equal< + typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types, + ExpectedTypes + > + )); +} + + +int test_main(int, char* []) +{ + // Transform Variant to Variant + typedef boost::geometry::transform_variant< + boost::variant<int, float, long>, + boost::add_pointer<_> + >::type transformed1; + + check<boost::mpl::vector<int*, float*, long*> >(transformed1()); + + // Transform Sequence to Variant (without inserter) + typedef boost::geometry::transform_variant< + boost::mpl::vector<int, float, long>, + boost::add_pointer<_> + >::type transformed2; + + check<boost::mpl::vector<int*, float*, long*> >(transformed2()); + + // Transform Sequence to Variant (with inserter) + typedef boost::geometry::transform_variant< + boost::mpl::vector<int, float, long>, + boost::add_pointer<_>, + boost::mpl::back_inserter<boost::mpl::vector0<> > + >::type transformed3; + + check<boost::mpl::vector<int*, float*, long*> >(transformed3()); + + return 0; +} diff --git a/src/boost/libs/geometry/test/util/write_dsv.cpp b/src/boost/libs/geometry/test/util/write_dsv.cpp new file mode 100644 index 00000000..ebb70636 --- /dev/null +++ b/src/boost/libs/geometry/test/util/write_dsv.cpp @@ -0,0 +1,73 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to 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 <sstream> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/io/dsv/write.hpp> + + +#include <boost/geometry/geometries/geometries.hpp> + +#include <boost/geometry/io/wkt/read.hpp> + + + +template <typename G> +void test_dsv(std::string const& wkt, std::string const& dsv) +{ + G geometry; + + bg::read_wkt(wkt, geometry); + + std::ostringstream out; + out << bg::dsv(geometry); + BOOST_CHECK_EQUAL(out.str(), dsv); +} + + +#ifndef GEOMETRY_TEST_MULTI +template <typename T> +void test_all() +{ + using namespace boost::geometry; + typedef model::point<T, 2, cs::cartesian> P; + + test_dsv<P >("POINT(1 2)", "(1, 2)"); + test_dsv<model::linestring<P> >( + "LINESTRING(1 1,2 2,3 3)", + "((1, 1), (2, 2), (3, 3))"); + test_dsv<model::polygon<P> >("POLYGON((0 0,0 4,4 4,4 0,0 0))", + "(((0, 0), (0, 4), (4, 4), (4, 0), (0, 0)))"); + + test_dsv<model::ring<P> >("POLYGON((0 0,0 4,4 4,4 0,0 0))", + "((0, 0), (0, 4), (4, 4), (4, 0), (0, 0))"); + + test_dsv<model::box<P> >("BOX(0 0,1 1)", + "((0, 0), (1, 1))"); +} +#endif + + +int test_main(int, char* []) +{ + test_all<double>(); + test_all<int>(); + + + return 0; +} + |