DGtal 1.4.0
Loading...
Searching...
No Matches
testIntegerConverter.cpp File Reference
#include <iostream>
#include "DGtal/kernel/PointVector.h"
#include "DGtal/kernel/IntegerConverter.h"
#include "DGtalCatch.h"
Include dependency graph for testIntegerConverter.cpp:

Go to the source code of this file.

Functions

 SCENARIO ("Integer types sizes", "[integer_conversions]")
 
 SCENARIO ("IntegerConverter< 1, int32 >", "[integer_conversions]")
 
 SCENARIO ("IntegerConverter< 1, int64 >", "[integer_conversions]")
 
 SCENARIO ("IntegerConverter< 1, BigInteger >", "[integer_conversions]")
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2021/04/10

Functions for testing class IntegerConverter.

This file is part of the DGtal library.

Definition in file testIntegerConverter.cpp.

Function Documentation

◆ SCENARIO() [1/4]

SCENARIO ( "Integer types sizes" ,
"" [integer_conversions] )

Definition at line 45 of file testIntegerConverter.cpp.

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}
CAPTURE(thicknessHV)
REQUIRE(domain.isInside(aPoint))

References CAPTURE(), and REQUIRE().

◆ SCENARIO() [2/4]

SCENARIO ( "IntegerConverter< 1, BigInteger >" ,
"" [integer_conversions] )

Definition at line 129 of file testIntegerConverter.cpp.

130{
132 DGtal::int32_t big_int32 = DGtal::int32_t( 0x123456789ABCDEFL );
133 DGtal::int64_t big_int64 = 0x123456789ABCDEFL;
134 DGtal::BigInteger big_bigint = 0x123456789ABCDEFL;
135 big_int32 *= big_int32;
136 big_int64 *= big_int64;
137 big_bigint *= big_bigint;
138 WHEN( "Converting big integers" ) {
139 DGtal::BigInteger a = Converter::cast( big_int32 );
140 DGtal::BigInteger b = Converter::cast( big_int64 );
141 DGtal::BigInteger c = Converter::cast( big_bigint );
142 DGtal::BigInteger b_prime;
143 detail::mpz_set_sll( b_prime.get_mpz_t(), big_int64 );
144 THEN( "Only bigger integers are identical" ) {
145 REQUIRE( a == big_int32 );
146 REQUIRE( a != b );
147 REQUIRE( b == b_prime );
148 REQUIRE( b != c );
149 REQUIRE( c == big_bigint );
150 }
151 }
152}
static void mpz_set_sll(mpz_t n, long long sll)
----------— GMP SPECIALIZED SERVICES -------------------------—
boost::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:74
boost::int32_t int32_t
signed 32-bit integer.
Definition BasicTypes.h:72
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition BasicTypes.h:79
----------— INTEGER/POINT CONVERSION SERVICES -----------------—

References DGtal::detail::mpz_set_sll(), and REQUIRE().

◆ SCENARIO() [3/4]

SCENARIO ( "IntegerConverter< 1, int32 >" ,
"" [integer_conversions] )

Definition at line 59 of file testIntegerConverter.cpp.

60{
62 DGtal::int32_t small_int32 = 0x12345678;
63 DGtal::int64_t small_int64 = 0x12345678L;
64#ifdef WITH_BIGINTEGER
65 DGtal::BigInteger small_bigint = 0x12345678;
66#endif
67 WHEN( "Converting small integers" ) {
68 DGtal::int32_t a = Converter::cast( small_int32 );
69 DGtal::int32_t b = Converter::cast( small_int64 );
70#ifdef WITH_BIGINTEGER
71 DGtal::int32_t c = Converter::cast( small_bigint );
72#endif
73 THEN( "Their values are all identical" ) {
74 REQUIRE( a == small_int32 );
75 REQUIRE( a == b );
76#ifdef WITH_BIGINTEGER
77 REQUIRE( a == c );
78#endif
79 }
80 }
81 WHEN( "Converting medium integers" ) {
82 DGtal::int64_t medium_int64 = 0x123456789ABCDEFL;
83 DGtal::int32_t a = Converter::cast( medium_int64 );
84 THEN( "The value is lost with a warning" ) {
85 REQUIRE( DGtal::int64_t( a ) != medium_int64 );
86 }
87 }
88}

References REQUIRE().

◆ SCENARIO() [4/4]

SCENARIO ( "IntegerConverter< 1, int64 >" ,
"" [integer_conversions] )

Definition at line 90 of file testIntegerConverter.cpp.

91{
93 DGtal::int32_t medium_int32 = DGtal::int32_t( 0x123456789ABCDEFL );
94 DGtal::int64_t medium_int64 = 0x123456789ABCDEFL;
95 #ifdef WITH_BIGINTEGER
96 DGtal::BigInteger medium_bigint = 0x123456789ABCDEFL;
97 #endif
98 WHEN( "Converting 64bits integers" ) {
99 DGtal::int64_t a = Converter::cast( medium_int32 );
100 DGtal::int64_t b = Converter::cast( medium_int64 );
101 #ifdef WITH_BIGINTEGER
102 DGtal::int64_t c = Converter::cast( medium_bigint );
103 #endif
104 THEN( "Only bigger integers are identical" ) {
105 REQUIRE( a == medium_int32 );
106 REQUIRE( a != b );
107 REQUIRE( b == medium_int64 );
108#ifdef WITH_BIGINTEGER
109 REQUIRE( b == c );
110 #endif
111 }
112 THEN( "It gives the same results with NumberTraits" ) {
115#ifdef WITH_BIGINTEGER
117#endif
118 REQUIRE( a == ap );
119 REQUIRE( b == bp );
120#ifdef WITH_BIGINTEGER
121 REQUIRE( c == cp );
122#endif
123 }
124 }
125}
Aim: The traits class for all models of Cinteger.

References REQUIRE().