mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibTest: Add a EXPECT_APPROXIMATE_WITH_ERROR macro with custom error
This commit is contained in:
parent
72195ade9d
commit
5fc11a316f
1 changed files with 4 additions and 2 deletions
|
@ -98,12 +98,12 @@ void current_test_case_did_fail();
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
#define EXPECT_APPROXIMATE(a, b) \
|
||||
#define EXPECT_APPROXIMATE_WITH_ERROR(a, b, err) \
|
||||
do { \
|
||||
auto expect_close_lhs = a; \
|
||||
auto expect_close_rhs = b; \
|
||||
auto expect_close_diff = static_cast<double>(expect_close_lhs) - static_cast<double>(expect_close_rhs); \
|
||||
if (AK::fabs(expect_close_diff) > 0.0000005) { \
|
||||
if (AK::fabs(expect_close_diff) > (err)) { \
|
||||
::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: EXPECT_APPROXIMATE({}, {})" \
|
||||
" failed with lhs={}, rhs={}, (lhs-rhs)={}", \
|
||||
__FILE__, __LINE__, #a, #b, expect_close_lhs, expect_close_rhs, expect_close_diff); \
|
||||
|
@ -111,6 +111,8 @@ void current_test_case_did_fail();
|
|||
} \
|
||||
} while (false)
|
||||
|
||||
#define EXPECT_APPROXIMATE(a, b) EXPECT_APPROXIMATE_WITH_ERROR(a, b, 0.0000005)
|
||||
|
||||
#define FAIL(message) \
|
||||
do { \
|
||||
::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: {}", __FILE__, __LINE__, message); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue