mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
AK+Tests: Test Checked for main functionality
This commit is contained in:
parent
6f668ca3a4
commit
90c070cb1d
Notes:
sideshowbarker
2024-07-18 21:48:30 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/90c070cb1d9 Pull-request: https://github.com/SerenityOS/serenity/pull/5323 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo
1 changed files with 23 additions and 0 deletions
|
@ -95,6 +95,29 @@ TEST_CASE(operator_arith)
|
|||
EXPECT_EQ(b / a, 28);
|
||||
}
|
||||
|
||||
TEST_CASE(detects_signed_overflow)
|
||||
{
|
||||
EXPECT(!(Checked<int>(0x40000000) + Checked<int>(0x3fffffff)).has_overflow());
|
||||
EXPECT((Checked<int>(0x40000000) + Checked<int>(0x40000000)).has_overflow());
|
||||
EXPECT(!(Checked<int>(-0x40000000) + Checked<int>(-0x40000000)).has_overflow());
|
||||
EXPECT((Checked<int>(-0x40000001) + Checked<int>(-0x40000000)).has_overflow());
|
||||
|
||||
EXPECT(!(Checked<int>(0x40000000) - Checked<int>(-0x3fffffff)).has_overflow());
|
||||
EXPECT((Checked<int>(0x40000000) - Checked<int>(-0x40000000)).has_overflow());
|
||||
EXPECT(!(Checked<int>(-0x40000000) - Checked<int>(0x40000000)).has_overflow());
|
||||
EXPECT((Checked<int>(-0x40000000) - Checked<int>(0x40000001)).has_overflow());
|
||||
|
||||
EXPECT(!(Checked<i64>(0x4000000000000000) + Checked<i64>(0x3fffffffffffffff)).has_overflow());
|
||||
EXPECT((Checked<i64>(0x4000000000000000) + Checked<i64>(0x4000000000000000)).has_overflow());
|
||||
EXPECT(!(Checked<i64>(-0x4000000000000000) + Checked<i64>(-0x4000000000000000)).has_overflow());
|
||||
EXPECT((Checked<i64>(-0x4000000000000001) + Checked<i64>(-0x4000000000000000)).has_overflow());
|
||||
|
||||
EXPECT(!(Checked<i64>(0x4000000000000000) - Checked<i64>(-0x3fffffffffffffff)).has_overflow());
|
||||
EXPECT((Checked<i64>(0x4000000000000000) - Checked<i64>(-0x4000000000000000)).has_overflow());
|
||||
EXPECT(!(Checked<i64>(-0x4000000000000000) - Checked<i64>(0x4000000000000000)).has_overflow());
|
||||
EXPECT((Checked<i64>(-0x4000000000000000) - Checked<i64>(0x4000000000000001)).has_overflow());
|
||||
}
|
||||
|
||||
TEST_CASE(should_constexpr_default_construct)
|
||||
{
|
||||
constexpr Checked<int> checked_value {};
|
||||
|
|
Loading…
Add table
Reference in a new issue