[Mpfi-commits] r308 - trunk/mpfi/tests

ptheveny at users.gforge.inria.fr ptheveny at users.gforge.inria.fr
Mar 22 Juin 13:33:50 CEST 2010


Author: ptheveny
Date: 2010-06-22 13:33:50 +0200 (Tue, 22 Jun 2010)
New Revision: 308

Added:
   trunk/mpfi/tests/type_ri.c
Modified:
   trunk/mpfi/tests/Makefile.am
   trunk/mpfi/tests/mpfi-tests.h
   trunk/mpfi/tests/read_data.c
Log:
Add reading test data support for mpfi_mid-like functions.

Modified: trunk/mpfi/tests/Makefile.am
===================================================================
--- trunk/mpfi/tests/Makefile.am	2010-06-22 11:20:19 UTC (rev 307)
+++ trunk/mpfi/tests/Makefile.am	2010-06-22 11:33:50 UTC (rev 308)
@@ -7,7 +7,7 @@
     type_id.c type_iz.c type_iq.c type_ir.c type_iiu.c		\
     type_iis.c type_iid.c type_iiz.c type_iiq.c type_iir.c	\
     type_iui.c type_isi.c type_idi.c type_izi.c type_iqi.c	\
-    type_iri.c check_data.c mpfi-tests.c
+    type_iri.c type_ri.c check_data.c mpfi-tests.c
 
 check_PROGRAMS = tabs tacos tacosh tadd tadd_d tadd_fr		\
     tadd_q tadd_si tadd_ui tadd_z tasin tasinh tatan tatan2	\

Modified: trunk/mpfi/tests/mpfi-tests.h
===================================================================
--- trunk/mpfi/tests/mpfi-tests.h	2010-06-22 11:20:19 UTC (rev 307)
+++ trunk/mpfi/tests/mpfi-tests.h	2010-06-22 11:33:50 UTC (rev 308)
@@ -64,6 +64,7 @@
 typedef int (*IZI_fun) (mpfi_t, mpz_srcptr, mpfi_srcptr);
 typedef int (*IQI_fun) (mpfi_t, mpq_srcptr, mpfi_srcptr);
 typedef int (*IRI_fun) (mpfi_t, mpfr_srcptr, mpfi_srcptr);
+typedef int (*RI_fun)  (mpfr_t, mpfi_srcptr);
 
 typedef int (*R_fun)   (mpfr_t, mp_rnd_t);
 typedef int (*RR_fun)  (mpfr_t, mpfr_srcptr, mp_rnd_t);
@@ -103,6 +104,7 @@
   IZI_fun IZI;     /* output: mpfi_t, inputs: mpz_t, mpfi_t */
   IQI_fun IQI;     /* output: mpfi_t, inputs: mpq_t, mpfi_t */
   IRI_fun IRI;     /* output: mpfi_t, inputs: mpfr_t, mpfi_t */
+  RI_fun  RI;      /* output: mpfr_t, input: mpfi_t */
 } mpfi_fun_ptr;
 
 typedef union
@@ -128,6 +130,7 @@
   RZR_fun  IZI;    /* output: mpfr_t, inputs: mpz_t, mpfr_t */
   RQR_fun  IQI;    /* output: mpfr_t, inputs: mpq_t, mpfr_t */
   RRR_fun  IRI;    /* output: mpfr_t, inputs: mpfr_t, mpfr_t */
+  NULL_fun RI;     /* dummy, no corresponding mpfr function */
 } mpfi_fun_mpfr_ptr;
 
 typedef enum
@@ -153,6 +156,7 @@
     IZI,   /* two inputs: mpz_t, interval */
     IQI,   /* two inputs: mpq_t, interval */
     IRI,   /* two inputs: mpfr_t, interval */
