-
Notifications
You must be signed in to change notification settings - Fork 3
/
byte_size.test.cc
474 lines (439 loc) · 34.7 KB
/
byte_size.test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/fmt/byte_size.hh"
#include "snn-core/unittest.hh"
namespace snn::app
{
namespace
{
constexpr bool example()
{
// SI units by default (powers of 1000).
snn_require(fmt::byte_size(byte_size{0}) == "0 B");
snn_require(fmt::byte_size(byte_size{123}) == "123 B");
snn_require(fmt::byte_size(byte_size{1000}) == "1.0 kB");
snn_require(fmt::byte_size(byte_size{1024}) == "1.0 kB");
snn_require(fmt::byte_size(byte_size{999999}) == "1.0 MB");
snn_require(fmt::byte_size(byte_size{1048576}) == "1.0 MB");
snn_require(fmt::byte_size(byte_size{1073741824}) == "1.1 GB");
snn_require(fmt::byte_size(byte_size{1099511627776}) == "1.1 TB");
snn_require(fmt::byte_size(byte_size{1125899906842624}) == "1.1 PB");
snn_require(fmt::byte_size(byte_size{1152921504606846976}) == "1.2 EB");
snn_require(fmt::byte_size(byte_size{constant::limit<usize>::max}) == "18 EB");
return true;
}
bool test_format_byte_size()
{
// Default (empty formatting string).
snn_require(fmt::format("{}", byte_size{0}) == "0 B");
snn_require(fmt::format("{}", byte_size{999'999}) == "1.0 MB");
snn_require(fmt::format("{}", byte_size{5'555'555'555}) == "5.6 GB");
// Unit (no spacing).
snn_require(fmt::format("{:k}", byte_size{999'999}) == "1.0M"); // SI-short
snn_require(fmt::format("{:k}", byte_size{5'555'555'555}) == "5.6G"); // SI-short
snn_require(fmt::format("{:kB}", byte_size{999'999}) == "1.0MB"); // SI
snn_require(fmt::format("{:kB}", byte_size{5'555'555'555}) == "5.6GB"); // SI
snn_require(fmt::format("{:K}", byte_size{999'999}) == "977K"); // IEC-short
snn_require(fmt::format("{:K}", byte_size{5'555'555'555}) == "5.2G"); // IEC-short
snn_require(fmt::format("{:KiB}", byte_size{999'999}) == "977KiB"); // IEC
snn_require(fmt::format("{:KiB}", byte_size{5'555'555'555}) == "5.2GiB"); // IEC
// Only "k", "kB", "K" and "KiB" are recognized as units.
// Here "MB" is parsed as spacing.
snn_require(fmt::format("{:MB}", byte_size{5'555'555'555}) == "5.6MBGB");
// Spacing (default unit)
snn_require(fmt::format("{: }", byte_size{999'999}) == "1.0 MB");
snn_require(fmt::format("{: }", byte_size{999'999}) == "1.0 MB");
snn_require(fmt::format("{: }", byte_size{999'999}) == "1.0 MB");
// Spacing + unit.
snn_require(fmt::format("{: k}", byte_size{999'999}) == "1.0 M");
snn_require(fmt::format("{: kB}", byte_size{999'999}) == "1.0 MB");
snn_require(fmt::format("{: K}", byte_size{999'999}) == "977 K");
snn_require(fmt::format("{: KiB}", byte_size{999'999}) == "977 KiB");
snn_require(fmt::format("{: k}", byte_size{999'999}) == "1.0 M");
snn_require(fmt::format("{: kB}", byte_size{999'999}) == "1.0 MB");
snn_require(fmt::format("{: K}", byte_size{999'999}) == "977 K");
snn_require(fmt::format("{: KiB}", byte_size{999'999}) == "977 KiB");
// Decimal point (no spacing, default unit).
snn_require(fmt::format("{:,0}", byte_size{999'999}) == "1,0MB");
snn_require(fmt::format("{:,0}", byte_size{999'999}) == "1,0MB"); // U+FF0C
snn_require(fmt::format("{:,0}", byte_size{5'555'555'555}) == "5,6GB");
snn_require(fmt::format("{:,0}", byte_size{5'555'555'555}) == "5,6GB"); // U+FF0C
// Only '0' can be used as a separator between decimal point and spacing.
snn_require_throws_code(fmt::format("{:,9}", byte_size{0}),
fmt::error::unexpected_character_in_format_string);
// '0' separator but empty decimal point.
snn_require_throws_code(fmt::format("{:0}", byte_size{0}),
fmt::error::unexpected_character_in_format_string);
// Decimal point + spacing (default unit).
snn_require(fmt::format("{:,0 }", byte_size{999'999}) == "1,0 MB");
snn_require(fmt::format("{:,0 }", byte_size{999'999}) == "1,0 MB"); // U+FF0C
// Decimal point + unit (no spacing).
snn_require(fmt::format("{:,0k}", byte_size{999'999}) == "1,0M");
snn_require(fmt::format("{:,0K}", byte_size{999'999}) == "977K");
// Decimal point + spacing + unit.
snn_require(fmt::format("{:,0 k}", byte_size{999'999}) == "1,0 M");
snn_require(fmt::format("{:,0 kB}", byte_size{999'999}) == "1,0 MB");
snn_require(fmt::format("{:,0 K}", byte_size{999'999}) == "977 K");
snn_require(fmt::format("{:,0 KiB}", byte_size{999'999}) == "977 KiB");
snn_require(fmt::format("{:,0 k}", byte_size{999'999}) == "1,0 M");
snn_require(fmt::format("{:,0 kB}", byte_size{999'999}) == "1,0 MB");
snn_require(fmt::format("{:,0 K}", byte_size{999'999}) == "977 K");
snn_require(fmt::format("{:,0 KiB}", byte_size{999'999}) == "977 KiB");
return true;
}
constexpr bool test_byte_size_generated()
{
// Generated by: detail/byte_size.test.gen.cc
// 1000 B,kB,MB,GB...
// 1000 B,k,M,G...
using fmt::table::byte_size::si;
using fmt::table::byte_size::si_short;
snn_require(fmt::byte_size<1000>(byte_size{0}, si) == "0 B");
snn_require(fmt::byte_size<1000>(byte_size{0}, si_short) == "0 B");
snn_require(fmt::byte_size<1000>(byte_size{1}, si) == "1 B");
snn_require(fmt::byte_size<1000>(byte_size{1}, si_short) == "1 B");
snn_require(fmt::byte_size<1000>(byte_size{10}, si) == "10 B");
snn_require(fmt::byte_size<1000>(byte_size{10}, si_short) == "10 B");
snn_require(fmt::byte_size<1000>(byte_size{100}, si) == "100 B");
snn_require(fmt::byte_size<1000>(byte_size{100}, si_short) == "100 B");
snn_require(fmt::byte_size<1000>(byte_size{1000}, si) == "1.0 kB");
snn_require(fmt::byte_size<1000>(byte_size{1000}, si_short) == "1.0 k");
snn_require(fmt::byte_size<1000>(byte_size{10000}, si) == "10 kB");
snn_require(fmt::byte_size<1000>(byte_size{10000}, si_short) == "10 k");
snn_require(fmt::byte_size<1000>(byte_size{100000}, si) == "100 kB");
snn_require(fmt::byte_size<1000>(byte_size{100000}, si_short) == "100 k");
snn_require(fmt::byte_size<1000>(byte_size{1000000}, si) == "1.0 MB");
snn_require(fmt::byte_size<1000>(byte_size{1000000}, si_short) == "1.0 M");
snn_require(fmt::byte_size<1000>(byte_size{10000000}, si) == "10 MB");
snn_require(fmt::byte_size<1000>(byte_size{10000000}, si_short) == "10 M");
snn_require(fmt::byte_size<1000>(byte_size{100000000}, si) == "100 MB");
snn_require(fmt::byte_size<1000>(byte_size{100000000}, si_short) == "100 M");
snn_require(fmt::byte_size<1000>(byte_size{1000000000}, si) == "1.0 GB");
snn_require(fmt::byte_size<1000>(byte_size{1000000000}, si_short) == "1.0 G");
snn_require(fmt::byte_size<1000>(byte_size{10000000000}, si) == "10 GB");
snn_require(fmt::byte_size<1000>(byte_size{10000000000}, si_short) == "10 G");
snn_require(fmt::byte_size<1000>(byte_size{100000000000}, si) == "100 GB");
snn_require(fmt::byte_size<1000>(byte_size{100000000000}, si_short) == "100 G");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000}, si) == "1.0 TB");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000}, si_short) == "1.0 T");
snn_require(fmt::byte_size<1000>(byte_size{10000000000000}, si) == "10 TB");
snn_require(fmt::byte_size<1000>(byte_size{10000000000000}, si_short) == "10 T");
snn_require(fmt::byte_size<1000>(byte_size{100000000000000}, si) == "100 TB");
snn_require(fmt::byte_size<1000>(byte_size{100000000000000}, si_short) == "100 T");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000000}, si) == "1.0 PB");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000000}, si_short) == "1.0 P");
snn_require(fmt::byte_size<1000>(byte_size{10000000000000000}, si) == "10 PB");
snn_require(fmt::byte_size<1000>(byte_size{10000000000000000}, si_short) == "10 P");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000000000}, si) == "1.0 EB");
snn_require(fmt::byte_size<1000>(byte_size{1000000000000000000}, si_short) == "1.0 E");
snn_require(fmt::byte_size<1000>(byte_size{2}, si) == "2 B");
snn_require(fmt::byte_size<1000>(byte_size{2}, si_short) == "2 B");
snn_require(fmt::byte_size<1000>(byte_size{22}, si) == "22 B");
snn_require(fmt::byte_size<1000>(byte_size{22}, si_short) == "22 B");
snn_require(fmt::byte_size<1000>(byte_size{222}, si) == "222 B");
snn_require(fmt::byte_size<1000>(byte_size{222}, si_short) == "222 B");
snn_require(fmt::byte_size<1000>(byte_size{2222}, si) == "2.2 kB");
snn_require(fmt::byte_size<1000>(byte_size{2222}, si_short) == "2.2 k");
snn_require(fmt::byte_size<1000>(byte_size{22222}, si) == "22 kB");
snn_require(fmt::byte_size<1000>(byte_size{22222}, si_short) == "22 k");
snn_require(fmt::byte_size<1000>(byte_size{222222}, si) == "222 kB");
snn_require(fmt::byte_size<1000>(byte_size{222222}, si_short) == "222 k");
snn_require(fmt::byte_size<1000>(byte_size{2222222}, si) == "2.2 MB");
snn_require(fmt::byte_size<1000>(byte_size{2222222}, si_short) == "2.2 M");
snn_require(fmt::byte_size<1000>(byte_size{22222222}, si) == "22 MB");
snn_require(fmt::byte_size<1000>(byte_size{22222222}, si_short) == "22 M");
snn_require(fmt::byte_size<1000>(byte_size{222222222}, si) == "222 MB");
snn_require(fmt::byte_size<1000>(byte_size{222222222}, si_short) == "222 M");
snn_require(fmt::byte_size<1000>(byte_size{2222222222}, si) == "2.2 GB");
snn_require(fmt::byte_size<1000>(byte_size{2222222222}, si_short) == "2.2 G");
snn_require(fmt::byte_size<1000>(byte_size{22222222222}, si) == "22 GB");
snn_require(fmt::byte_size<1000>(byte_size{22222222222}, si_short) == "22 G");
snn_require(fmt::byte_size<1000>(byte_size{222222222222}, si) == "222 GB");
snn_require(fmt::byte_size<1000>(byte_size{222222222222}, si_short) == "222 G");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222}, si) == "2.2 TB");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222}, si_short) == "2.2 T");
snn_require(fmt::byte_size<1000>(byte_size{22222222222222}, si) == "22 TB");
snn_require(fmt::byte_size<1000>(byte_size{22222222222222}, si_short) == "22 T");
snn_require(fmt::byte_size<1000>(byte_size{222222222222222}, si) == "222 TB");
snn_require(fmt::byte_size<1000>(byte_size{222222222222222}, si_short) == "222 T");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222222}, si) == "2.2 PB");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222222}, si_short) == "2.2 P");
snn_require(fmt::byte_size<1000>(byte_size{22222222222222222}, si) == "22 PB");
snn_require(fmt::byte_size<1000>(byte_size{22222222222222222}, si_short) == "22 P");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222222222}, si) == "2.2 EB");
snn_require(fmt::byte_size<1000>(byte_size{2222222222222222222}, si_short) == "2.2 E");
snn_require(fmt::byte_size<1000>(byte_size{5}, si) == "5 B");
snn_require(fmt::byte_size<1000>(byte_size{5}, si_short) == "5 B");
snn_require(fmt::byte_size<1000>(byte_size{55}, si) == "55 B");
snn_require(fmt::byte_size<1000>(byte_size{55}, si_short) == "55 B");
snn_require(fmt::byte_size<1000>(byte_size{555}, si) == "555 B");
snn_require(fmt::byte_size<1000>(byte_size{555}, si_short) == "555 B");
snn_require(fmt::byte_size<1000>(byte_size{5555}, si) == "5.6 kB");
snn_require(fmt::byte_size<1000>(byte_size{5555}, si_short) == "5.6 k");
snn_require(fmt::byte_size<1000>(byte_size{55555}, si) == "56 kB");
snn_require(fmt::byte_size<1000>(byte_size{55555}, si_short) == "56 k");
snn_require(fmt::byte_size<1000>(byte_size{555555}, si) == "556 kB");
snn_require(fmt::byte_size<1000>(byte_size{555555}, si_short) == "556 k");
snn_require(fmt::byte_size<1000>(byte_size{5555555}, si) == "5.6 MB");
snn_require(fmt::byte_size<1000>(byte_size{5555555}, si_short) == "5.6 M");
snn_require(fmt::byte_size<1000>(byte_size{55555555}, si) == "56 MB");
snn_require(fmt::byte_size<1000>(byte_size{55555555}, si_short) == "56 M");
snn_require(fmt::byte_size<1000>(byte_size{555555555}, si) == "556 MB");
snn_require(fmt::byte_size<1000>(byte_size{555555555}, si_short) == "556 M");
snn_require(fmt::byte_size<1000>(byte_size{5555555555}, si) == "5.6 GB");
snn_require(fmt::byte_size<1000>(byte_size{5555555555}, si_short) == "5.6 G");
snn_require(fmt::byte_size<1000>(byte_size{55555555555}, si) == "56 GB");
snn_require(fmt::byte_size<1000>(byte_size{55555555555}, si_short) == "56 G");
snn_require(fmt::byte_size<1000>(byte_size{555555555555}, si) == "556 GB");
snn_require(fmt::byte_size<1000>(byte_size{555555555555}, si_short) == "556 G");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555}, si) == "5.6 TB");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555}, si_short) == "5.6 T");
snn_require(fmt::byte_size<1000>(byte_size{55555555555555}, si) == "56 TB");
snn_require(fmt::byte_size<1000>(byte_size{55555555555555}, si_short) == "56 T");
snn_require(fmt::byte_size<1000>(byte_size{555555555555555}, si) == "556 TB");
snn_require(fmt::byte_size<1000>(byte_size{555555555555555}, si_short) == "556 T");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555555}, si) == "5.6 PB");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555555}, si_short) == "5.6 P");
snn_require(fmt::byte_size<1000>(byte_size{55555555555555555}, si) == "56 PB");
snn_require(fmt::byte_size<1000>(byte_size{55555555555555555}, si_short) == "56 P");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555555555}, si) == "5.6 EB");
snn_require(fmt::byte_size<1000>(byte_size{5555555555555555555}, si_short) == "5.6 E");
snn_require(fmt::byte_size<1000>(byte_size{9}, si) == "9 B");
snn_require(fmt::byte_size<1000>(byte_size{9}, si_short) == "9 B");
snn_require(fmt::byte_size<1000>(byte_size{99}, si) == "99 B");
snn_require(fmt::byte_size<1000>(byte_size{99}, si_short) == "99 B");
snn_require(fmt::byte_size<1000>(byte_size{999}, si) == "999 B");
snn_require(fmt::byte_size<1000>(byte_size{999}, si_short) == "999 B");
snn_require(fmt::byte_size<1000>(byte_size{9999}, si) == "10 kB");
snn_require(fmt::byte_size<1000>(byte_size{9999}, si_short) == "10 k");
snn_require(fmt::byte_size<1000>(byte_size{99999}, si) == "100 kB");
snn_require(fmt::byte_size<1000>(byte_size{99999}, si_short) == "100 k");
snn_require(fmt::byte_size<1000>(byte_size{999999}, si) == "1.0 MB");
snn_require(fmt::byte_size<1000>(byte_size{999999}, si_short) == "1.0 M");
snn_require(fmt::byte_size<1000>(byte_size{9999999}, si) == "10 MB");
snn_require(fmt::byte_size<1000>(byte_size{9999999}, si_short) == "10 M");
snn_require(fmt::byte_size<1000>(byte_size{99999999}, si) == "100 MB");
snn_require(fmt::byte_size<1000>(byte_size{99999999}, si_short) == "100 M");
snn_require(fmt::byte_size<1000>(byte_size{999999999}, si) == "1.0 GB");
snn_require(fmt::byte_size<1000>(byte_size{999999999}, si_short) == "1.0 G");
snn_require(fmt::byte_size<1000>(byte_size{9999999999}, si) == "10 GB");
snn_require(fmt::byte_size<1000>(byte_size{9999999999}, si_short) == "10 G");
snn_require(fmt::byte_size<1000>(byte_size{99999999999}, si) == "100 GB");
snn_require(fmt::byte_size<1000>(byte_size{99999999999}, si_short) == "100 G");
snn_require(fmt::byte_size<1000>(byte_size{999999999999}, si) == "1.0 TB");
snn_require(fmt::byte_size<1000>(byte_size{999999999999}, si_short) == "1.0 T");
snn_require(fmt::byte_size<1000>(byte_size{9999999999999}, si) == "10 TB");
snn_require(fmt::byte_size<1000>(byte_size{9999999999999}, si_short) == "10 T");
snn_require(fmt::byte_size<1000>(byte_size{99999999999999}, si) == "100 TB");
snn_require(fmt::byte_size<1000>(byte_size{99999999999999}, si_short) == "100 T");
snn_require(fmt::byte_size<1000>(byte_size{999999999999999}, si) == "1.0 PB");
snn_require(fmt::byte_size<1000>(byte_size{999999999999999}, si_short) == "1.0 P");
snn_require(fmt::byte_size<1000>(byte_size{9999999999999999}, si) == "10 PB");
snn_require(fmt::byte_size<1000>(byte_size{9999999999999999}, si_short) == "10 P");
snn_require(fmt::byte_size<1000>(byte_size{99999999999999999}, si) == "100 PB");
snn_require(fmt::byte_size<1000>(byte_size{99999999999999999}, si_short) == "100 P");
snn_require(fmt::byte_size<1000>(byte_size{9223372036854775807}, si) == "9.2 EB");
snn_require(fmt::byte_size<1000>(byte_size{9223372036854775807}, si_short) == "9.2 E");
snn_require(fmt::byte_size<1000>(byte_size{1024}, si) == "1.0 kB");
snn_require(fmt::byte_size<1000>(byte_size{1024}, si_short) == "1.0 k");
snn_require(fmt::byte_size<1000>(byte_size{1048576}, si) == "1.0 MB");
snn_require(fmt::byte_size<1000>(byte_size{1048576}, si_short) == "1.0 M");
snn_require(fmt::byte_size<1000>(byte_size{1073741824}, si) == "1.1 GB");
snn_require(fmt::byte_size<1000>(byte_size{1073741824}, si_short) == "1.1 G");
snn_require(fmt::byte_size<1000>(byte_size{1099511627776}, si) == "1.1 TB");
snn_require(fmt::byte_size<1000>(byte_size{1099511627776}, si_short) == "1.1 T");
snn_require(fmt::byte_size<1000>(byte_size{1125899906842624}, si) == "1.1 PB");
snn_require(fmt::byte_size<1000>(byte_size{1125899906842624}, si_short) == "1.1 P");
snn_require(fmt::byte_size<1000>(byte_size{1152921504606846976}, si) == "1.2 EB");
snn_require(fmt::byte_size<1000>(byte_size{1152921504606846976}, si_short) == "1.2 E");
snn_require(fmt::byte_size<1000>(byte_size{1001}, si) == "1.0 kB");
snn_require(fmt::byte_size<1000>(byte_size{1001}, si_short) == "1.0 k");
snn_require(fmt::byte_size<1000>(byte_size{1023}, si) == "1.0 kB");
snn_require(fmt::byte_size<1000>(byte_size{1023}, si_short) == "1.0 k");
snn_require(fmt::byte_size<1000>(byte_size{1047552}, si) == "1.0 MB");
snn_require(fmt::byte_size<1000>(byte_size{1047552}, si_short) == "1.0 M");
snn_require(fmt::byte_size<1000>(byte_size{1048575}, si) == "1.0 MB");
snn_require(fmt::byte_size<1000>(byte_size{1048575}, si_short) == "1.0 M");
// 1024 B,K,M,G...
// 1024 B,KiB,MiB,GiB...
using fmt::table::byte_size::iec;
using fmt::table::byte_size::iec_short;
snn_require(fmt::byte_size<1024>(byte_size{0}, iec) == "0 B");
snn_require(fmt::byte_size<1024>(byte_size{0}, iec_short) == "0 B");
snn_require(fmt::byte_size<1024>(byte_size{1}, iec) == "1 B");
snn_require(fmt::byte_size<1024>(byte_size{1}, iec_short) == "1 B");
snn_require(fmt::byte_size<1024>(byte_size{10}, iec) == "10 B");
snn_require(fmt::byte_size<1024>(byte_size{10}, iec_short) == "10 B");
snn_require(fmt::byte_size<1024>(byte_size{100}, iec) == "100 B");
snn_require(fmt::byte_size<1024>(byte_size{100}, iec_short) == "100 B");
snn_require(fmt::byte_size<1024>(byte_size{1000}, iec) == "1.0 KiB");
snn_require(fmt::byte_size<1024>(byte_size{1000}, iec_short) == "1.0 K");
snn_require(fmt::byte_size<1024>(byte_size{10000}, iec) == "9.8 KiB");
snn_require(fmt::byte_size<1024>(byte_size{10000}, iec_short) == "9.8 K");
snn_require(fmt::byte_size<1024>(byte_size{100000}, iec) == "98 KiB");
snn_require(fmt::byte_size<1024>(byte_size{100000}, iec_short) == "98 K");
snn_require(fmt::byte_size<1024>(byte_size{1000000}, iec) == "977 KiB");
snn_require(fmt::byte_size<1024>(byte_size{1000000}, iec_short) == "977 K");
snn_require(fmt::byte_size<1024>(byte_size{10000000}, iec) == "9.5 MiB");
snn_require(fmt::byte_size<1024>(byte_size{10000000}, iec_short) == "9.5 M");
snn_require(fmt::byte_size<1024>(byte_size{100000000}, iec) == "95 MiB");
snn_require(fmt::byte_size<1024>(byte_size{100000000}, iec_short) == "95 M");
snn_require(fmt::byte_size<1024>(byte_size{1000000000}, iec) == "954 MiB");
snn_require(fmt::byte_size<1024>(byte_size{1000000000}, iec_short) == "954 M");
snn_require(fmt::byte_size<1024>(byte_size{10000000000}, iec) == "9.3 GiB");
snn_require(fmt::byte_size<1024>(byte_size{10000000000}, iec_short) == "9.3 G");
snn_require(fmt::byte_size<1024>(byte_size{100000000000}, iec) == "93 GiB");
snn_require(fmt::byte_size<1024>(byte_size{100000000000}, iec_short) == "93 G");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000}, iec) == "931 GiB");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000}, iec_short) == "931 G");
snn_require(fmt::byte_size<1024>(byte_size{10000000000000}, iec) == "9.1 TiB");
snn_require(fmt::byte_size<1024>(byte_size{10000000000000}, iec_short) == "9.1 T");
snn_require(fmt::byte_size<1024>(byte_size{100000000000000}, iec) == "91 TiB");
snn_require(fmt::byte_size<1024>(byte_size{100000000000000}, iec_short) == "91 T");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000000}, iec) == "909 TiB");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000000}, iec_short) == "909 T");
snn_require(fmt::byte_size<1024>(byte_size{10000000000000000}, iec) == "8.9 PiB");
snn_require(fmt::byte_size<1024>(byte_size{10000000000000000}, iec_short) == "8.9 P");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000000000}, iec) == "888 PiB");
snn_require(fmt::byte_size<1024>(byte_size{1000000000000000000}, iec_short) == "888 P");
snn_require(fmt::byte_size<1024>(byte_size{2}, iec) == "2 B");
snn_require(fmt::byte_size<1024>(byte_size{2}, iec_short) == "2 B");
snn_require(fmt::byte_size<1024>(byte_size{22}, iec) == "22 B");
snn_require(fmt::byte_size<1024>(byte_size{22}, iec_short) == "22 B");
snn_require(fmt::byte_size<1024>(byte_size{222}, iec) == "222 B");
snn_require(fmt::byte_size<1024>(byte_size{222}, iec_short) == "222 B");
snn_require(fmt::byte_size<1024>(byte_size{2222}, iec) == "2.2 KiB");
snn_require(fmt::byte_size<1024>(byte_size{2222}, iec_short) == "2.2 K");
snn_require(fmt::byte_size<1024>(byte_size{22222}, iec) == "22 KiB");
snn_require(fmt::byte_size<1024>(byte_size{22222}, iec_short) == "22 K");
snn_require(fmt::byte_size<1024>(byte_size{222222}, iec) == "217 KiB");
snn_require(fmt::byte_size<1024>(byte_size{222222}, iec_short) == "217 K");
snn_require(fmt::byte_size<1024>(byte_size{2222222}, iec) == "2.1 MiB");
snn_require(fmt::byte_size<1024>(byte_size{2222222}, iec_short) == "2.1 M");
snn_require(fmt::byte_size<1024>(byte_size{22222222}, iec) == "21 MiB");
snn_require(fmt::byte_size<1024>(byte_size{22222222}, iec_short) == "21 M");
snn_require(fmt::byte_size<1024>(byte_size{222222222}, iec) == "212 MiB");
snn_require(fmt::byte_size<1024>(byte_size{222222222}, iec_short) == "212 M");
snn_require(fmt::byte_size<1024>(byte_size{2222222222}, iec) == "2.1 GiB");
snn_require(fmt::byte_size<1024>(byte_size{2222222222}, iec_short) == "2.1 G");
snn_require(fmt::byte_size<1024>(byte_size{22222222222}, iec) == "21 GiB");
snn_require(fmt::byte_size<1024>(byte_size{22222222222}, iec_short) == "21 G");
snn_require(fmt::byte_size<1024>(byte_size{222222222222}, iec) == "207 GiB");
snn_require(fmt::byte_size<1024>(byte_size{222222222222}, iec_short) == "207 G");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222}, iec) == "2.0 TiB");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222}, iec_short) == "2.0 T");
snn_require(fmt::byte_size<1024>(byte_size{22222222222222}, iec) == "20 TiB");
snn_require(fmt::byte_size<1024>(byte_size{22222222222222}, iec_short) == "20 T");
snn_require(fmt::byte_size<1024>(byte_size{222222222222222}, iec) == "202 TiB");
snn_require(fmt::byte_size<1024>(byte_size{222222222222222}, iec_short) == "202 T");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222222}, iec) == "2.0 PiB");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222222}, iec_short) == "2.0 P");
snn_require(fmt::byte_size<1024>(byte_size{22222222222222222}, iec) == "20 PiB");
snn_require(fmt::byte_size<1024>(byte_size{22222222222222222}, iec_short) == "20 P");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222222222}, iec) == "1.9 EiB");
snn_require(fmt::byte_size<1024>(byte_size{2222222222222222222}, iec_short) == "1.9 E");
snn_require(fmt::byte_size<1024>(byte_size{5}, iec) == "5 B");
snn_require(fmt::byte_size<1024>(byte_size{5}, iec_short) == "5 B");
snn_require(fmt::byte_size<1024>(byte_size{55}, iec) == "55 B");
snn_require(fmt::byte_size<1024>(byte_size{55}, iec_short) == "55 B");
snn_require(fmt::byte_size<1024>(byte_size{555}, iec) == "555 B");
snn_require(fmt::byte_size<1024>(byte_size{555}, iec_short) == "555 B");
snn_require(fmt::byte_size<1024>(byte_size{5555}, iec) == "5.4 KiB");
snn_require(fmt::byte_size<1024>(byte_size{5555}, iec_short) == "5.4 K");
snn_require(fmt::byte_size<1024>(byte_size{55555}, iec) == "54 KiB");
snn_require(fmt::byte_size<1024>(byte_size{55555}, iec_short) == "54 K");
snn_require(fmt::byte_size<1024>(byte_size{555555}, iec) == "543 KiB");
snn_require(fmt::byte_size<1024>(byte_size{555555}, iec_short) == "543 K");
snn_require(fmt::byte_size<1024>(byte_size{5555555}, iec) == "5.3 MiB");
snn_require(fmt::byte_size<1024>(byte_size{5555555}, iec_short) == "5.3 M");
snn_require(fmt::byte_size<1024>(byte_size{55555555}, iec) == "53 MiB");
snn_require(fmt::byte_size<1024>(byte_size{55555555}, iec_short) == "53 M");
snn_require(fmt::byte_size<1024>(byte_size{555555555}, iec) == "530 MiB");
snn_require(fmt::byte_size<1024>(byte_size{555555555}, iec_short) == "530 M");
snn_require(fmt::byte_size<1024>(byte_size{5555555555}, iec) == "5.2 GiB");
snn_require(fmt::byte_size<1024>(byte_size{5555555555}, iec_short) == "5.2 G");
snn_require(fmt::byte_size<1024>(byte_size{55555555555}, iec) == "52 GiB");
snn_require(fmt::byte_size<1024>(byte_size{55555555555}, iec_short) == "52 G");
snn_require(fmt::byte_size<1024>(byte_size{555555555555}, iec) == "517 GiB");
snn_require(fmt::byte_size<1024>(byte_size{555555555555}, iec_short) == "517 G");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555}, iec) == "5.1 TiB");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555}, iec_short) == "5.1 T");
snn_require(fmt::byte_size<1024>(byte_size{55555555555555}, iec) == "51 TiB");
snn_require(fmt::byte_size<1024>(byte_size{55555555555555}, iec_short) == "51 T");
snn_require(fmt::byte_size<1024>(byte_size{555555555555555}, iec) == "505 TiB");
snn_require(fmt::byte_size<1024>(byte_size{555555555555555}, iec_short) == "505 T");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555555}, iec) == "4.9 PiB");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555555}, iec_short) == "4.9 P");
snn_require(fmt::byte_size<1024>(byte_size{55555555555555555}, iec) == "49 PiB");
snn_require(fmt::byte_size<1024>(byte_size{55555555555555555}, iec_short) == "49 P");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555555555}, iec) == "4.8 EiB");
snn_require(fmt::byte_size<1024>(byte_size{5555555555555555555}, iec_short) == "4.8 E");
snn_require(fmt::byte_size<1024>(byte_size{9}, iec) == "9 B");
snn_require(fmt::byte_size<1024>(byte_size{9}, iec_short) == "9 B");
snn_require(fmt::byte_size<1024>(byte_size{99}, iec) == "99 B");
snn_require(fmt::byte_size<1024>(byte_size{99}, iec_short) == "99 B");
snn_require(fmt::byte_size<1024>(byte_size{999}, iec) == "999 B");
snn_require(fmt::byte_size<1024>(byte_size{999}, iec_short) == "999 B");
snn_require(fmt::byte_size<1024>(byte_size{9999}, iec) == "9.8 KiB");
snn_require(fmt::byte_size<1024>(byte_size{9999}, iec_short) == "9.8 K");
snn_require(fmt::byte_size<1024>(byte_size{99999}, iec) == "98 KiB");
snn_require(fmt::byte_size<1024>(byte_size{99999}, iec_short) == "98 K");
snn_require(fmt::byte_size<1024>(byte_size{999999}, iec) == "977 KiB");
snn_require(fmt::byte_size<1024>(byte_size{999999}, iec_short) == "977 K");
snn_require(fmt::byte_size<1024>(byte_size{9999999}, iec) == "9.5 MiB");
snn_require(fmt::byte_size<1024>(byte_size{9999999}, iec_short) == "9.5 M");
snn_require(fmt::byte_size<1024>(byte_size{99999999}, iec) == "95 MiB");
snn_require(fmt::byte_size<1024>(byte_size{99999999}, iec_short) == "95 M");
snn_require(fmt::byte_size<1024>(byte_size{999999999}, iec) == "954 MiB");
snn_require(fmt::byte_size<1024>(byte_size{999999999}, iec_short) == "954 M");
snn_require(fmt::byte_size<1024>(byte_size{9999999999}, iec) == "9.3 GiB");
snn_require(fmt::byte_size<1024>(byte_size{9999999999}, iec_short) == "9.3 G");
snn_require(fmt::byte_size<1024>(byte_size{99999999999}, iec) == "93 GiB");
snn_require(fmt::byte_size<1024>(byte_size{99999999999}, iec_short) == "93 G");
snn_require(fmt::byte_size<1024>(byte_size{999999999999}, iec) == "931 GiB");
snn_require(fmt::byte_size<1024>(byte_size{999999999999}, iec_short) == "931 G");
snn_require(fmt::byte_size<1024>(byte_size{9999999999999}, iec) == "9.1 TiB");
snn_require(fmt::byte_size<1024>(byte_size{9999999999999}, iec_short) == "9.1 T");
snn_require(fmt::byte_size<1024>(byte_size{99999999999999}, iec) == "91 TiB");
snn_require(fmt::byte_size<1024>(byte_size{99999999999999}, iec_short) == "91 T");
snn_require(fmt::byte_size<1024>(byte_size{999999999999999}, iec) == "909 TiB");
snn_require(fmt::byte_size<1024>(byte_size{999999999999999}, iec_short) == "909 T");
snn_require(fmt::byte_size<1024>(byte_size{9999999999999999}, iec) == "8.9 PiB");
snn_require(fmt::byte_size<1024>(byte_size{9999999999999999}, iec_short) == "8.9 P");
snn_require(fmt::byte_size<1024>(byte_size{99999999999999999}, iec) == "89 PiB");
snn_require(fmt::byte_size<1024>(byte_size{99999999999999999}, iec_short) == "89 P");
snn_require(fmt::byte_size<1024>(byte_size{9223372036854775807}, iec) == "8.0 EiB");
snn_require(fmt::byte_size<1024>(byte_size{9223372036854775807}, iec_short) == "8.0 E");
snn_require(fmt::byte_size<1024>(byte_size{1024}, iec) == "1.0 KiB");
snn_require(fmt::byte_size<1024>(byte_size{1024}, iec_short) == "1.0 K");
snn_require(fmt::byte_size<1024>(byte_size{1048576}, iec) == "1.0 MiB");
snn_require(fmt::byte_size<1024>(byte_size{1048576}, iec_short) == "1.0 M");
snn_require(fmt::byte_size<1024>(byte_size{1073741824}, iec) == "1.0 GiB");
snn_require(fmt::byte_size<1024>(byte_size{1073741824}, iec_short) == "1.0 G");
snn_require(fmt::byte_size<1024>(byte_size{1099511627776}, iec) == "1.0 TiB");
snn_require(fmt::byte_size<1024>(byte_size{1099511627776}, iec_short) == "1.0 T");
snn_require(fmt::byte_size<1024>(byte_size{1125899906842624}, iec) == "1.0 PiB");
snn_require(fmt::byte_size<1024>(byte_size{1125899906842624}, iec_short) == "1.0 P");
snn_require(fmt::byte_size<1024>(byte_size{1152921504606846976}, iec) == "1.0 EiB");
snn_require(fmt::byte_size<1024>(byte_size{1152921504606846976}, iec_short) == "1.0 E");
snn_require(fmt::byte_size<1024>(byte_size{1001}, iec) == "1.0 KiB");
snn_require(fmt::byte_size<1024>(byte_size{1001}, iec_short) == "1.0 K");
snn_require(fmt::byte_size<1024>(byte_size{1023}, iec) == "1.0 KiB");
snn_require(fmt::byte_size<1024>(byte_size{1023}, iec_short) == "1.0 K");
snn_require(fmt::byte_size<1024>(byte_size{1047552}, iec) == "1.0 MiB");
snn_require(fmt::byte_size<1024>(byte_size{1047552}, iec_short) == "1.0 M");
snn_require(fmt::byte_size<1024>(byte_size{1048575}, iec) == "1.0 MiB");
snn_require(fmt::byte_size<1024>(byte_size{1048575}, iec_short) == "1.0 M");
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_static_require(app::example());
snn_static_require(app::test_byte_size_generated());
snn_require(app::test_format_byte_size());
}
}