DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
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
37
using namespace
std
;
38
using namespace
DGtal
;
39
40
42
// Functions for testing class IntegerConverter.
44
45
SCENARIO
(
"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
}
59
SCENARIO
(
"IntegerConverter< 1, int32 >"
,
"[integer_conversions]"
)
60
{
61
typedef
IntegerConverter< 1, DGtal::int32_t >
Converter;
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
84
SCENARIO
(
"IntegerConverter< 1, int64 >"
,
"[integer_conversions]"
)
85
{
86
typedef
IntegerConverter< 1, DGtal::int64_t >
Converter;
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"
) {
101
DGtal::int64_t
ap =
NumberTraits<DGtal::int32_t>::castToInt64_t
( medium_int32 );
102
DGtal::int64_t
bp =
NumberTraits<DGtal::int64_t>::castToInt64_t
( medium_int64 );
103
DGtal::int64_t
cp =
NumberTraits<DGtal::BigInteger>::castToInt64_t
( medium_bigint );
104
REQUIRE
( a == ap );
105
REQUIRE
( b == bp );
106
REQUIRE
( c == cp );
107
}
108
}
109
}
110
111
112
SCENARIO
(
"IntegerConverter< 1, BigInteger >"
,
"[integer_conversions]"
)
113
{
114
typedef
IntegerConverter< 1, DGtal::BigInteger >
Converter;
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
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::int32_t
std::int32_t int32_t
signed 32-bit integer.
Definition
BasicTypes.h:71
DGtal::int64_t
std::int64_t int64_t
signed 94-bit integer.
Definition
BasicTypes.h:73
DGtal::BigInteger
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition
BasicTypes.h:75
std
STL namespace.
DGtal::IntegerConverter
----------— INTEGER/POINT CONVERSION SERVICES -----------------—
Definition
IntegerConverter.h:69
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition
NumberTraits.h:562
CAPTURE
CAPTURE(thicknessHV)
SCENARIO
SCENARIO("CorrectedNormalCurrentComputer interpolated curvature measures on sphere tests", "[icnc][sphere]")
Definition
testCorrectedNormalCurrentComputer.cpp:50
REQUIRE
REQUIRE(domain.isInside(aPoint))
tests
kernel
testIntegerConverter.cpp
Generated on
for DGtal by
1.18.0