1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

AK+LibM: Make EXPECT_CLOSE more useful during debugging

This commit is contained in:
Ben Wiederhake 2021-03-02 20:33:44 +01:00 committed by Andreas Kling
parent 9b27b0cd1a
commit 5df014b8ff
2 changed files with 27 additions and 19 deletions

View file

@ -324,3 +324,16 @@ using AK::TestSuite;
current_test_case_did_fail(); \
} \
} while (false)
#define EXPECT_CLOSE(a, b) \
do { \
auto expect_close_lhs = a; \
auto expect_close_rhs = b; \
auto expect_close_diff = expect_close_lhs - expect_close_rhs; \
if (fabs(expect_close_diff) >= 0.000001) { \
warnln("\033[31;1mFAIL\033[0m: {}:{}: EXPECT_CLOSE({}, {})" \
" failed with lhs={}, rhs={}, (lhs-rhs)={}", \
__FILE__, __LINE__, #a, #b, expect_close_lhs, expect_close_rhs, expect_close_diff); \
current_test_case_did_fail(); \
} \
} while (false)