mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
AK+LibM: Make EXPECT_CLOSE more useful during debugging
This commit is contained in:
parent
9b27b0cd1a
commit
5df014b8ff
Notes:
sideshowbarker
2024-07-18 21:45:10 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/5df014b8ff6 Pull-request: https://github.com/SerenityOS/serenity/pull/5615
2 changed files with 27 additions and 19 deletions
|
@ -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)
|
||||
|
|
|
@ -28,17 +28,12 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
#define EXPECT_CLOSE(a, b) \
|
||||
{ \
|
||||
EXPECT(fabs(a - b) < 0.000001); \
|
||||
}
|
||||
|
||||
TEST_CASE(trig)
|
||||
{
|
||||
EXPECT_CLOSE(sin(1234), 0.601927);
|
||||
EXPECT_CLOSE(cos(1234), -0.798550);
|
||||
EXPECT_CLOSE(tan(1234), -0.753775);
|
||||
EXPECT_CLOSE(sqrt(1234), 35.128336)
|
||||
EXPECT_CLOSE(sqrt(1234), 35.128336);
|
||||
EXPECT_CLOSE(sin(-1), -0.8414709848078965);
|
||||
EXPECT_CLOSE(cos(-1), 0.5403023058681398);
|
||||
EXPECT_CLOSE(tan(-1), -1.5574077246549023);
|
||||
|
@ -55,12 +50,12 @@ TEST_CASE(trig)
|
|||
EXPECT_CLOSE(asin(0.9), 1.119770);
|
||||
EXPECT_CLOSE(asin(0.99), 1.429245);
|
||||
EXPECT_CLOSE(asin(1.0), 1.570750);
|
||||
EXPECT_CLOSE(atan(0), 0.0)
|
||||
EXPECT_CLOSE(atan(0.5), 0.463648)
|
||||
EXPECT_CLOSE(atan(-0.5), -0.463648)
|
||||
EXPECT_CLOSE(atan(5.5), 1.390943)
|
||||
EXPECT_CLOSE(atan(-5.5), -1.390943)
|
||||
EXPECT_CLOSE(atan(555.5), 1.568996)
|
||||
EXPECT_CLOSE(atan(0), 0.0);
|
||||
EXPECT_CLOSE(atan(0.5), 0.463648);
|
||||
EXPECT_CLOSE(atan(-0.5), -0.463648);
|
||||
EXPECT_CLOSE(atan(5.5), 1.390943);
|
||||
EXPECT_CLOSE(atan(-5.5), -1.390943);
|
||||
EXPECT_CLOSE(atan(555.5), 1.568996);
|
||||
}
|
||||
|
||||
TEST_CASE(other)
|
||||
|
@ -102,13 +97,13 @@ TEST_CASE(logarithms)
|
|||
{
|
||||
EXPECT(isnan(log(-1)));
|
||||
EXPECT(log(0) < -1000000);
|
||||
EXPECT_CLOSE(log(0.5), -0.693233)
|
||||
EXPECT_CLOSE(log(1.1), 0.095310)
|
||||
EXPECT_CLOSE(log(5), 1.609480)
|
||||
EXPECT_CLOSE(log(5.5), 1.704842)
|
||||
EXPECT_CLOSE(log(500), 6.214104)
|
||||
EXPECT_CLOSE(log2(5), 2.321989)
|
||||
EXPECT_CLOSE(log10(5), 0.698988)
|
||||
EXPECT_CLOSE(log(0.5), -0.693233);
|
||||
EXPECT_CLOSE(log(1.1), 0.095310);
|
||||
EXPECT_CLOSE(log(5), 1.609480);
|
||||
EXPECT_CLOSE(log(5.5), 1.704842);
|
||||
EXPECT_CLOSE(log(500), 6.214104);
|
||||
EXPECT_CLOSE(log2(5), 2.321989);
|
||||
EXPECT_CLOSE(log10(5), 0.698988);
|
||||
}
|
||||
|
||||
union Extractor {
|
||||
|
|
Loading…
Add table
Reference in a new issue