From 95e1cefb40af92149e306b653e7f9411d9d0b5ff Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 6 Jan 2017 15:19:41 -0800 Subject: [PATCH] eina: add test for all float/double util function. --- src/Makefile_Eina.am | 1 + src/tests/eina/eina_suite.c | 1 + src/tests/eina/eina_suite.x | 7 +++++ src/tests/eina/eina_test_util.c | 61 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/tests/eina/eina_test_util.c diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am index 967d023..56b1959 100644 --- a/src/Makefile_Eina.am +++ b/src/Makefile_Eina.am @@ -387,4 +387,5 @@ tests/eina/sample.gpx \ tests/eina/eina_suite.x \ lib/eina/eina_config.h.in \ tests/eina/eina_test_stringshare.c \ +tests/eina/eina_test_util.c \ $(bin_SCRIPTS) diff --git a/src/tests/eina/eina_suite.c b/src/tests/eina/eina_suite.c index 24719fe..5cb67f9 100644 --- a/src/tests/eina/eina_suite.c +++ b/src/tests/eina/eina_suite.c @@ -85,6 +85,7 @@ static const Efl_Test_Case etc[] = { { "SafePointer", eina_test_safepointer }, { "Slice", eina_test_slice }, { "Free Queue", eina_test_freeq }, + { "Util", eina_test_util }, { NULL, NULL } }; diff --git a/src/tests/eina/eina_suite.x b/src/tests/eina/eina_suite.x index 4c9274e..52d80c3 100644 --- a/src/tests/eina/eina_suite.x +++ b/src/tests/eina/eina_suite.x @@ -18,6 +18,7 @@ #define EINA_TEST_CODE #include "eina_test_stringshare.c" +#include "eina_test_util.c" #undef EINA_TEST_START #undef EINA_TEST_END @@ -37,4 +38,10 @@ eina_test_stringshare(TCase *tc) #include "eina_test_stringshare.c" } +static void +eina_test_util(TCase *tc) +{ +#include "eina_test_util.c" +} + #endif diff --git a/src/tests/eina/eina_test_util.c b/src/tests/eina/eina_test_util.c new file mode 100644 index 0000000..71680ba --- /dev/null +++ b/src/tests/eina/eina_test_util.c @@ -0,0 +1,61 @@ +/* EINA - EFL data type library + * Copyright (C) 2017 Cedric Bail + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; + * if not, see . + */ + +EINA_TEST_START(eina_util_fpx) +{ + double a = 42.42, b = 42.41; + float c = 7.654, d = 8.765; + + ck_assert_int_eq(eina_dbl_exact(a, b), EINA_FALSE); + ck_assert_int_eq(eina_dbl_exact(a, a), EINA_TRUE); + ck_assert_int_eq(eina_flt_exact(c, d), EINA_FALSE); + ck_assert_int_eq(eina_flt_exact(c, c), EINA_TRUE); + ck_assert_int_eq(eina_dbl_exact(a, c), EINA_FALSE); +} +EINA_TEST_END + +EINA_TEST_START(eina_util_fpeq) +{ + double a, b, c; + double d, e, f; + + a = 6.0 * 7.0 + 7.0; + b = 7.0 * 7.0; + c = a - 0.1; + + d = 6.0 * 7.0 + 7.0; + e = 7.0 * 7.0; + f = a - 0.1; + + ck_assert_int_ne(EINA_DBL_EQ(a, b), 0); + ck_assert_int_eq(EINA_DBL_EQ(a, c), 0); + ck_assert_int_ne(EINA_DBL_EQ(d, e), 0); + ck_assert_int_eq(EINA_DBL_EQ(d, f), 0); +} +EINA_TEST_END + +EINA_TEST_START(eina_util_fpz) +{ + ck_assert_int_eq(EINA_FLT_NONZERO(7.0 - 7.0), 0); + ck_assert_int_ne(EINA_FLT_NONZERO(7.1 - 7.0), 0); + ck_assert_int_eq(EINA_FLT_NONZERO(0.0), 0); + ck_assert_int_eq(EINA_DBL_NONZERO(7.0 - 7.0), 0); + ck_assert_int_ne(EINA_DBL_NONZERO(7.1 - 7.0), 0); + ck_assert_int_eq(EINA_DBL_NONZERO(0.0), 0); +} +EINA_TEST_END -- 2.7.4