+    RI,    /* one input: interval */
   } mpfi_fun_type;
 
 typedef union {
@@ -230,6 +234,7 @@
 void mpfi_fun_init_IZI  (mpfi_function_ptr, IZI_fun, RZR_fun);
 void mpfi_fun_init_IQI  (mpfi_function_ptr, IQI_fun, RQR_fun);
 void mpfi_fun_init_IRI  (mpfi_function_ptr, IRI_fun, RRR_fun);
+void mpfi_fun_init_RI   (mpfi_function_ptr, RI_fun, NULL_fun);
 void mpfi_fun_clear     (mpfi_function_ptr);
 
 
@@ -252,6 +257,7 @@
 void init_reading       (FILE*);
 void close_file         (FILE*);
 void skip_whitespace_comments (FILE*);
+void read_sign          (FILE*, int*);
 void read_exactness     (FILE*, int*);
 void read_ui            (FILE*, unsigned long*);
 void read_si            (FILE*, long*);

Modified: trunk/mpfi/tests/read_data.c
===================================================================
--- trunk/mpfi/tests/read_data.c	2010-06-22 11:20:19 UTC (rev 307)
+++ trunk/mpfi/tests/read_data.c	2010-06-22 11:33:50 UTC (rev 308)
@@ -139,6 +139,35 @@
 /* Read operand in file, and sometimes check its validity */
 
 void
+read_sign (FILE *f, int *sign)
+{
+  switch (nextchar) {
+  case '-':
+    *sign = -1;
+    break;
+  case '0':
+    *sign = 0;
+    break;
+  case '+':
+    *sign = +1;
+    break;
+  default:
+    printf ("Error: unexpected signedness '%c' in file '%s' line %lu\n",
+            nextchar, pathname, line_number);
+    exit (1);
+  }
+
+  nextchar = getc (f);
+  if (!isspace(nextchar)) {
+    printf ("Error: unexpected character '%c' after exactness flag"
+            " in file '%s' line %lu\n", nextchar, pathname, line_number);
+    exit (1);
+  }
+
+  skip_whitespace_comments (f);
+}
+
+void
 read_exactness (FILE *f, int *exactness)
 {
   if (!isdigit (nextchar) || nextchar < '0' || nextchar > '4') {

Added: trunk/mpfi/tests/type_ri.c
===================================================================
--- trunk/mpfi/tests/type_ri.c	                        (rev 0)
+++ trunk/mpfi/tests/type_ri.c	2010-06-22 11:33:50 UTC (rev 308)
@@ -0,0 +1,129 @@
+/* type_ri.c -- Test functions associated with functions of the type
+                mpfi_f (mpfr_t, mpfi_t).
+
+Copyright 2010
+                     Spaces project, Inria Lorraine
+                     and Salsa project, INRIA Rocquencourt,
+                     and Arenaire project, Inria Rhone-Alpes, France
+                     and Lab. ANO, USTL (Univ. of Lille),  France
+
+
+This file is part of the MPFI Library.
+
+The MPFI Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The MPFI Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the MPFI Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+MA 02110-1301, USA. */
+
+#include "mpfi-tests.h"
+
+extern char * pathname;
+extern unsigned long line_number;
+unsigned long test_line_number;   /* start line of a test */
+
+void
+read_line_ri (mpfi_function_ptr this, FILE* fp)
+{
+  test_line_number = line_number;
+  /* [1] return value */
+  read_sign (fp, &(MPFI_FUN_ARG (*this, 1, i)));
+  /* [2] expected value  (mpfr_t)*/
+  read_mpfr (fp, MPFI_FUN_ARG (*this, 2, mpfr));
+  /* [3] operand */
+  read_mpfi (fp, MPFI_FUN_ARG (*this, 3, mpfi));
+}
+
+void
+check_line_ri (mpfi_function_ptr this)
+{
+  int ret;
+
+  /* rename operands for better readability */
+  RI_fun  f_RI      = MPFI_FUN_GET (*this, RI);
+  mpfr_ptr got      = MPFI_FUN_ARG (*this, 0, mpfr);
+  int expected_ret  = MPFI_FUN_ARG (*this, 1, i);
+  mpfr_ptr expected = MPFI_FUN_ARG (*this, 2, mpfr);
+  mpfi_ptr op       = MPFI_FUN_ARG (*this, 3, mpfi);
+
+  mpfr_set_prec (got, mpfr_get_prec (expected));
+  ret = f_RI (got, op);
+  if ((ret != expected_ret && ret * expected_ret <= 0)
+      || !same_mpfr_value (got, expected)) {
+    printf ("Failed line %lu.\nop = ", test_line_number);
+    mpfi_out_str (stdout, 16, 0, op);
+    printf ("\ngot      = ");
+    mpfr_out_str (stdout, 16, 0, got, MPFI_RNDD);
+    printf ("\nexpected = ");
+    mpfr_out_str (stdout, 16, 0, expected, MPFI_RNDD);
+    putchar ('\n');
+    if (ret != expected_ret || ret * expected_ret < 0) {
+      printf ("return value: got = %d, %s expected\n", ret,
+              expected_ret < 0 ? "negative"
+              : expected_ret > 0 ? "positive" : "zero");
+    }
+
+    exit (1);
+  }
+}
+
+void
+set_prec_ri (mpfi_function_ptr this, mp_prec_t prec)
+{
+  mpfr_set_prec (MPFI_FUN_ARG (*this, 0, mpfr), prec);
+  mpfr_set_prec (MPFI_FUN_ARG (*this, 2, mpfr), prec);
+  mpfi_set_prec (MPFI_FUN_ARG (*this, 3, mpfi), prec);
+}
+
+void
+clear_ri (mpfi_function_ptr this)
+{
+  /* [0] result (mpfr_t) */
+  mpfr_clear (MPFI_FUN_ARG (*this, 0, mpfr));
+  /* [1] return value (int), needs no deallocation */
+  /* [2] expected value (mpfr_t) */
+  mpfr_clear (MPFI_FUN_ARG (*this, 2, mpfr));
+  /* [3] operand (mpfi_t) */
+  mpfi_clear (MPFI_FUN_ARG (*this, 3, mpfi));
+
+  free (MPFI_FUN_ARGS (*this));
+  MPFI_FUN_ARGS (*this) = NULL;
+}
+
+/* In operands array, variables are in the same order as for data in
+   '.dat' files plus one additional variable before them. */
+void
+mpfi_fun_init_RI (mpfi_function_ptr this, RI_fun mpfi_function,
+              NULL_fun mpfr_function)
+{
+  this->type = RI;
+  this->func.RI = mpfi_function;
+  this->mpfr_func.RI = mpfr_function;
+
+  MPFI_FUN_ARGS (*this) =
+    (mpfi_fun_operand_t*) malloc (4 * sizeof (mpfi_fun_operand_t));
+
+  /* [0] result (mpfr_t) */
+  mpfr_init2 (MPFI_FUN_ARG (*this, 0, mpfr), 1024);
+  /* [1] return value (int), needs no initialization */
+  /* [2] expected value (mpfr_t) */
+  mpfr_init2 (MPFI_FUN_ARG (*this, 2, mpfr), 1024);
+  /* [3] operand (mpfi_t) */
+  mpfi_init2 (MPFI_FUN_ARG (*this, 3, mpfi), 1024);
+
+  /* init methods */
+  this->set_prec   = set_prec_ri;
+  this->read_line  = read_line_ri;
+  this->check_line = check_line_ri;
+  this->random     = NULL;
+  this->clear      = clear_ri;
+}




More information about the Mpfi-commits mailing list