1 /* mpfi_tests.c -- Test constant functions
2                    and test non-constant functions with random values.
3 
4 Copyright (C) 2001, 2002, 2009, 2010,
5                      Spaces project, Inria Lorraine
6                      Arenaire project, Inria Rhone-Alpes, France
7                      and Lab. ANO, USTL (Univ. of Lille),  France
8 
9 
10 This file is part of the MPFI Library, based on the MPFR Library.
11 
12 The MPFI Library is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Library General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or (at your
15 option) any later version.
16 
17 The MPFI Library is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
20 License for more details.
21 
22 You should have received a copy of the GNU Library General Public License
23 along with the MPFR Library; see the file COPYING.LIB.  If not, write to
24 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25 MA 02110-1301, USA. */
26 
27 #include "mpfi-tests.h"
28 
29 void
mpfi_restrict_random(mpfi_function_ptr func,I_fun restriction)30 mpfi_restrict_random (mpfi_function_ptr func, I_fun restriction)
31 {
32   func->random_domain = restriction;
33 }
34 
35 void
mpfi_fun_clear(mpfi_function_ptr func)36 mpfi_fun_clear (mpfi_function_ptr func)
37 {
38   func->clear (func);
39 }
40 
41 void
check_random(mpfi_function_ptr function,mpfr_prec_t prec_min,mpfr_prec_t prec_max,int nb_tests)42 check_random (mpfi_function_ptr function,
43               mpfr_prec_t prec_min, mpfr_prec_t prec_max, int nb_tests)
44 {
45   mpfr_prec_t prec;
46   int i;
47 
48   if (!rands_initialized)
49     {
50       printf ("Put test_start at the beginning of your test function.\n");
51       printf ("There is a bug in the test suite itself, "
52               "please report to the MPFI mailing list.\n");
53       exit (1);
54     }
55 
56   if (function->random == NULL) {
57     printf ("Error: no random function for this type.\n");
58     printf ("There is a bug in the test suite itself, "
59 	    "please report to the MPFI mailing list.\n");
60     exit (1);
61   }
62 
63   for (prec = prec_min; prec <= prec_max; ++prec) {
64     function->set_prec (function, prec);
65     for (i = 0; i < nb_tests; ++i) {
66       function->random (function);
67     }
68   }
69 }
70