Skip to content

Commit b80067d

Browse files
committed
add tests with different word sizes
1 parent 54270bc commit b80067d

File tree

1 file changed

+76
-20
lines changed

1 file changed

+76
-20
lines changed

libc/test/src/__support/integer_to_string_test.cpp

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -299,46 +299,102 @@ TEST(LlvmLibcIntegerToStringTest, Sign) {
299299
}
300300

301301
TEST(LlvmLibcIntegerToStringTest, BigInt_Base_10) {
302-
uint64_t uint256_max[4] = {
303-
0xFFFFFFFFFFFFFFFF,
304-
0xFFFFFFFFFFFFFFFF,
305-
0xFFFFFFFFFFFFFFFF,
306-
0xFFFFFFFFFFFFFFFF,
307-
};
308-
uint64_t int256_max[4] = {
302+
uint64_t int256_max_w64[4] = {
309303
0xFFFFFFFFFFFFFFFF,
310304
0xFFFFFFFFFFFFFFFF,
311305
0xFFFFFFFFFFFFFFFF,
312306
0x7FFFFFFFFFFFFFFF,
313307
};
314-
uint64_t int256_min[4] = {
308+
uint64_t int256_min_w64[4] = {
315309
0,
316310
0,
317311
0,
318312
0x8000000000000000,
319313
};
314+
uint32_t int256_max_w32[8] = {
315+
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
316+
0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF,
317+
};
318+
uint32_t int256_min_w32[8] = {
319+
0, 0, 0, 0, 0, 0, 0, 0x80000000,
320+
};
321+
uint16_t int256_max_w16[16] = {
322+
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
323+
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x7FFF,
324+
};
325+
uint16_t int256_min_w16[16] = {
326+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x8000,
327+
};
320328

321-
using unsigned_type = IntegerToString<BigInt<256, false>, Dec>;
322-
EXPECT(unsigned_type, 0, "0");
323-
EXPECT(unsigned_type, 1, "1");
324-
EXPECT(unsigned_type, uint256_max,
329+
using unsigned_type_w64 = IntegerToString<BigInt<256, false, uint64_t>, Dec>;
330+
EXPECT(unsigned_type_w64, 0, "0");
331+
EXPECT(unsigned_type_w64, 1, "1");
332+
EXPECT(unsigned_type_w64, -1,
325333
"115792089237316195423570985008687907853269984665640564039457584007913"
326334
"129639935");
327-
EXPECT(unsigned_type, int256_max,
335+
EXPECT(unsigned_type_w64, int256_max_w64,
328336
"578960446186580977117854925043439539266349923328202820197287920039565"
329337
"64819967");
330-
EXPECT(unsigned_type, int256_min,
338+
EXPECT(unsigned_type_w64, int256_min_w64,
331339
"578960446186580977117854925043439539266349923328202820197287920039565"
332340
"64819968");
333341

334-
using signed_type = IntegerToString<BigInt<256, true>, Dec>;
335-
EXPECT(signed_type, 0, "0");
336-
EXPECT(signed_type, 1, "1");
337-
EXPECT(signed_type, uint256_max, "-1");
338-
EXPECT(signed_type, int256_max,
342+
using unsigned_type_w32 = IntegerToString<BigInt<256, false, uint32_t>, Dec>;
343+
EXPECT(unsigned_type_w32, 0, "0");
344+
EXPECT(unsigned_type_w32, 1, "1");
345+
EXPECT(unsigned_type_w32, -1,
346+
"115792089237316195423570985008687907853269984665640564039457584007913"
347+
"129639935");
348+
EXPECT(unsigned_type_w32, int256_max_w32,
349+
"578960446186580977117854925043439539266349923328202820197287920039565"
350+
"64819967");
351+
EXPECT(unsigned_type_w32, int256_min_w32,
352+
"578960446186580977117854925043439539266349923328202820197287920039565"
353+
"64819968");
354+
355+
using unsigned_type_w16 = IntegerToString<BigInt<256, false, uint16_t>, Dec>;
356+
EXPECT(unsigned_type_w16, 0, "0");
357+
EXPECT(unsigned_type_w16, 1, "1");
358+
EXPECT(unsigned_type_w16, -1,
359+
"115792089237316195423570985008687907853269984665640564039457584007913"
360+
"129639935");
361+
EXPECT(unsigned_type_w16, int256_max_w16,
362+
"578960446186580977117854925043439539266349923328202820197287920039565"
363+
"64819967");
364+
EXPECT(unsigned_type_w16, int256_min_w16,
365+
"578960446186580977117854925043439539266349923328202820197287920039565"
366+
"64819968");
367+
368+
using signed_type_w64 = IntegerToString<BigInt<256, true, uint64_t>, Dec>;
369+
EXPECT(signed_type_w64, 0, "0");
370+
EXPECT(signed_type_w64, 1, "1");
371+
EXPECT(signed_type_w64, -1, "-1");
372+
EXPECT(signed_type_w64, int256_max_w64,
373+
"578960446186580977117854925043439539266349923328202820197287920039565"
374+
"64819967");
375+
EXPECT(signed_type_w64, int256_min_w64,
376+
"-57896044618658097711785492504343953926634992332820282019728792003956"
377+
"564819968");
378+
379+
using signed_type_w32 = IntegerToString<BigInt<256, true, uint32_t>, Dec>;
380+
EXPECT(signed_type_w32, 0, "0");
381+
EXPECT(signed_type_w32, 1, "1");
382+
EXPECT(signed_type_w32, -1, "-1");
383+
EXPECT(signed_type_w32, int256_max_w32,
384+
"578960446186580977117854925043439539266349923328202820197287920039565"
385+
"64819967");
386+
EXPECT(signed_type_w32, int256_min_w32,
387+
"-57896044618658097711785492504343953926634992332820282019728792003956"
388+
"564819968");
389+
390+
using signed_type_w16 = IntegerToString<BigInt<256, true, uint16_t>, Dec>;
391+
EXPECT(signed_type_w16, 0, "0");
392+
EXPECT(signed_type_w16, 1, "1");
393+
EXPECT(signed_type_w16, -1, "-1");
394+
EXPECT(signed_type_w16, int256_max_w16,
339395
"578960446186580977117854925043439539266349923328202820197287920039565"
340396
"64819967");
341-
EXPECT(signed_type, int256_min,
397+
EXPECT(signed_type_w16, int256_min_w16,
342398
"-57896044618658097711785492504343953926634992332820282019728792003956"
343399
"564819968");
344400
}

0 commit comments

Comments
 (0)