summaryrefslogtreecommitdiff
path: root/tests/mpz
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2002-02-01 15:57:02 +0100
committertege <tege@gmplib.org>2002-02-01 15:57:02 +0100
commit2065fa6ac1f13b1898c790bbf56737ba2d87d1a0 (patch)
treef8f39fe94e7383c4ce161afedcb767d7b55665aa /tests/mpz
parent7fb63e47229f80d3365c8dcd27efb2d9da01226d (diff)
downloadgmp-2065fa6ac1f13b1898c790bbf56737ba2d87d1a0.tar.gz
Increase operand size.
Add (yet disabled) code for testing with random strings.
Diffstat (limited to 'tests/mpz')
-rw-r--r--tests/mpz/convert.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/mpz/convert.c b/tests/mpz/convert.c
index 492d3e726..75761bd75 100644
--- a/tests/mpz/convert.c
+++ b/tests/mpz/convert.c
@@ -36,7 +36,7 @@ main (int argc, char **argv)
mp_size_t size;
int i;
int reps = 10000;
- char *str;
+ char *str, *buf;
int base;
gmp_randstate_ptr rands;
mpz_t bs;
@@ -55,9 +55,11 @@ main (int argc, char **argv)
for (i = 0; i < reps; i++)
{
+ /* 1. Generate random mpz_t and convert to a string and back to mpz_t
+ again. */
mpz_urandomb (bs, rands, 32);
- size_range = mpz_get_ui (bs) % 10 + 2;
- mpz_urandomb (bs, rands, size_range);
+ size_range = mpz_get_ui (bs) % 12 + 2; /* 2..13 */
+ mpz_urandomb (bs, rands, size_range); /* 3..8191 bits */
size = mpz_get_ui (bs);
mpz_rrandomb (op1, rands, size);
@@ -85,6 +87,32 @@ main (int argc, char **argv)
fprintf (stderr, "op2 = "); debug_mp (op2, -16);
abort ();
}
+
+#if 0
+ /* 2. Generate random string and convert to mpz_t and back to a string
+ again. */
+ mpz_urandomb (bs, rands, 32);
+ size_range = mpz_get_ui (bs) % 10 + 2; /* 2..11 */
+ mpz_urandomb (bs, rands, size_range); /* 3..2047 bits */
+ len = mpz_get_ui (bs);
+ buf = (*__gmp_allocate_func) (len + 1);
+ string_urandomb (buf, len, base);
+ mpz_set_str_or_abort (op1, buf, base);
+ str = mpz_get_str ((char *) 0, base, op1);
+
+ if (strcmp (str, buf) != 0)
+ {
+ fprintf (stderr, "ERROR, str and buf different\n");
+ fprintf (stderr, "str = %s\n", str);
+ fprintf (stderr, "buf = %s\n", buf);
+ fprintf (stderr, "base = %d\n", base);
+ fprintf (stderr, "op1 = "); debug_mp (op1, -16);
+ abort ();
+ }
+
+ (*__gmp_free_func) (buf, len + 1);
+ (*__gmp_free_func) (str, strlen (str) + 1);
+#endif
}
mpz_clear (bs);