From 2d1f993d259d7797deeeec862f7d29d4befcff28 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 14 Oct 2023 20:43:39 +0200 Subject: [PATCH] totalorder* tests: Verify also the function signatures. * tests/test-totalorder.h: New file, based on tests/test-totalorder.c. * tests/test-totalorder.c: Check the signature. Include test-totalorder.h for the rest. * tests/test-totalorderf.c: Include , . Check the signature. Include test-totalorder.h instead of test-totalorder.c. * tests/test-totalorderl.c: Likewise. * modules/totalorder-tests (Files): Add test-totalorder.h, signature.h. * modules/totalorderf-tests (Files): Add test-totalorder.h, signature.h. Remove test-totalorder.c. * modules/totalorderl-tests (Files): Likewise. --- ChangeLog | 14 ++++++++++++++ modules/totalorder-tests | 2 ++ modules/totalorderf-tests | 3 ++- modules/totalorderl-tests | 3 ++- tests/test-totalorder.c | 39 ++++++++++----------------------------- tests/test-totalorder.h | 37 +++++++++++++++++++++++++++++++++++++ tests/test-totalorderf.c | 28 ++++++++++++++++++++++++++-- tests/test-totalorderl.c | 28 ++++++++++++++++++++++++++-- 8 files changed, 119 insertions(+), 35 deletions(-) create mode 100644 tests/test-totalorder.h diff --git a/ChangeLog b/ChangeLog index 40b2116a88..db5cd18148 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2023-10-14 Bruno Haible + + totalorder* tests: Verify also the function signatures. + * tests/test-totalorder.h: New file, based on tests/test-totalorder.c. + * tests/test-totalorder.c: Check the signature. Include + test-totalorder.h for the rest. + * tests/test-totalorderf.c: Include , . Check the + signature. Include test-totalorder.h instead of test-totalorder.c. + * tests/test-totalorderl.c: Likewise. + * modules/totalorder-tests (Files): Add test-totalorder.h, signature.h. + * modules/totalorderf-tests (Files): Add test-totalorder.h, signature.h. + Remove test-totalorder.c. + * modules/totalorderl-tests (Files): Likewise. + 2023-10-14 Bruno Haible totalorder*: Improve documentation. diff --git a/modules/totalorder-tests b/modules/totalorder-tests index 3741b88d4c..2035acd697 100644 --- a/modules/totalorder-tests +++ b/modules/totalorder-tests @@ -1,7 +1,9 @@ Files: tests/test-totalorder.c +tests/test-totalorder.h tests/minus-zero.h tests/infinity.h +tests/signature.h tests/macros.h Depends-on: diff --git a/modules/totalorderf-tests b/modules/totalorderf-tests index f2801f496f..5fb1cc8225 100644 --- a/modules/totalorderf-tests +++ b/modules/totalorderf-tests @@ -1,8 +1,9 @@ Files: tests/test-totalorderf.c -tests/test-totalorder.c +tests/test-totalorder.h tests/minus-zero.h tests/infinity.h +tests/signature.h tests/macros.h Depends-on: diff --git a/modules/totalorderl-tests b/modules/totalorderl-tests index fa25c3e301..85d1768dfc 100644 --- a/modules/totalorderl-tests +++ b/modules/totalorderl-tests @@ -1,8 +1,9 @@ Files: tests/test-totalorderl.c -tests/test-totalorder.c +tests/test-totalorder.h tests/minus-zero.h tests/infinity.h +tests/signature.h tests/macros.h Depends-on: diff --git a/tests/test-totalorder.c b/tests/test-totalorder.c index af903c68b5..2b50b8d437 100644 --- a/tests/test-totalorder.c +++ b/tests/test-totalorder.c @@ -16,35 +16,16 @@ #include +/* Specification. */ #include -#include "infinity.h" -#include "macros.h" -#include "minus-zero.h" -#include "signed-nan.h" +#include "signature.h" +SIGNATURE_CHECK (totalorderf, int, (const float *, const float *)); -#ifndef TOTALORDER -# define TOTALORDER totalorder -# define TOTALORDER_INF Infinityd -# define TOTALORDER_MINUS_ZERO minus_zerod -# define TOTALORDER_POSITIVE_NAN positive_NaNd -# define TOTALORDER_NEGATIVE_NAN negative_NaNd -# define TOTALORDER_TYPE double -#endif - -int -main () -{ - TOTALORDER_TYPE x[] = - { - TOTALORDER_NEGATIVE_NAN (), -TOTALORDER_INF (), -1e37, -1, -1e-5, - TOTALORDER_MINUS_ZERO, 0, - 1e-5, 1, 1e37, TOTALORDER_INF (), TOTALORDER_POSITIVE_NAN () - }; - int n = sizeof x / sizeof *x; - - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - ASSERT (!!TOTALORDER (&x[i], &x[j]) == (i <= j)); - return 0; -} +#define TOTALORDER totalorder +#define TOTALORDER_TYPE double +#define TOTALORDER_INF Infinityd +#define TOTALORDER_MINUS_ZERO minus_zerod +#define TOTALORDER_POSITIVE_NAN positive_NaNd +#define TOTALORDER_NEGATIVE_NAN negative_NaNd +#include "test-totalorder.h" diff --git a/tests/test-totalorder.h b/tests/test-totalorder.h new file mode 100644 index 0000000000..2405e49edf --- /dev/null +++ b/tests/test-totalorder.h @@ -0,0 +1,37 @@ +/* Test a totalorder-like function. + Copyright 2023 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 "infinity.h" +#include "macros.h" +#include "minus-zero.h" +#include "signed-nan.h" + +int +main () +{ + TOTALORDER_TYPE x[] = + { + TOTALORDER_NEGATIVE_NAN (), -TOTALORDER_INF (), -1e37, -1, -1e-5, + TOTALORDER_MINUS_ZERO, 0, + 1e-5, 1, 1e37, TOTALORDER_INF (), TOTALORDER_POSITIVE_NAN () + }; + int n = sizeof x / sizeof *x; + + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + ASSERT (!!TOTALORDER (&x[i], &x[j]) == (i <= j)); + return 0; +} diff --git a/tests/test-totalorderf.c b/tests/test-totalorderf.c index 5fd27031c0..6d921dd103 100644 --- a/tests/test-totalorderf.c +++ b/tests/test-totalorderf.c @@ -1,7 +1,31 @@ +/* Test totalorderf. + Copyright 2023 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 (totalorderf, int, (const float *, const float *)); + #define TOTALORDER totalorderf +#define TOTALORDER_TYPE float #define TOTALORDER_INF Infinityf #define TOTALORDER_MINUS_ZERO minus_zerof #define TOTALORDER_POSITIVE_NAN positive_NaNf #define TOTALORDER_NEGATIVE_NAN negative_NaNf -#define TOTALORDER_TYPE float -#include "test-totalorder.c" +#include "test-totalorder.h" diff --git a/tests/test-totalorderl.c b/tests/test-totalorderl.c index c8f1fbd4b6..89df547fc5 100644 --- a/tests/test-totalorderl.c +++ b/tests/test-totalorderl.c @@ -1,7 +1,31 @@ +/* Test totalorderl. + Copyright 2023 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 (totalorderl, int, (const long double *, const long double *)); + #define TOTALORDER totalorderl +#define TOTALORDER_TYPE long double #define TOTALORDER_INF Infinityl #define TOTALORDER_MINUS_ZERO minus_zerol #define TOTALORDER_POSITIVE_NAN positive_NaNl #define TOTALORDER_NEGATIVE_NAN negative_NaNl -#define TOTALORDER_TYPE long double -#include "test-totalorder.c" +#include "test-totalorder.h" -- 2.39.5