Skip to content

Commit 1539375

Browse files
committed
Fix bigint integer cast
1 parent 3bfe437 commit 1539375

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/corelib/src/utility/bigint_tests.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,47 @@ TEST_CASE("bigint operations")
422422
CHECK(expected == b);
423423
}
424424
}
425+
426+
TEST_CASE("bigint cast")
427+
{
428+
SECTION("to short")
429+
{
430+
bigint b{(std::numeric_limits<short>::lowest)()};
431+
auto val = (short)b;
432+
CHECK((std::numeric_limits<short>::lowest)() == val);
433+
}
434+
SECTION("to int")
435+
{
436+
bigint b{(std::numeric_limits<int>::lowest)()};
437+
auto val = (int)b;
438+
CHECK((std::numeric_limits<int>::lowest)() == val);
439+
}
440+
SECTION("to long")
441+
{
442+
bigint b{(std::numeric_limits<long>::lowest)()};
443+
auto val = (long)b;
444+
CHECK((std::numeric_limits<long>::lowest)() == val);
445+
}
446+
SECTION("to long long")
447+
{
448+
bigint b{(std::numeric_limits<long long>::max)()};
449+
auto val = (long long)b;
450+
CHECK((std::numeric_limits<long long>::max)() == val);
451+
}
452+
SECTION("to unsigned long")
453+
{
454+
bigint b{(std::numeric_limits<unsigned long>::max)()};
455+
auto val = (unsigned long)b;
456+
CHECK((std::numeric_limits<unsigned long>::max)() == val);
457+
}
458+
SECTION("to unsigned long long")
459+
{
460+
bigint b{(std::numeric_limits<unsigned long long>::max)()};
461+
auto val = (unsigned long long)b;
462+
CHECK((std::numeric_limits<unsigned long long>::max)() == val);
463+
}
464+
}
465+
425466
TEST_CASE("https://github.com/rgroshanrg/bigint SampleTest.cpp")
426467
{
427468
bigint a("56654250564056135415631554531554513813");

0 commit comments

Comments
 (0)