From fdaf344253d7314cb2c3534560851e75672221bc Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Thu, 1 Feb 2024 20:10:50 +0000
Subject: [PATCH] test: Don't accept results that are much less than expected
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
While looking at the other tests in this file, I noticed that instead
of checking for a result in the range of expected ± FLT_EPSILON as I
would have expected, these tests would accept any result strictly less
than expected + FLT_EPSILON, for example a wrong result that is very
large and negative. This is presumably not what was intended, so add
the SDL_fabs() that I assume was meant to be here.
Fixes: 474c8d00 "testautomation: don't do float equality tests"
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
test/testautomation_math.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/testautomation_math.c b/test/testautomation_math.c
index ef9b40b..faf1bc3 100644
--- a/test/testautomation_math.c
+++ b/test/testautomation_math.c
@@ -82,7 +82,7 @@ helper_dtod(const char *func_name, d_to_d_func func,
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].input);
- SDLTest_AssertCheck((result - cases[i].expected) < FLT_EPSILON,
+ SDLTest_AssertCheck(SDL_fabs(result - cases[i].expected) < FLT_EPSILON,
"%s(%f), expected %f, got %f",
func_name,
cases[i].input,
@@ -1161,7 +1161,7 @@ log_baseCases(void *args)
1.0, 0.0, result);
result = SDL_log(EULER);
- SDLTest_AssertCheck((result - 1.) < FLT_EPSILON,
+ SDLTest_AssertCheck(SDL_fabs(result - 1.) < FLT_EPSILON,
"Log(%f), expected %f, got %f",
EULER, 1.0, result);