usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-totalorder.h
blobef8c6b121d3a49d310bca5239cc60f5d1314d7c4
1 /* Test a totalorder-like function.
2 Copyright 2023-2024 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <stdio.h>
19 /* Specification. */
20 #include <math.h>
22 #if defined __IBMC__
23 /* The IBM XL C compiler cannot compile the initializer of x[] below. */
25 # include <stdio.h>
27 int
28 main ()
30 fputs ("Skipping test: broken C compiler\n", stderr);
31 return 77;
34 #else
36 # include "infinity.h"
37 # include "macros.h"
38 # include "minus-zero.h"
39 # include "signed-nan.h"
40 # include "signed-snan.h"
42 static TOTALORDER_TYPE
43 positive_NaN_with_payload (int payload)
45 TOTALORDER_TYPE x;
46 ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0);
47 return x;
50 static TOTALORDER_TYPE
51 negative_NaN_with_payload (int payload)
53 TOTALORDER_TYPE x;
54 ASSERT (TOTALORDER_SETPAYLOAD (&x.value, payload) == 0);
55 x.value = TOTALORDER_MINUS (x.value);
56 return x;
59 int
60 main ()
62 TOTALORDER_TYPE x[] =
64 negative_NaN_with_payload (1729),
65 negative_NaN_with_payload (641),
66 # if TOTALORDER_HAVE_SNAN
67 TOTALORDER_NEGATIVE_SNAN (),
68 # endif
69 { -TOTALORDER_INF () },
70 { -1e37 },
71 { -1 },
72 { -1e-5 },
73 { TOTALORDER_MINUS_ZERO },
74 { 0 },
75 { 1e-5 },
76 { 1 },
77 { 1e37 },
78 { TOTALORDER_INF () },
79 # if TOTALORDER_HAVE_SNAN
80 TOTALORDER_POSITIVE_SNAN (),
81 # endif
82 positive_NaN_with_payload (641),
83 positive_NaN_with_payload (1729)
85 int n = SIZEOF (x);
87 for (int i = 0; i < n; i++)
88 for (int j = 0; j < n; j++)
89 if (!(!!TOTALORDER (&x[i].value, &x[j].value) == (i <= j)))
91 fprintf (stderr, "Failed: i=%d j=%d\n", i, j);
92 test_exit_status = EXIT_FAILURE;
95 return test_exit_status;
98 #endif