summaryrefslogtreecommitdiff
path: root/tests/ttotal_order.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-03-24 01:34:17 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-03-24 01:34:17 +0000
commit8db88f3bcd2eb58f7e11d15e79b49869ea2e646b (patch)
tree643a060c75021755b003aa408e79ada744102215 /tests/ttotal_order.c
parentc3a432c61175dbb9b790135429f92a7b81eb7ccf (diff)
downloadmpfr-8db88f3bcd2eb58f7e11d15e79b49869ea2e646b.tar.gz
[tests/ttotal_order.c] Rewrote the tests to test every combination
of classes of values. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12495 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/ttotal_order.c')
-rw-r--r--tests/ttotal_order.c164
1 files changed, 77 insertions, 87 deletions
diff --git a/tests/ttotal_order.c b/tests/ttotal_order.c
index 0fa019c22..ac99a9106 100644
--- a/tests/ttotal_order.c
+++ b/tests/ttotal_order.c
@@ -22,99 +22,89 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-test.h"
+static void
+check1 (mpfr_ptr x, mpfr_ptr y)
+{
+ if (! mpfr_total_order (x, x))
+ {
+ printf ("Error on mpfr_total_order (x, x) with\n");
+ printf ("x = ");
+ mpfr_dump (x);
+ exit (1);
+ }
+
+ mpfr_set (y, x, MPFR_RNDN);
+
+ if (! mpfr_total_order (x, y))
+ {
+ printf ("Error on mpfr_total_order (x, y) with\n");
+ printf ("x = ");
+ mpfr_dump (x);
+ printf ("y = ");
+ mpfr_dump (y);
+ exit (1);
+ }
+}
+
+static void
+check2 (mpfr_ptr x, mpfr_ptr y)
+{
+ if (! mpfr_total_order (x, y))
+ {
+ printf ("Error on mpfr_total_order (x, y) with\n");
+ printf ("x = ");
+ mpfr_dump (x);
+ printf ("y = ");
+ mpfr_dump (y);
+ exit (1);
+ }
+
+ if (mpfr_total_order (y, x))
+ {
+ printf ("Error on mpfr_total_order (y, x) with\n");
+ printf ("x = ");
+ mpfr_dump (x);
+ printf ("y = ");
+ mpfr_dump (y);
+ exit (1);
+ }
+}
+
int
main (void)
{
- mpfr_t x, y;
+ mpfr_t x[13];
+ int i, j;
tests_start_mpfr ();
- mpfr_init (x);
- mpfr_init (y);
-
- /* If x < y, totalOrder(x, y) is true */
- mpfr_set_ui (x, 1, MPFR_RNDN);
- mpfr_set_ui (y, 2, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- /* If x > y, totalOrder(x, y) is false */
- mpfr_set_ui (x, 2, MPFR_RNDN);
- mpfr_set_ui (y, 1, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) == 0);
-
- /* totalOrder(-0, +0) is true */
- mpfr_set_ui (x, 0, MPFR_RNDN);
- mpfr_neg (x, x, MPFR_RNDN);
- mpfr_set_ui (y, 0, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- /* totalOrder(+0, -0) is false */
- mpfr_set_ui (x, 0, MPFR_RNDN);
- mpfr_set_ui (y, 0, MPFR_RNDN);
- mpfr_neg (y, y, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) == 0);
-
- /* Case x = y */
- mpfr_set_si (x, -1, MPFR_RNDN);
- mpfr_set_si (y, -1, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- mpfr_set_si (x, 1, MPFR_RNDN);
- mpfr_set_si (y, 1, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- /* Case x = -NaN */
- mpfr_set_nan (x);
- /* warning: the sign of x is unspecified in mpfr_set_nan */
- if (!mpfr_signbit (x))
- mpfr_neg (x, x, MPFR_RNDN);
- /* now x = -NaN */
- mpfr_set_si (y, 1, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_set_inf (y, -1);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_set_inf (y, +1);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- /* Case y = +NaN */
- mpfr_set_nan (y);
- if (mpfr_signbit (y))
- mpfr_neg (y, y, MPFR_RNDN);
- /* now y = +NaN */
- mpfr_set_si (x, 1, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_set_inf (x, -1);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_set_inf (x, +1);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- /* Both x and y are NaN */
- mpfr_set_nan (x);
- if (!mpfr_signbit (x))
- mpfr_neg (x, x, MPFR_RNDN);
- /* now x = -NaN */
- mpfr_set_nan (y);
- if (mpfr_signbit (y))
- mpfr_neg (y, y, MPFR_RNDN);
- /* now y = +NaN */
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_neg (y, y, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
-
- mpfr_set_nan (x);
- if (mpfr_signbit (x))
- mpfr_neg (x, x, MPFR_RNDN);
- /* now x = +NaN */
- mpfr_set_nan (y);
- if (mpfr_signbit (y))
- mpfr_neg (y, y, MPFR_RNDN);
- /* now y = +NaN */
- MPFR_ASSERTN(mpfr_total_order (x, y) != 0);
- mpfr_neg (y, y, MPFR_RNDN);
- MPFR_ASSERTN(mpfr_total_order (x, y) == 0);
-
- mpfr_clear (x);
- mpfr_clear (y);
+ for (i = 0; i < 13; i++)
+ mpfr_init2 (x[i], 32);
+
+ mpfr_set_nan (x[1]);
+ MPFR_SET_NEG (x[1]);
+ mpfr_set_inf (x[2], -1);
+ mpfr_set_si (x[3], -3, MPFR_RNDN);
+ mpfr_set_si (x[4], -2, MPFR_RNDN);
+ mpfr_set_si (x[5], -1, MPFR_RNDN);
+ mpfr_set_zero (x[6], -1);
+ mpfr_set_zero (x[7], 1);
+ mpfr_set_si (x[8], 1, MPFR_RNDN);
+ mpfr_set_si (x[9], 2, MPFR_RNDN);
+ mpfr_set_si (x[10], 3, MPFR_RNDN);
+ mpfr_set_inf (x[11], 1);
+ mpfr_set_nan (x[12]);
+ MPFR_SET_POS (x[12]);
+
+ for (i = 1; i <= 12; i++)
+ {
+ check1 (x[i], x[0]);
+ for (j = i+1; j <= 12; j++)
+ check2 (x[i], x[j]);
+ }
+
+ for (i = 0; i < 13; i++)
+ mpfr_clear (x[i]);
tests_end_mpfr ();
return 0;