summaryrefslogtreecommitdiff
path: root/tests/mpz
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2016-12-28 18:24:03 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2016-12-28 18:24:03 +0100
commit384d404241fb2a9f30263a17eb1692cd8095711d (patch)
tree0ce312351d26725fb9c9da0a2f5d7e3d6f12039f /tests/mpz
parent597e975c08e77466196cce4db5f683a5f04dc9d6 (diff)
downloadgmp-384d404241fb2a9f30263a17eb1692cd8095711d.tar.gz
tests/mpz/t-primorial_ui.c: Add randomization to the test
Diffstat (limited to 'tests/mpz')
-rw-r--r--tests/mpz/t-primorial_ui.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/mpz/t-primorial_ui.c b/tests/mpz/t-primorial_ui.c
index c140bb710..9c94802ea 100644
--- a/tests/mpz/t-primorial_ui.c
+++ b/tests/mpz/t-primorial_ui.c
@@ -37,9 +37,11 @@ main (int argc, char *argv[])
{
unsigned long n;
unsigned long limit = 2222;
- mpz_t f, r;
+ gmp_randstate_ptr rands;
+ mpz_t f, r, bs;
tests_start ();
+ rands = RANDS;
if (argc > 1 && argv[1][0] == 'x')
limit = ULONG_MAX;
@@ -71,6 +73,34 @@ main (int argc, char *argv[])
if (n%16 == 0) { mpz_clear (r); mpz_init (r); }
} while (n < limit);
+ n = 0; limit =1;
+ mpz_init (bs);
+ do
+ {
+ unsigned long i, d;
+
+ mpz_urandomb (bs, rands, 21);
+ i = mpz_get_ui (bs);
+ mpz_urandomb (bs, rands, 9);
+ d = mpz_get_ui (bs) + 3*64;
+ mpz_primorial_ui (f, i);
+ MPZ_CHECK_FORMAT (f);
+ mpz_primorial_ui (r, i+d);
+ MPZ_CHECK_FORMAT (r);
+
+ do {
+ if (isprime (++i))
+ mpz_mul_ui (f, f, i);
+ } while (--d != 0);
+
+ if (mpz_cmp (f, r) != 0)
+ {
+ printf ("mpz_primorial_ui(%lu) wrong\n", i);
+ printf (" got "); mpz_out_str (stdout, 10, r); printf("\n");
+ printf (" want "); mpz_out_str (stdout, 10, f); printf("\n");
+ abort ();
+ }
+ } while (++n < limit);
/* Chech a single "big" value, modulo a larger prime */
n = 2095637;
mpz_primorial_ui (r, n);
@@ -87,6 +117,7 @@ main (int argc, char *argv[])
abort ();
}
+ mpz_clear (bs);
mpz_clear (f);
mpz_clear (r);