29#include "DGtal/base/BasicTypes.h"
30#include "DGtal/kernel/NumberTraits.h"
32#include "DGtalCatch.h"
36struct IntegralCstToTag
42struct IntegralCstToTag<
std::true_type>
48struct IntegralCstToTag<
std::false_type>
61struct ValueToTag<true>
67struct ValueToTag<false>
72#define REQUIRE_SAME_TAG(a, b) REQUIRE( (std::is_same<a, typename IntegralCstToTag<b>::type>::value) )
73#define REQUIRE_SAME_VALUE(a, b) REQUIRE( (std::is_same<a, typename ValueToTag<b>::type>::value) )
74#define REQUIRE_SAME_TYPE(a, b) REQUIRE( (std::is_same<a, b>::value) )
78void checkParamRef(T
const&)
84void checkFundamentalType()
87 using NL =
typename std::numeric_limits<T>;
89 REQUIRE_SAME_VALUE(
typename NT::IsBounded, NL::is_bounded );
90 REQUIRE_SAME_VALUE(
typename NT::IsSigned, NL::is_signed );
91 REQUIRE_SAME_VALUE(
typename NT::IsUnsigned, ! NL::is_signed );
92 REQUIRE_SAME_VALUE(
typename NT::IsIntegral, NL::is_integer );
93 REQUIRE_SAME_VALUE(
typename NT::IsSpecialized,
true );
94 REQUIRE_SAME_TYPE(
typename NT::ReturnType, T );
95 REQUIRE_SAME_TYPE(
typename std::decay<typename NT::ParamType>::type, T );
103 REQUIRE( NT::min() == NL::min() );
104 REQUIRE( NT::max() == NL::max() );
105 REQUIRE( NT::digits() == NL::digits );
109 REQUIRE( NT::castToInt64_t(T(3.25)) == 3 );
110 REQUIRE( NT::castToDouble(T(3.25)) == (NL::is_integer ? 3. : 3.25) );
112 checkParamRef(NT::ZERO);
113 checkParamRef(NT::ONE);
118void checkFundamentalIntegerType()
120 checkFundamentalType<T>();
124 REQUIRE_SAME_TYPE(
typename NT::SignedVersion,
typename std::make_signed<T>::type );
125 REQUIRE_SAME_TYPE(
typename NT::UnsignedVersion,
typename std::make_unsigned<T>::type );
127 REQUIRE( NT::even(T(42)) ==
true );
128 REQUIRE( NT::even(T(43)) ==
false );
129 REQUIRE( NT::odd(T(42)) ==
false );
130 REQUIRE( NT::odd(T(43)) ==
true );
135void checkFundamentalFloatType()
137 checkFundamentalType<T>();
140#define TEST_TYPE_TRAITS( test, a ) TEST_CASE( #a ) { test<a>(); }
141#define TEST_FUNDAMENTAL_INTEGER_TYPE( a ) TEST_TYPE_TRAITS( checkFundamentalIntegerType, a )
142#define TEST_FUNDAMENTAL_FLOAT_TYPE( a ) TEST_TYPE_TRAITS( checkFundamentalFloatType, a )
144TEST_FUNDAMENTAL_INTEGER_TYPE(
signed char )
145TEST_FUNDAMENTAL_INTEGER_TYPE(
unsigned char )
146TEST_FUNDAMENTAL_INTEGER_TYPE(
signed short )
147TEST_FUNDAMENTAL_INTEGER_TYPE(
unsigned short )
148TEST_FUNDAMENTAL_INTEGER_TYPE(
signed int )
149TEST_FUNDAMENTAL_INTEGER_TYPE(
unsigned int )
150TEST_FUNDAMENTAL_INTEGER_TYPE(
signed long int )
151TEST_FUNDAMENTAL_INTEGER_TYPE(
unsigned long int )
152TEST_FUNDAMENTAL_INTEGER_TYPE(
signed long long int )
153TEST_FUNDAMENTAL_INTEGER_TYPE(
unsigned long long int )
155TEST_FUNDAMENTAL_INTEGER_TYPE( int8_t )
156TEST_FUNDAMENTAL_INTEGER_TYPE( uint8_t )
157TEST_FUNDAMENTAL_INTEGER_TYPE( int16_t )
158TEST_FUNDAMENTAL_INTEGER_TYPE( uint16_t )
159TEST_FUNDAMENTAL_INTEGER_TYPE( int32_t )
160TEST_FUNDAMENTAL_INTEGER_TYPE( uint32_t )
161TEST_FUNDAMENTAL_INTEGER_TYPE( int64_t )
162TEST_FUNDAMENTAL_INTEGER_TYPE( uint64_t )
164TEST_FUNDAMENTAL_FLOAT_TYPE(
float )
165TEST_FUNDAMENTAL_FLOAT_TYPE(
double )
166TEST_FUNDAMENTAL_FLOAT_TYPE(
long double )
168#ifdef WITH_BIGINTEGER
176 REQUIRE_SAME_VALUE(
typename NT::IsBounded,
false );
177 REQUIRE_SAME_VALUE(
typename NT::IsSigned,
true );
178 REQUIRE_SAME_VALUE(
typename NT::IsUnsigned,
true );
179 REQUIRE_SAME_VALUE(
typename NT::IsIntegral,
true );
180 REQUIRE_SAME_VALUE(
typename NT::IsSpecialized,
true );
182 REQUIRE_SAME_TYPE(
typename NT::ReturnType, T );
183 REQUIRE_SAME_TYPE(
typename std::decay<NT::ParamType>::type, T );
188 REQUIRE( NT::even(T(42)) ==
true );
189 REQUIRE( NT::even(T(43)) ==
false );
190 REQUIRE( NT::odd(T(42)) ==
false );
191 REQUIRE( NT::odd(T(43)) ==
true );
196 REQUIRE( NT::castToInt64_t(T(3.25)) == 3 );
197 REQUIRE( NT::castToDouble(T(3.25)) == 3. );
199 checkParamRef(NT::ZERO);
200 checkParamRef(NT::ONE);
DGtal is the top-level namespace which contains all DGtal functions and types.
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Aim: The traits class for all models of Cinteger.
TEST_CASE("int container traits", "[int][traits]")
REQUIRE(domain.isInside(aPoint))