[Gmp-commit] /var/hg/gmp: mini-gmp/tests/t-signed.c: Slightly larger coverage.
mercurial at gmplib.org
mercurial at gmplib.org
Fri Jan 18 12:06:50 CET 2013
details: /var/hg/gmp/rev/0d119642e9e3
changeset: 15293:0d119642e9e3
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Fri Jan 18 12:06:39 2013 +0100
description:
mini-gmp/tests/t-signed.c: Slightly larger coverage.
diffstat:
ChangeLog | 4 ++
mini-gmp/tests/t-signed.c | 67 ++++++++++++++++++++++------------------------
2 files changed, 36 insertions(+), 35 deletions(-)
diffs (132 lines):
diff -r 6898230ae9ba -r 0d119642e9e3 ChangeLog
--- a/ChangeLog Fri Jan 18 11:54:53 2013 +0100
+++ b/ChangeLog Fri Jan 18 12:06:39 2013 +0100
@@ -1,3 +1,7 @@
+2013-01-18 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * mini-gmp/tests/t-signed.c: Slightly larger coverage.
+
2013-01-18 Torbjorn Granlund <tege at gmplib.org>
* mini-gmp/tests/t-div.c: Test mpz_divisible_p and mpz_divisible_ui_p.
diff -r 6898230ae9ba -r 0d119642e9e3 mini-gmp/tests/t-signed.c
--- a/mini-gmp/tests/t-signed.c Fri Jan 18 11:54:53 2013 +0100
+++ b/mini-gmp/tests/t-signed.c Fri Jan 18 12:06:39 2013 +0100
@@ -22,12 +22,22 @@
#include "mini-gmp.h"
-void
-check_si (mpz_t sz, mpz_t oz, long si, int c)
+int
+check_si (mpz_t sz, mpz_t oz, long si, long oi, int c)
{
mpz_t t;
int fail;
+ if (mpz_cmp_si (sz, oi) != c)
+ {
+ printf ("mpz_cmp_si (sz, %ld) != %i.\n", oi, c);
+ printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
+ abort ();
+ }
+
+ if ((si < oi ? -1 : si > oi) != c)
+ return 1;
+
mpz_init_set_si (t, si);
if ((fail = mpz_cmp_si (sz, si)) != 0)
@@ -54,6 +64,8 @@
printf (" si=%ld\n", si);
abort ();
}
+
+ return 0;
}
void
@@ -72,58 +84,28 @@
si *= 2; /* c * 2^k */
mpz_mul_2exp (sz, sz, 1);
- if (mpz_cmp_si (sz, oi) != c)
- {
- printf ("mpz_cmp_si (sz, %ld) != %i.\n", oi, c);
- printf (" sz="); mpz_out_str (stdout, 10, sz); printf ("\n");
- abort ();
- }
-
- if ((si < oi ? -1 : si > oi) != c)
+ if (check_si (sz, oz, si, oi, c))
{
mpz_set (oz, sz);
break;
}
- check_si (sz, oz, si, c);
-
oi = si + c; /* c * (2^k + 1) */
if (c == -1)
mpz_sub_ui (oz, sz, 1);
else
mpz_add_ui (oz, sz, 1);
- if (mpz_cmp_si (oz, si) != c)
- {
- printf ("mpz_cmp_si (oz, %ld) != %i.\n", si, c);
- printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
- abort ();
- }
-
- if ((oi < si ? -1 : oi > si) != c)
+ if (check_si (oz, sz, oi, si, c))
break;
- check_si (oz, sz, oi, c);
-
oi = (si - c) * 2 + c; /* c * (2^K - 1) */
mpz_mul_si (oz, sz, 2*c);
if (c == -1)
mpz_ui_sub (oz, 1, oz); /* oz = sz * 2 + 1 */
else
mpz_sub_ui (oz, oz, 1); /* oz = sz * 2 - 1 */
-
- if (mpz_cmp_si (oz, si) != c)
- {
- printf ("mpz_cmp_si (oz, %ld) != %i.\n", si, c);
- printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
- abort ();
- }
-
- if ((oi < si ? -1 : oi > si) != c)
- break;
-
- check_si (oz, sz, oi, c);
- } while (1);
+ } while (check_si (oz, sz, oi, si, c) == 0);
mpz_clear (sz);
@@ -134,6 +116,21 @@
abort ();
}
+ if (mpz_cmp_si (oz, -c) != c)
+ {
+ printf ("mpz_cmp_si (oz, %i) != %i.\n", c, c);
+ printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
+ abort ();
+ }
+
+ mpz_mul_2exp (oz, oz, 1);
+ if (mpz_cmp_si (oz, -c) != c)
+ {
+ printf ("mpz_cmp_si (oz, %i) != %i.\n", c, c);
+ printf (" oz="); mpz_out_str (stdout, 10, oz); printf ("\n");
+ abort ();
+ }
+
mpz_clear (oz);
}
More information about the gmp-commit
mailing list