Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
util
Utility.ut.cpp
Go to the documentation of this file.
1
// The Reactive C++ Toolbox.
2
// Copyright (C) 2013-2019 Swirly Cloud Limited
3
// Copyright (C) 2021 Reactive Markets Limited
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
17
#include "
Utility.hpp
"
18
#include <cmath>
19
#include <limits>
20
21
#include <boost/test/unit_test.hpp>
22
23
using namespace
std
;
24
using namespace
toolbox
;
25
26
namespace
utf
= boost::unit_test;
27
28
BOOST_AUTO_TEST_SUITE
(
UtilitySuite
)
29
30
BOOST_AUTO_TEST_CASE
(
StobCase
)
31
{
32
BOOST_CHECK_EQUAL
(
stob
(
""
sv
,
false
),
false
);
33
BOOST_CHECK_EQUAL
(
stob
(
""
sv
,
true
),
true
);
34
35
BOOST_CHECK_EQUAL
(
stob
(
"0"
sv
,
true
),
false
);
36
BOOST_CHECK_EQUAL
(
stob
(
"F"
sv
,
true
),
false
);
37
BOOST_CHECK_EQUAL
(
stob
(
"N"
sv
,
true
),
false
);
38
BOOST_CHECK_EQUAL
(
stob
(
"f"
sv
,
true
),
false
);
39
BOOST_CHECK_EQUAL
(
stob
(
"n"
sv
,
true
),
false
);
40
41
BOOST_CHECK_EQUAL
(
stob
(
"1"
sv
,
false
),
true
);
42
BOOST_CHECK_EQUAL
(
stob
(
"T"
sv
,
false
),
true
);
43
BOOST_CHECK_EQUAL
(
stob
(
"Y"
sv
,
false
),
true
);
44
BOOST_CHECK_EQUAL
(
stob
(
"t"
sv
,
false
),
true
);
45
BOOST_CHECK_EQUAL
(
stob
(
"y"
sv
,
false
),
true
);
46
47
BOOST_CHECK_EQUAL
(
stob
(
"NO"
sv
,
true
),
false
);
48
BOOST_CHECK_EQUAL
(
stob
(
"No"
sv
,
true
),
false
);
49
BOOST_CHECK_EQUAL
(
stob
(
"no"
sv
,
true
),
false
);
50
51
BOOST_CHECK_EQUAL
(
stob
(
"ON"
sv
,
false
),
true
);
52
BOOST_CHECK_EQUAL
(
stob
(
"On"
sv
,
false
),
true
);
53
BOOST_CHECK_EQUAL
(
stob
(
"on"
sv
,
false
),
true
);
54
55
BOOST_CHECK_EQUAL
(
stob
(
"OFF"
sv
,
true
),
false
);
56
BOOST_CHECK_EQUAL
(
stob
(
"Off"
sv
,
true
),
false
);
57
BOOST_CHECK_EQUAL
(
stob
(
"off"
sv
,
true
),
false
);
58
59
BOOST_CHECK_EQUAL
(
stob
(
"YES"
sv
,
false
),
true
);
60
BOOST_CHECK_EQUAL
(
stob
(
"Yes"
sv
,
false
),
true
);
61
BOOST_CHECK_EQUAL
(
stob
(
"yes"
sv
,
false
),
true
);
62
63
BOOST_CHECK_EQUAL
(
stob
(
"TRUE"
sv
,
false
),
true
);
64
BOOST_CHECK_EQUAL
(
stob
(
"True"
sv
,
false
),
true
);
65
BOOST_CHECK_EQUAL
(
stob
(
"true"
sv
,
false
),
true
);
66
67
BOOST_CHECK_EQUAL
(
stob
(
"FALSE"
sv
,
true
),
false
);
68
BOOST_CHECK_EQUAL
(
stob
(
"False"
sv
,
true
),
false
);
69
BOOST_CHECK_EQUAL
(
stob
(
"false"
sv
,
true
),
false
);
70
}
71
72
BOOST_AUTO_TEST_CASE
(
StodCase
, *utf::tolerance(0.0000001))
73
{
74
BOOST_CHECK_EQUAL
(
stod
(
""
sv
), 0);
75
BOOST_CHECK_EQUAL
(
stod
(
"1"
sv
), 1);
76
BOOST_CHECK_EQUAL
(
stod
(
"-1"
sv
), -1);
77
BOOST_CHECK_EQUAL
(
stod
(
"1.23E2"
sv
), 123);
78
BOOST_CHECK_EQUAL
(
stod
(
"-1.23E2"
sv
), -123);
79
BOOST_CHECK_EQUAL
(
stod
(
"1.23E1"
sv
), 12.3);
80
BOOST_CHECK_EQUAL
(
stod
(
"-1.23E1"
sv
), -12.3);
81
BOOST_CHECK_EQUAL
(
stod
(
"1.23"
sv
), 1.23);
82
BOOST_CHECK_EQUAL
(
stod
(
"-1.23"
sv
), -1.23);
83
84
// with default value.
85
BOOST_CHECK
(
isnan
(
stod
(
""
sv
, numeric_limits<double>::quiet_NaN())));
86
BOOST_CHECK
(
isnan
(
stod
(
"abc"
sv
, numeric_limits<double>::quiet_NaN())));
87
BOOST_CHECK_EQUAL
(
stod
(
"1"
sv
, numeric_limits<double>::quiet_NaN()), 1);
88
}
89
90
BOOST_AUTO_TEST_CASE
(
StonDoubleCase
, *utf::tolerance(0.0000001))
91
{
92
BOOST_CHECK_EQUAL
(
ston<double>
(
""
sv
), 0);
93
BOOST_CHECK_EQUAL
(
ston<double>
(
"1"
sv
), 1);
94
BOOST_CHECK_EQUAL
(
ston<double>
(
"-1"
sv
), -1);
95
BOOST_CHECK_EQUAL
(
ston<double>
(
"1.23E2"
sv
), 123);
96
BOOST_CHECK_EQUAL
(
ston<double>
(
"-1.23E2"
sv
), -123);
97
BOOST_CHECK_EQUAL
(
ston<double>
(
"1.23E1"
sv
), 12.3);
98
BOOST_CHECK_EQUAL
(
ston<double>
(
"-1.23E1"
sv
), -12.3);
99
BOOST_CHECK_EQUAL
(
ston<double>
(
"1.23"
sv
), 1.23);
100
BOOST_CHECK_EQUAL
(
ston<double>
(
"-1.23"
sv
), -1.23);
101
}
102
103
BOOST_AUTO_TEST_CASE
(
StonSubstrCase
)
104
{
105
constexpr
auto
s
=
"12345"
sv
;
106
BOOST_CHECK_EQUAL
(
ston<double>
(
s
.substr(0, 3)), 123);
107
BOOST_CHECK_EQUAL
(
ston<int>
(
s
.substr(0, 3)), 123);
108
}
109
110
BOOST_AUTO_TEST_CASE
(
Stoi16Case
)
111
{
112
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
""
sv
), 0);
113
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"1"
sv
), 1);
114
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"123"
sv
), 123);
115
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
" "
sv
), 0);
116
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"x"
sv
), 0);
117
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"x1 "
sv
), 0);
118
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"x123 "
sv
), 0);
119
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"32767"
sv
), 0x7fff);
120
BOOST_CHECK_EQUAL
(
ston<int16_t>
(
"-32768"
sv
), -0x8000);
121
}
122
123
BOOST_AUTO_TEST_CASE
(
Stoi32Case
)
124
{
125
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
""
sv
), 0);
126
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"1"
sv
), 1);
127
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"123"
sv
), 123);
128
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
" "
sv
), 0);
129
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"x"
sv
), 0);
130
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"x1 "
sv
), 0);
131
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"x123 "
sv
), 0);
132
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"2147483647"
sv
), 0x7fffffff);
133
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"-2147483648"
sv
), -0x80000000);
134
}
135
136
BOOST_AUTO_TEST_CASE
(
Stoi32NegSignCase
)
137
{
138
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"-"
sv
), 0);
139
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"-1"
sv
), -1);
140
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"-123"
sv
), -123);
141
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"-x"
sv
), 0);
142
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"x-1 "
sv
), 0);
143
BOOST_CHECK_EQUAL
(
ston<int32_t>
(
"x-123 "
sv
), 0);
144
}
145
146
BOOST_AUTO_TEST_CASE
(
Stoi64Case
)
147
{
148
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
""
sv
), 0
L
);
149
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"1"
sv
), 1L);
150
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"123"
sv
), 123L);
151
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
" "
sv
), 0
L
);
152
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"x"
sv
), 0
L
);
153
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"x1 "
sv
), 0
L
);
154
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"x123 "
sv
), 0
L
);
155
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"9223372036854775807"
sv
), 0x7fffffffffffffffLL);
156
BOOST_CHECK_EQUAL
(
ston<int64_t>
(
"-9223372036854775808"
sv
), -0x8000000000000000LL);
157
}
158
159
BOOST_AUTO_TEST_CASE
(
Stou16Case
)
160
{
161
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
""
sv
), 0);
162
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"1"
sv
), 1);
163
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"123"
sv
), 123);
164
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
" "
sv
), 0);
165
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"x"
sv
), 0);
166
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"x1 "
sv
), 0);
167
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"x123 "
sv
), 0);
168
BOOST_CHECK_EQUAL
(
ston<uint16_t>
(
"65535"
sv
), 0xffff);
169
}
170
171
BOOST_AUTO_TEST_CASE
(
Stou32Case
)
172
{
173
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
""
sv
), 0
U
);
174
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"1"
sv
), 1U);
175
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"123"
sv
), 123U);
176
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
" "
sv
), 0
U
);
177
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"x"
sv
), 0
U
);
178
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"x1 "
sv
), 0
U
);
179
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"x123 "
sv
), 0
U
);
180
BOOST_CHECK_EQUAL
(
ston<uint32_t>
(
"4294967295"
sv
), 0xffffffffU);
181
}
182
183
BOOST_AUTO_TEST_CASE
(
Stou64Case
)
184
{
185
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
""
sv
), 0
UL
);
186
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"1"
sv
), 1UL);
187
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"123"
sv
), 123UL);
188
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
" "
sv
), 0
UL
);
189
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"x"
sv
), 0
UL
);
190
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"x1 "
sv
), 0
UL
);
191
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"x123 "
sv
), 0
UL
);
192
BOOST_CHECK_EQUAL
(
ston<uint64_t>
(
"18446744073709551615"
sv
), 0xffffffffffffffffULL);
193
}
194
195
BOOST_AUTO_TEST_CASE
(
HexDigitsCase
)
196
{
197
BOOST_CHECK_EQUAL
(
hex_digits
(0x0U), 1);
198
BOOST_CHECK_EQUAL
(
hex_digits
(0x1U), 1);
199
BOOST_CHECK_EQUAL
(
hex_digits
(0xfU), 1);
200
BOOST_CHECK_EQUAL
(
hex_digits
(0x10U), 2);
201
BOOST_CHECK_EQUAL
(
hex_digits
(0xffU), 2);
202
203
BOOST_CHECK_EQUAL
(
hex_digits
(0xcdefU), 4);
204
BOOST_CHECK_EQUAL
(
hex_digits
(0x10000U), 5);
205
BOOST_CHECK_EQUAL
(
hex_digits
(0x89abcdefU), 8);
206
BOOST_CHECK_EQUAL
(
hex_digits
(0x100000000U), 9);
207
BOOST_CHECK_EQUAL
(
hex_digits
(0x567890abcdefU), 12);
208
BOOST_CHECK_EQUAL
(
hex_digits
(0x1000000000000U), 13);
209
BOOST_CHECK_EQUAL
(
hex_digits
(0x1234567890abcdefU), 16);
210
}
211
212
BOOST_AUTO_TEST_CASE
(
DecDigitsUnsignedCase
)
213
{
214
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{0}), 1);
215
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1}), 1);
216
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9}), 1);
217
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10}), 2);
218
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{11}), 2);
219
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99}), 2);
220
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100}), 3);
221
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{101}), 3);
222
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999}), 3);
223
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000}), 4);
224
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1001}), 4);
225
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999}), 4);
226
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000}), 5);
227
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10001}), 5);
228
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99999}), 5);
229
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000}), 6);
230
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100001}), 6);
231
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999999}), 6);
232
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000}), 7);
233
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000001}), 7);
234
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999999}), 7);
235
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000}), 8);
236
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000001}), 8);
237
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99999999}), 8);
238
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000}), 9);
239
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000001}), 9);
240
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999999999}), 9);
241
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000}), 10);
242
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000001}), 10);
243
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999999999}), 10);
244
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000}), 11);
245
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000001}), 11);
246
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99999999999}), 11);
247
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000000}), 12);
248
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000001}), 12);
249
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999999999999}), 12);
250
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000000}), 13);
251
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000001}), 13);
252
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999999999999}), 13);
253
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000000}), 14);
254
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000001}), 14);
255
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99999999999999}), 14);
256
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000000000}), 15);
257
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000000001}), 15);
258
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999999999999999}), 15);
259
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000000000}), 16);
260
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000000001}), 16);
261
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999999999999999}), 16);
262
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000000000}), 17);
263
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000000001}), 17);
264
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{99999999999999999}), 17);
265
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000000000000}), 18);
266
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{100000000000000001}), 18);
267
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{999999999999999999}), 18);
268
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000000000000}), 19);
269
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{1000000000000000001}), 19);
270
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{9999999999999999999ULL}), 19);
271
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000000000000ULL}), 20);
272
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{10000000000000000001ULL}), 20);
273
BOOST_CHECK_EQUAL
(
dec_digits
(std::uint64_t{18446744073709551615ULL}), 20);
274
}
275
276
BOOST_AUTO_TEST_CASE
(
DecDigitSignedCase
)
277
{
278
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1}), 1);
279
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9}), 1);
280
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10}), 2);
281
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-11}), 2);
282
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99}), 2);
283
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100}), 3);
284
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-101}), 3);
285
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999}), 3);
286
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000}), 4);
287
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1001}), 4);
288
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9999}), 4);
289
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000}), 5);
290
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10001}), 5);
291
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99999}), 5);
292
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000}), 6);
293
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100001}), 6);
294
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999999}), 6);
295
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000}), 7);
296
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000001}), 7);
297
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9999999}), 7);
298
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000}), 8);
299
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000001}), 8);
300
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99999999}), 8);
301
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000}), 9);
302
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000001}), 9);
303
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999999999}), 9);
304
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000}), 10);
305
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000001}), 10);
306
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9999999999}), 10);
307
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000000}), 11);
308
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000001}), 11);
309
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99999999999}), 11);
310
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000000}), 12);
311
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000001}), 12);
312
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999999999999}), 12);
313
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000000}), 13);
314
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000001}), 13);
315
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9999999999999}), 13);
316
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000000000}), 14);
317
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000000001}), 14);
318
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99999999999999}), 14);
319
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000000000}), 15);
320
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000000001}), 15);
321
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999999999999999}), 15);
322
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000000000}), 16);
323
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000000001}), 16);
324
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9999999999999999}), 16);
325
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000000000000}), 17);
326
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-10000000000000001}), 17);
327
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-99999999999999999}), 17);
328
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000000000000}), 18);
329
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-100000000000000001}), 18);
330
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-999999999999999999}), 18);
331
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000000000000}), 19);
332
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-1000000000000000001}), 19);
333
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{-9223372036854775807}), 19);
334
BOOST_CHECK_EQUAL
(
dec_digits
(std::numeric_limits<std::int64_t>::min()), 19);
335
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{0}), 1);
336
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1}), 1);
337
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9}), 1);
338
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10}), 2);
339
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{11}), 2);
340
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99}), 2);
341
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100}), 3);
342
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{101}), 3);
343
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999}), 3);
344
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000}), 4);
345
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1001}), 4);
346
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9999}), 4);
347
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000}), 5);
348
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10001}), 5);
349
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99999}), 5);
350
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000}), 6);
351
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100001}), 6);
352
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999999}), 6);
353
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000}), 7);
354
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000001}), 7);
355
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9999999}), 7);
356
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000}), 8);
357
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000001}), 8);
358
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99999999}), 8);
359
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000}), 9);
360
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000001}), 9);
361
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999999999}), 9);
362
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000}), 10);
363
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000001}), 10);
364
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9999999999}), 10);
365
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000000}), 11);
366
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000001}), 11);
367
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99999999999}), 11);
368
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000000}), 12);
369
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000001}), 12);
370
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999999999999}), 12);
371
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000000}), 13);
372
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000001}), 13);
373
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9999999999999}), 13);
374
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000000000}), 14);
375
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000000001}), 14);
376
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99999999999999}), 14);
377
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000000000}), 15);
378
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000000001}), 15);
379
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999999999999999}), 15);
380
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000000000}), 16);
381
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000000001}), 16);
382
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9999999999999999}), 16);
383
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000000000000}), 17);
384
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{10000000000000001}), 17);
385
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{99999999999999999}), 17);
386
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000000000000}), 18);
387
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{100000000000000001}), 18);
388
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{999999999999999999}), 18);
389
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000000000000}), 19);
390
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{1000000000000000001}), 19);
391
BOOST_CHECK_EQUAL
(
dec_digits
(std::int64_t{9223372036854775807}), 19);
392
}
393
394
BOOST_AUTO_TEST_SUITE_END
()
std
STL namespace.
toolbox::util::stob
bool stob(string_view sv, bool dfl) noexcept
Definition
Utility.cpp:26
toolbox::util::dec_digits
constexpr int dec_digits(ValueT i) noexcept
Definition
Utility.hpp:52
toolbox::util::hex_digits
constexpr int hex_digits(UIntegerT i) noexcept
Definition
Utility.hpp:103
toolbox::util::sv
std::string_view sv
Definition
Tokeniser.hpp:26
toolbox::util::stod
double stod(std::string_view sv, double dfl) noexcept
Definition
Utility.cpp:89
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
Utility.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(StobCase)
Definition
Utility.ut.cpp:30
BOOST_CHECK
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(stod("1"sv), 1)
Generated by
1.9.8