[Gmp-commit] /var/hg/gmp: Rewrite tests/mpf/t-eq.c.
mercurial at gmplib.org
mercurial at gmplib.org
Wed May 16 20:17:02 CEST 2012
details: /var/hg/gmp/rev/d73d376a7c3d
changeset: 14968:d73d376a7c3d
user: Torbjorn Granlund <tege at gmplib.org>
date: Wed May 16 20:17:00 2012 +0200
description:
Rewrite tests/mpf/t-eq.c.
diffstat:
ChangeLog | 5 ++
tests/mpf/t-eq.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 97 insertions(+), 15 deletions(-)
diffs (160 lines):
diff -r 7870161cfa00 -r d73d376a7c3d ChangeLog
--- a/ChangeLog Sun May 13 16:05:41 2012 +0200
+++ b/ChangeLog Wed May 16 20:17:00 2012 +0200
@@ -1,3 +1,8 @@
+2012-05-16 Torbjorn Granlund <tege at gmplib.org>
+
+ * tests/mpf/t-eq.c (check_random): New function, meat from old main().
+ (check_data): New function.
+
2012-05-13 Torbjorn Granlund <tege at gmplib.org>
* mpn/arm/rsh1aors_n.asm: New file.
diff -r 7870161cfa00 -r d73d376a7c3d tests/mpf/t-eq.c
--- a/tests/mpf/t-eq.c Sun May 13 16:05:41 2012 +0200
+++ b/tests/mpf/t-eq.c Wed May 16 20:17:00 2012 +0200
@@ -30,12 +30,79 @@
void dump_abort (mpf_t, mpf_t, int, int, int, int, int, long);
void hexdump (mpf_t);
-int
-main (int argc, char **argv)
+void
+check_data (void)
{
- unsigned long test, reps = 10000;
+ static const struct
+ {
+ struct {
+ int exp, size;
+ mp_limb_t d[10];
+ } x, y;
+ mp_bitcnt_t bits;
+ int want;
+
+ } data[] = {
+ { { 0, 0, { 0 } }, { 0, 0, { 0 } }, 0, 1 },
+
+ { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 0, 1 },
+ { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 17, 1 },
+ { { 0, 1, { 7 } }, { 0, 1, { 7 } }, 4711, 1 },
+
+ { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 0, 1 },
+ { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 2, 1 },
+ { { 0, 1, { 7 } }, { 0, 1, { 6 } }, 3, 0 },
+
+ { { 0, 0, { 0 } }, { 0, 1, { 1 } }, 0, 0 },
+ { { 0, 1, { 1 } }, { 0,-1 ,{ 1 } }, 0, 0 },
+ { { 1, 1, { 1 } }, { 0, 1, { 1 } }, 0, 0 },
+
+ { { 0, 1, { 8 } }, { 0, 1, { 4 } }, 0, 0 },
+
+ { { 0, 2, { 0, 3 } }, { 0, 1, { 3 } }, 1000, 1 },
+ };
+
+ mpf_t x, y;
+ int got, got_swapped;
+ mp_trace_base = 16;
+ int i;
+
+ for (i = 0; i < numberof (data); i++)
+ {
+ PTR(x) = (mp_ptr) data[i].x.d;
+ SIZ(x) = data[i].x.size;
+ EXP(x) = data[i].x.exp;
+ PREC(x) = numberof (data[i].x.d);
+ MPF_CHECK_FORMAT (x);
+
+ PTR(y) = (mp_ptr) data[i].y.d;
+ SIZ(y) = data[i].y.size;
+ EXP(y) = data[i].y.exp;
+ PREC(y) = numberof (data[i].y.d);
+ MPF_CHECK_FORMAT (y);
+
+ got = mpf_eq (x, y, data[i].bits);
+ got_swapped = mpf_eq (y, x, data[i].bits);
+
+ if (got != got_swapped || got != data[i].want)
+ {
+ printf ("check_data() wrong reault at data[%d]\n", i);
+ mpf_trace ("x ", x);
+ mpf_trace ("y ", y);
+ printf ("got %d\n", got);
+ printf ("got_swapped %d\n", got_swapped);
+ printf ("want %d\n", data[i].want);
+ abort ();
+ }
+ }
+}
+
+void
+check_random (long reps)
+{
+ unsigned long test;
+ gmp_randstate_ptr rands = RANDS;
mpf_t a, b, x;
- gmp_randstate_ptr rands;
mpz_t ds;
int hibits, lshift1, lshift2;
int xtra;
@@ -44,13 +111,6 @@
#define LSHIFT1 10
#define LSHIFT2 10
- if (argc > 1)
- reps = strtol (argv[1], 0, 0);
-
- tests_start ();
-
- rands = RANDS;
-
mpf_set_default_prec ((1 << HIBITS) + (1 << LSHIFT1) + (1 << LSHIFT2));
mpz_init (ds);
@@ -83,12 +143,14 @@
insert_random_low_zero_limbs (a, rands);
insert_random_low_zero_limbs (b, rands);
- if (mpf_eq (a, b, lshift1 + hibits) == 0)
+ if (mpf_eq (a, b, lshift1 + hibits) == 0 ||
+ mpf_eq (b, a, lshift1 + hibits) == 0)
{
dump_abort (a, b, lshift1 + hibits, lshift1, lshift2, hibits, 1, test);
}
for (xtra = 1; xtra < 100; xtra++)
- if (mpf_eq (a, b, lshift1 + hibits + xtra) != 0)
+ if (mpf_eq (a, b, lshift1 + hibits + xtra) != 0 ||
+ mpf_eq (b, a, lshift1 + hibits + xtra) != 0)
{
dump_abort (a, b, lshift1 + hibits + xtra, lshift1, lshift2, hibits, 0, test);
}
@@ -96,8 +158,6 @@
mpf_clears (a, b, x, NULL);
mpz_clear (ds);
- tests_end ();
- exit (0);
}
void
@@ -139,3 +199,20 @@
printf (" ");
}
}
+
+int
+main (int argc, char *argv[])
+{
+ long reps = 10000;
+
+ if (argc == 2)
+ reps = strtol (argv[1], 0, 0);
+
+ tests_start ();
+
+ check_data ();
+ check_random (reps);
+
+ tests_end ();
+ exit (0);
+}
More information about the gmp-commit
mailing list