[Gmp-commit] /var/hg/gmp: tests/mpz/t-cong_2exp.c: Wider coverrage.

mercurial at gmplib.org mercurial at gmplib.org
Sat Mar 9 10:09:46 CET 2013


details:   /var/hg/gmp/rev/dc3a58a673a3
changeset: 15543:dc3a58a673a3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Mar 09 10:09:40 2013 +0100
description:
tests/mpz/t-cong_2exp.c: Wider coverrage.

diffstat:

 tests/mpz/t-cong_2exp.c |  70 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 57 insertions(+), 13 deletions(-)

diffs (123 lines):

diff -r b42278fb6fa2 -r dc3a58a673a3 tests/mpz/t-cong_2exp.c
--- a/tests/mpz/t-cong_2exp.c	Sat Mar 09 03:24:54 2013 +0100
+++ b/tests/mpz/t-cong_2exp.c	Sat Mar 09 10:09:40 2013 +0100
@@ -1,7 +1,7 @@
 /* test mpz_congruent_2exp_p */
 
 /*
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -81,8 +81,10 @@
     { "0", "0", 0, 1 },
     { "1", "0", 0, 1 },
     { "0", "1", 0, 1 },
-    { "123", "456", 0, 1 },
+    { "123", "-456", 0, 1 },
     { "0x123456789123456789", "0x987654321987654321", 0, 1 },
+    { "0xfffffffffffffffffffffffffffffff7", "-0x9", 129, 0 },
+    { "0xfffffffffffffffffffffffffffffff6", "-0xa", 128, 1 },
 
   };
 
@@ -105,17 +107,12 @@
 
 
 void
-check_random (int argc, char *argv[])
+check_random (int reps)
 {
   gmp_randstate_ptr rands = RANDS;
   unsigned long  d;
   mpz_t  a, c, ra, rc;
   int    i;
-  int    want;
-  int    reps = 5000;
-
-  if (argc >= 2)
-    reps = atoi (argv[1]);
 
   mpz_init (a);
   mpz_init (c);
@@ -137,12 +134,18 @@
       mpz_fdiv_r_2exp (ra, a, d);
       mpz_fdiv_r_2exp (rc, c, d);
 
-      want = (mpz_cmp (ra, rc) == 0);
-      check_one (a, c, d, want);
-
       mpz_sub (ra, ra, rc);
-      mpz_sub (a, a, ra);
+      if (mpz_cmp_ui (ra, 0) != 0)
+	{
+	  check_one (a, c, d, 0);
+	  mpz_sub (a, a, ra);
+	}
       check_one (a, c, d, 1);
+      if (d != 0)
+	{
+	  mpz_combit (a, urandom() % d);
+	  check_one (a, c, d, 0);
+	}
     }
 
   mpz_clear (a);
@@ -151,14 +154,55 @@
   mpz_clear (rc);
 }
 
+void
+check_random_bits (int reps)
+{
+  gmp_randstate_ptr rands = RANDS;
+  mp_bitcnt_t ea, ec, en, d;
+  mp_bitcnt_t m = 10 * GMP_LIMB_BITS;
+  mpz_t  a, c;
+  int    i;
+
+  mpz_init2 (a, m + 1);
+  mpz_init2 (c, m);
+
+  for (i = 0; i < reps; i++)
+    {
+      d  = urandom() % m;
+      ea = urandom() % m;
+      ec = urandom() % m;
+      en = urandom() % m;
+
+      mpz_set_ui (c, 0);
+      mpz_setbit (c, en);
+
+      mpz_set_ui (a, 0);
+      mpz_setbit (a, ec);
+      mpz_sub (c , a, c);
+
+      mpz_set_ui (a, 0);
+      mpz_setbit (a, ea);
+      mpz_add (a , a, c);
+
+      check_one (a, c, d, ea >= d);
+    }
+
+  mpz_clear (a);
+  mpz_clear (c);
+}
+
 
 int
 main (int argc, char *argv[])
 {
+  int    reps = 5000;
+
   tests_start ();
+  TESTS_REPS (reps, argv, argc);
 
   check_data ();
-  check_random (argc, argv);
+  check_random (reps);
+  check_random_bits (reps);
 
   tests_end ();
   exit (0);


More information about the gmp-commit mailing list