From b374282e23a1811088aff88fe494f4293484b49e Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Mon, 29 May 2023 23:36:33 +0800 Subject: [PATCH] test: add math test for cubic-bezier function Signed-off-by: Neo Xu --- tests/src/test_cases/test_math.c | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/src/test_cases/test_math.c diff --git a/tests/src/test_cases/test_math.c b/tests/src/test_cases/test_math.c new file mode 100644 index 000000000..f5f8af1ac --- /dev/null +++ b/tests/src/test_cases/test_math.c @@ -0,0 +1,37 @@ +#if LV_BUILD_TEST +#include "../lvgl.h" + +#include "unity/unity.h" + +void test_math_cubic_bezier_result_should_be_precise(void) +{ + int32_t x, x1, y1, x2, y2, y; + int i = 0; + while(i++ < 10000) { + x1 = lv_rand(0, 1024); + x2 = lv_rand(0, 1024); + y1 = lv_rand(0, 1024); + y2 = lv_rand(0, 1024); + float fx1 = x1 / 1024.f; + float fx2 = x2 / 1024.f; + float fy1 = y1 / 1024.f; + float fy2 = y2 / 1024.f; + float fx, fy; + + int j = 0; + while(j++ < 100000) { + x = lv_rand(0, 1024); + y = lv_cubic_bezier(x, x1, y1, x2, y2); + fx = x / 1024.f; + fy = lv_cubic_bezier_f(fx, fx1, fy1, fx2, fy2); +#if 1 + if (LV_ABS(fy * 1024 - y) > 250) { + printf("x, x1, y1, x2, y2: %d,%d,%d,%d,%d\n", (int)x, (int)x1, (int)y1, (int)x2, (int)y2); + } +#endif + TEST_ASSERT_LESS_OR_EQUAL(250, LV_ABS(fy * 1024 - y)); + } + } +} + +#endif