DGtal 2.1.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 112 of file testIntegerConverter.cpp.

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}
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
----------— INTEGER/POINT CONVERSION SERVICES -----------------—

References 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 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}

References REQUIRE().

◆ SCENARIO() [4/4]

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

Definition at line 84 of file testIntegerConverter.cpp.

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}
Aim: The traits class for all models of Cinteger.

References REQUIRE().