From 3aa4bf34cf1f8a710764bfd35849c2474589bf2e Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Wed, 9 Apr 2025 12:35:16 -0400 Subject: pke-test: compare floats using epsilon --- tests/pke-test-static-ui.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'tests/pke-test-static-ui.cpp') diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp index 9ca4cdd..410f290 100644 --- a/tests/pke-test-static-ui.cpp +++ b/tests/pke-test-static-ui.cpp @@ -1,9 +1,12 @@ #include "./pke-test-static-ui.h" +#include "./pke-test-types.h" + #include "window.hpp" #include "dynamic-array.hpp" #include "vendor-glm-include.hpp" +#include struct pke_ui_box_instance_buffer_item { glm::mat4 pos_scale; glm::vec2 px_scale; @@ -74,6 +77,7 @@ int pke_test_static_ui_000() { // test dynamic int pke_test_static_ui_100() { DynArray arr{}; + bool b; float unit; float calculated_offset_x, calculated_offset_y; uint8_t err_index = 0; @@ -116,11 +120,16 @@ int pke_test_static_ui_100() { PKE_TEST_ASSERT(ui_box->internal.px_size.x == (Extent.width * 0.1) * 8, err_index); PKE_TEST_ASSERT(ui_box->internal.px_size.y == (Extent.height * 0.1) * 8, err_index); - // TODO rounding? - // using a debugger, the actual and calculated values are ~0.01 off - // this is either a real issue or a rounding issue, either here or within pke - PKE_TEST_ASSERT(c_ui_box->internal.px_size.x == (ui_box->internal.px_size.x - (built_in_offset * 2)) * 0.8, err_index); - PKE_TEST_ASSERT(c_ui_box->internal.px_size.y == (ui_box->internal.px_size.y - (built_in_offset * 2)) * 0.8, err_index); + b = flt_equal( + c_ui_box->internal.px_size.x, + (ui_box->internal.px_size.x - (built_in_offset * 2)) * 0.8, + std::numeric_limits::epsilon()); + PKE_TEST_ASSERT(b, err_index); + b = flt_equal( + c_ui_box->internal.px_size.y, + (ui_box->internal.px_size.y - (built_in_offset * 2)) * 0.8, + std::numeric_limits::epsilon()); + PKE_TEST_ASSERT(b, err_index); return 0; } -- cgit v1.2.3