From 86400484d7e4af4b42df08e8999cfdae77d90d69 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 16 Apr 2024 14:40:37 +0200 Subject: [PATCH] setpayloadf: Add tests. * tests/test-setpayloadf.c: New file. * modules/setpayloadf-tests: New file. --- ChangeLog | 4 ++ modules/setpayloadf-tests | 15 +++++++ tests/test-setpayloadf.c | 86 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 modules/setpayloadf-tests create mode 100644 tests/test-setpayloadf.c diff --git a/ChangeLog b/ChangeLog index 9640eb8ef1..1a5dbdf669 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-04-16 Bruno Haible + setpayloadf: Add tests. + * tests/test-setpayloadf.c: New file. + * modules/setpayloadf-tests: New file. + setpayloadf: New module. * lib/math.in.h (setpayloadf): New declaration. * lib/setpayloadf.c: New file. diff --git a/modules/setpayloadf-tests b/modules/setpayloadf-tests new file mode 100644 index 0000000000..75cda25d33 --- /dev/null +++ b/modules/setpayloadf-tests @@ -0,0 +1,15 @@ +Files: +tests/test-setpayloadf.c +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +isnanf-nolibm + +configure.ac: + +Makefile.am: +TESTS += test-setpayloadf +check_PROGRAMS += test-setpayloadf +test_setpayloadf_LDADD = $(LDADD) @SETPAYLOADF_LIBM@ diff --git a/tests/test-setpayloadf.c b/tests/test-setpayloadf.c new file mode 100644 index 0000000000..aa790343ae --- /dev/null +++ b/tests/test-setpayloadf.c @@ -0,0 +1,86 @@ +/* Test setpayloadf. + Copyright 2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (setpayloadf, int, (float *, float)); + +#include "infinity.h" +#include "isnanf-nolibm.h" +#include "macros.h" + +int +main () +{ + int i; + float p; + + { + /* Test valid payloads. */ + for (i = 0, p = 1.0f; i < 24 - 2; i++, p *= 2.0f) + { + int ret; + float x; + + ret = setpayloadf (&x, p); + ASSERT (ret == 0); + ASSERT (isnanf (x)); + } + /* Test out-of-range payload. */ + int ret; + float x; + + ret = setpayloadf (&x, p); + ASSERT (ret != 0); + ASSERT (x == 0.0f); + } + + /* Test infinite payload. */ + { + int ret; + float x; + + ret = setpayloadf (&x, Infinityf ()); + ASSERT (ret != 0); + ASSERT (x == 0.0f); + } + + /* Test negative payload. */ + { + int ret; + float x; + + ret = setpayloadf (&x, -1.0f); + ASSERT (ret != 0); + ASSERT (x == 0.0f); + } + + /* Test fractional payload. */ + { + int ret; + float x; + + ret = setpayloadf (&x, 1.4f); + ASSERT (ret != 0); + ASSERT (x == 0.0f); + } + + return 0; +} -- 2.39.5