diff options
author | Nico Weber <thakis@chromium.org> | 2023-04-29 15:15:19 -0400 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-04-30 00:46:11 +0200 |
commit | 5fc11a316f58c45062eb0a82e857f98d87f48bd8 (patch) | |
tree | b527855cfe46776400f62a11ec3e814a14b05e50 /Userland | |
parent | 72195ade9d0722eab639017378f43f9e1dd884dc (diff) | |
download | serenity-5fc11a316f58c45062eb0a82e857f98d87f48bd8.zip |
LibTest: Add a EXPECT_APPROXIMATE_WITH_ERROR macro with custom error
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibTest/Macros.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Libraries/LibTest/Macros.h b/Userland/Libraries/LibTest/Macros.h index dff131fccc..ee500be688 100644 --- a/Userland/Libraries/LibTest/Macros.h +++ b/Userland/Libraries/LibTest/Macros.h @@ -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); \ |