Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testIntegerConverter.cpp
Go to the documentation of this file.
1
16
29
31#include <iostream>
32#include "DGtal/kernel/PointVector.h"
33#include "DGtal/kernel/IntegerConverter.h"
34#include "DGtalCatch.h"
36
37using namespace std;
38using namespace DGtal;
39
40
42// Functions for testing class IntegerConverter.
44
45SCENARIO( "Integer types sizes", "[integer_conversions]" )
46{
47 WHEN( "Checking integral types" ) {
48 THEN( "Integral types are progressive" ) {
49 CAPTURE( sizeof( int ) );
50 CAPTURE( sizeof( long ) );
51 CAPTURE( sizeof( long long ) );
52 REQUIRE( sizeof( int ) == 4 );
53 REQUIRE( sizeof( int ) <= sizeof( long ) );
54 REQUIRE( sizeof( long ) <= sizeof( long long ) );
55 REQUIRE( sizeof( long long ) == 8 );
56 }
57 }
58}
59SCENARIO( "IntegerConverter< 1, int32 >", "[integer_conversions]" )
60{
62 DGtal::int32_t small_int32 = 0x12345678;
63 DGtal::int64_t small_int64 = 0x12345678L;
64 DGtal::BigInteger small_bigint = 0x12345678;
65 WHEN( "Converting small integers" ) {
66 DGtal::int32_t a = Converter::cast( small_int32 );
67 DGtal::int32_t b = Converter::cast( small_int64 );
68 DGtal::int32_t c = Converter::cast( small_bigint );
69 THEN( "Their values are all identical" ) {
70 REQUIRE( a == small_int32 );
71 REQUIRE( a == b );
72 REQUIRE( a == c );
73 }
74 }
75 WHEN( "Converting medium integers" ) {
76 DGtal::int64_t medium_int64 = 0x123456789ABCDEFL;
77 DGtal::int32_t a = Converter::cast( medium_int64 );
78 THEN( "The value is lost with a warning" ) {
79 REQUIRE( DGtal::int64_t( a ) != medium_int64 );
80 }
81 }
82}
83
84SCENARIO( "IntegerConverter< 1, int64 >", "[integer_conversions]" )
85{
87 DGtal::int32_t medium_int32 = DGtal::int32_t( 0x123456789ABCDEFL );
88 DGtal::int64_t medium_int64 = 0x123456789ABCDEFL;
89 DGtal::BigInteger medium_bigint = 0x123456789ABCDEFL;
90 WHEN( "Converting 64bits integers" ) {
91 DGtal::int64_t a = Converter::cast( medium_int32 );
92 DGtal::int64_t b = Converter::cast( medium_int64 );
93 DGtal::int64_t c = Converter::cast( medium_bigint );
94 THEN( "Only bigger integers are identical" ) {
95 REQUIRE( a == medium_int32 );
96 REQUIRE( a != b );
97 REQUIRE( b == medium_int64 );
98 REQUIRE( b == c );
99 }
100 THEN( "It gives the same results with NumberTraits" ) {
104 REQUIRE( a == ap );
105 REQUIRE( b == bp );
106 REQUIRE( c == cp );
107 }
108 }
109}
110
111
112SCENARIO( "IntegerConverter< 1, BigInteger >", "[integer_conversions]" )
113{
115 DGtal::int32_t big_int32 = DGtal::int32_t( 0x123456789ABCDEFL );
116 DGtal::int64_t big_int64 = 0x123456789ABCDEFL;
117 DGtal::BigInteger big_bigint = 0x123456789ABCDEFL;
118 big_int32 *= big_int32;
119 big_int64 *= big_int64;
120 big_bigint *= big_bigint;
121 WHEN( "Converting big integers" ) {
122 DGtal::BigInteger a = Converter::cast( big_int32 );
123 DGtal::BigInteger b = Converter::cast( big_int64 );
124 DGtal::BigInteger c = Converter::cast( big_bigint );
125 DGtal::BigInteger b_prime = big_int64;
126
127 THEN( "Only bigger integers are identical" ) {
128 REQUIRE( a == big_int32 );
129 REQUIRE( a != b );
130 REQUIRE( b == b_prime );
131 REQUIRE( b != c );
132 REQUIRE( c == big_bigint );
133 }
134 }
135}
DGtal is the top-level namespace which contains all DGtal functions and types.
std::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:71
std::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:73
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
STL namespace.
----------— INTEGER/POINT CONVERSION SERVICES -----------------—
Aim: The traits class for all models of Cinteger.
CAPTURE(thicknessHV)
REQUIRE(domain.isInside(aPoint))
SCENARIO("UnorderedSetByBlock< PointVector< 2, int > unit tests with 32 bits blocks", "[unorderedsetbyblock][2d]")