[Gmp-commit] /var/hg/gmp-5.0: Improved hgcd and gcd tests.

mercurial at gmplib.org mercurial at gmplib.org
Sun Feb 5 23:29:23 CET 2012


details:   /var/hg/gmp-5.0/rev/ce65a74bea1a
changeset: 13546:ce65a74bea1a
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sun Feb 05 23:29:16 2012 +0100
description:
Improved hgcd and gcd tests.

diffstat:

 ChangeLog          |   3 +++
 tests/mpn/t-hgcd.c |  15 +++++++++++++++
 tests/mpz/t-gcd.c  |  24 ++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)

diffs (71 lines):

diff -r 11a901ce5242 -r ce65a74bea1a ChangeLog
--- a/ChangeLog	Sun Feb 05 20:44:21 2012 +0100
+++ b/ChangeLog	Sun Feb 05 23:29:16 2012 +0100
@@ -1,5 +1,8 @@
 2012-02-05  Niels Möller  <nisse at lysator.liu.se>
 
+	* tests/mpz/t-gcd.c (main): Add tests with rrandomb operands.
+	* tests/mpn/t-hgcd.c (main): Likewise.
+
 	* mpn/generic/gcdext_subdiv_step.c (mpn_gcdext_subdiv_step):
 	Bugfix, in u1 += q * u0, handle carry in all cases. Also normalize
 	the product q * u0.
diff -r 11a901ce5242 -r ce65a74bea1a tests/mpn/t-hgcd.c
--- a/tests/mpn/t-hgcd.c	Sun Feb 05 20:44:21 2012 +0100
+++ b/tests/mpn/t-hgcd.c	Sun Feb 05 23:29:16 2012 +0100
@@ -115,6 +115,21 @@
       if (mpz_size (op1) > 0)
 	one_test (op1, op2, i);
 
+      /* And with rrandomb */
+      mpz_urandomb (bs, rands, 32);
+      size_range = mpz_get_ui (bs) % 13 + 2;
+
+      mpz_urandomb (bs, rands, size_range);
+      mpz_rrandomb (op1, rands, mpz_get_ui (bs) + MIN_OPERAND_SIZE);
+      mpz_urandomb (bs, rands, size_range);
+      mpz_rrandomb (op2, rands, mpz_get_ui (bs) + MIN_OPERAND_SIZE);
+
+      if (mpz_cmp (op1, op2) < 0)
+	mpz_swap (op1, op2);
+
+      if (mpz_size (op1) > 0)
+	one_test (op1, op2, i);
+      
       /* Generate a division chain backwards, allowing otherwise
 	 unlikely huge quotients.  */
 
diff -r 11a901ce5242 -r ce65a74bea1a tests/mpz/t-gcd.c
--- a/tests/mpz/t-gcd.c	Sun Feb 05 20:44:21 2012 +0100
+++ b/tests/mpz/t-gcd.c	Sun Feb 05 23:29:16 2012 +0100
@@ -173,6 +173,30 @@
 
       one_test (op1, op2, NULL, i);
 
+      /* And rrandomb inputs have triggered other bugs. */
+      mpz_urandomb (bs, rands, 32);
+      size_range = mpz_get_ui (bs) % 17 + 2;
+
+      mpz_urandomb (bs, rands, size_range);
+      mpz_rrandomb (op1, rands, mpz_get_ui (bs) + MIN_OPERAND_BITSIZE);
+      mpz_urandomb (bs, rands, size_range);
+      mpz_rrandomb (op2, rands, mpz_get_ui (bs) + MIN_OPERAND_BITSIZE);
+
+      mpz_urandomb (bs, rands, 8);
+      bsi = mpz_get_ui (bs);
+
+      if ((bsi & 0x3c) == 4)
+	mpz_mul (op1, op1, op2);	/* make op1 a multiple of op2 */
+      else if ((bsi & 0x3c) == 8)
+	mpz_mul (op2, op1, op2);	/* make op2 a multiple of op1 */
+
+      if ((bsi & 1) != 0)
+	mpz_neg (op1, op1);
+      if ((bsi & 2) != 0)
+	mpz_neg (op2, op2);
+
+      one_test (op1, op2, NULL, i);
+	 
       /* Generate a division chain backwards, allowing otherwise unlikely huge
 	 quotients.  */
 


More information about the gmp-commit mailing list