mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
[test][util][promote integral] add unit test for the promote_integral meta-function
This commit is contained in:
parent
abbb664226
commit
b87c59375a
@ -1,11 +1,11 @@
|
||||
# Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
#
|
||||
# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
# Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
||||
# Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
||||
# 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.
|
||||
# Modifications copyright (c) 2014, Oracle and/or its affiliates.
|
||||
# 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
|
||||
#
|
||||
@ -18,6 +18,7 @@ test-suite boost-geometry-util
|
||||
[ run calculation_type.cpp ]
|
||||
[ run for_each_coordinate.cpp ]
|
||||
[ run math_sqrt.cpp ]
|
||||
[ run promote_integral.cpp ]
|
||||
[ run range.cpp ]
|
||||
[ run rational.cpp ]
|
||||
[ run select_most_precise.cpp ]
|
||||
|
206
test/util/promote_integral.cpp
Normal file
206
test/util/promote_integral.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
// 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
|
||||
|
||||
#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER)
|
||||
#include <climits>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
//#include <boost/config.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <geometry_test_common.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) && defined(BOOST_HAS_INT128)
|
||||
std::ostream& operator<<(std::ostream& os, boost::int128_type i)
|
||||
{
|
||||
os << double(i);
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace bg = boost::geometry;
|
||||
|
||||
template <typename Type, typename ExpectedPromotedType>
|
||||
inline void test_promote_integral()
|
||||
{
|
||||
typedef typename bg::promote_integral<Type>::type promoted_integral_type;
|
||||
bool const same_types = boost::is_same
|
||||
<
|
||||
promoted_integral_type, ExpectedPromotedType
|
||||
>::type::value;
|
||||
|
||||
BOOST_CHECK(same_types);
|
||||
|
||||
#ifdef BOOST_GEOMETRY_TEST_DEBUG
|
||||
std::cout << "type : " << typeid(Type).name()
|
||||
<< ", sizeof: " << sizeof(Type)
|
||||
<< ", max value: "
|
||||
<< std::numeric_limits<Type>::max()
|
||||
<< std::endl;
|
||||
std::cout << "detected promoted type : "
|
||||
<< typeid(promoted_integral_type).name()
|
||||
<< ", sizeof: " << sizeof(promoted_integral_type)
|
||||
<< ", max value: "
|
||||
<< std::numeric_limits<promoted_integral_type>::max()
|
||||
<< std::endl;
|
||||
std::cout << "expected promoted type : "
|
||||
<< typeid(ExpectedPromotedType).name()
|
||||
<< ", sizeof: " << sizeof(ExpectedPromotedType)
|
||||
<< ", max value: "
|
||||
<< std::numeric_limits<ExpectedPromotedType>::max()
|
||||
<< std::endl;
|
||||
std::cout << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_promotion()
|
||||
{
|
||||
if (sizeof(short) >= 2 * sizeof(T))
|
||||
{
|
||||
test_promote_integral<T, short>();
|
||||
}
|
||||
else if (sizeof(int) >= 2 * sizeof(T))
|
||||
{
|
||||
test_promote_integral<T, int>();
|
||||
}
|
||||
else if (sizeof(long) >= 2 * sizeof(T))
|
||||
{
|
||||
test_promote_integral<T, long>();
|
||||
}
|
||||
#if defined(BOOST_HAS_LONG_LONG)
|
||||
else if (sizeof(boost::long_long_type) >= 2 * sizeof(T))
|
||||
{
|
||||
test_promote_integral<T, boost::long_long_type>();
|
||||
}
|
||||
#endif
|
||||
#if defined(BOOST_HAS_INT128)
|
||||
else if (sizeof(boost::int128_type) >= 2 * sizeof(T))
|
||||
{
|
||||
test_promote_integral<T, boost::int128_type>();
|
||||
}
|
||||
#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::signed_magnitude,
|
||||
bm::unchecked,
|
||||
void
|
||||
>
|
||||
> multiprecision_integer_type;
|
||||
|
||||
test_promote_integral<T, multiprecision_integer_type>();
|
||||
#else
|
||||
test_promote_integral<T, T>();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_char )
|
||||
{
|
||||
test_promotion<char>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_short )
|
||||
{
|
||||
test_promotion<short>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_int )
|
||||
{
|
||||
test_promotion<int>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_long )
|
||||
{
|
||||
test_promotion<long>();
|
||||
}
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
BOOST_AUTO_TEST_CASE( test_long_long )
|
||||
{
|
||||
test_promotion<boost::long_long_type>();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_INT128)
|
||||
BOOST_AUTO_TEST_CASE( test_int128 )
|
||||
{
|
||||
test_promotion<boost::int128_type>();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_GEOMETRY_NO_MULTIPRECISION_INTEGER)
|
||||
BOOST_AUTO_TEST_CASE( test_custom_types )
|
||||
{
|
||||
namespace bm = boost::multiprecision;
|
||||
typedef bm::number
|
||||
<
|
||||
bm::cpp_int_backend
|
||||
<
|
||||
CHAR_BIT * sizeof(short) + 1,
|
||||
CHAR_BIT * sizeof(short) + 1,
|
||||
bm::signed_magnitude,
|
||||
bm::unchecked,
|
||||
void
|
||||
>
|
||||
> custom_integral_type1;
|
||||
|
||||
typedef bm::number
|
||||
<
|
||||
bm::cpp_int_backend
|
||||
<
|
||||
500,
|
||||
500,
|
||||
bm::signed_magnitude,
|
||||
bm::unchecked,
|
||||
void
|
||||
>
|
||||
> custom_integral_type2;
|
||||
|
||||
// for user defined number types we do not do any promotion
|
||||
test_promote_integral<custom_integral_type1, custom_integral_type1>();
|
||||
test_promote_integral<custom_integral_type2, custom_integral_type2>();
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_floating_point )
|
||||
{
|
||||
// for floating-point types we do not do any promotion
|
||||
test_promote_integral<float, float>();
|
||||
test_promote_integral<double, double>();
|
||||
test_promote_integral<long double, long double>();
|
||||
|
||||
#ifdef HAVE_TTMATH
|
||||
test_promote_integral<ttmath_big, ttmath_big>();
|
||||
#endif
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user