summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-10 23:46:47 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-06-10 23:46:47 +0000
commitb396f757a3ed90127238f9d071b32539db7d543a (patch)
treed93880094de38d3997843a42843fc86ece0a9680
parent0c7bb6432a0783269c6598629c8449b8079befc6 (diff)
downloadmpfr-b396f757a3ed90127238f9d071b32539db7d543a.tar.gz
[tests/trandom.c] Cleaner test, avoiding the explicit use of mpfr_rands.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9553 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--tests/trandom.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/tests/trandom.c b/tests/trandom.c
index a86d77a91..943abab07 100644
--- a/tests/trandom.c
+++ b/tests/trandom.c
@@ -23,7 +23,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-test.h"
static void
-test_urandomb (long nbtests, mpfr_prec_t prec, int verbose, char *s)
+test_urandomb (long nbtests, mpfr_prec_t prec, int verbose)
{
mpfr_t x;
int *tab, size_tab, k, sh, xn;
@@ -57,15 +57,6 @@ test_urandomb (long nbtests, mpfr_prec_t prec, int verbose, char *s)
tab[(int)(size_tab * d)]++;
}
- if (s != NULL && mpfr_cmp_str (x, s, 2, MPFR_RNDN) != 0)
- {
- printf ("Error in test_urandomb:\n");
- printf ("Expected %s\n", s);
- printf ("Got ");
- mpfr_dump (x);
- exit (1);
- }
-
/* coverage test */
emin = mpfr_get_emin ();
set_emin (1); /* the generated number in [0,1[ is not in the exponent
@@ -176,11 +167,11 @@ main (int argc, char *argv[])
else
prec = atol(argv[2]);
- test_urandomb (nbtests, prec, verbose, NULL);
+ test_urandomb (nbtests, prec, verbose);
if (argc == 1) /* check also small precision */
{
- test_urandomb (nbtests, 2, 0, NULL);
+ test_urandomb (nbtests, 2, 0);
}
#ifndef MPFR_USE_MINI_GMP
@@ -194,9 +185,34 @@ main (int argc, char *argv[])
/* Get a non-zero fixed-point number whose first 32 bits are 0 with the
default GMP PRNG. This corresponds to the case cnt == 0 && k != 0 in
src/urandomb.c (fixed in r8762) with the 32-bit ABI. */
- gmp_randseed_ui (mpfr_rands, 4518);
- test_urandomb (575123, 40, 0,
- "0.1010111100000000000000000000000000000000E-32");
+ {
+ gmp_randstate_t s;
+ mpfr_t x;
+ char *str = "0.1010111100000000000000000000000000000000E-32";
+ int k;
+
+ gmp_randinit_default (s);
+ gmp_randseed_ui (s, 4518);
+ mpfr_init2 (x, 40);
+
+ for (k = 0; k < 575123; k++)
+ {
+ mpfr_urandomb (x, s);
+ MPFR_ASSERTN (MPFR_IS_FP (x));
+ }
+
+ if (mpfr_cmp_str (x, str, 2, MPFR_RNDN) != 0)
+ {
+ printf ("Error in test_urandomb:\n");
+ printf ("Expected %s\n", str);
+ printf ("Got ");
+ mpfr_dump (x);
+ exit (1);
+ }
+
+ mpfr_clear (x);
+ gmp_randclear (s);
+ }
#endif
#endif