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

ptheveny at users.gforge.inria.fr ptheveny at users.gforge.inria.fr
Mer 23 Juin 11:20:11 CEST 2010


Author: ptheveny
Date: 2010-06-23 11:20:10 +0200 (Wed, 23 Jun 2010)
New Revision: 314

Added:
   trunk/mpfi/tests/inp_str.dat
   trunk/mpfi/tests/tio_str.c
Modified:
   trunk/mpfi/tests/Makefile.am
Log:
Add test data for mpfi_out_str and mpfi_inp_str.

Modified: trunk/mpfi/tests/Makefile.am
===================================================================
--- trunk/mpfi/tests/Makefile.am	2010-06-23 09:17:30 UTC (rev 313)
+++ trunk/mpfi/tests/Makefile.am	2010-06-23 09:20:10 UTC (rev 314)
@@ -18,13 +18,13 @@
     tdiv_z terror texp texp2 texpm1 tfr_div tfr_sub thypot	\
     tincrease tinit_set tintersect tinterv_d tinterv_fr		\
     tinterv_q tinterv_si tinterv_ui tinterv_z tinv tget_d	\
-    tis_empty tget_endpoints tget_fr thas_zero tlog tlog10	\
-    tlog1p tlog2 tmag tmid tmig tmul tmul_2exp tmul_2si		\
-    tmul_2ui tmul_d tmul_fr tmul_q tmul_ui tmul_si tmul_z	\
-    tneg tput_d tput_fr tput_q tput_si tput_ui tput_z tq_div	\
-    tq_sub tround_prec tsec tsech tset tset_d tset_fr tset_q	\
-    tset_si tset_str tset_ui tset_z tsi_div tsi_sub tsin	\
-    tsinh tsqr tsqrt tsub tsub_d tsub_fr tsub_q tsub_ui		\
+    tis_empty tio_str tget_endpoints tget_fr thas_zero tlog	\
+    tlog10 tlog1p tlog2 tmag tmid tmig tmul tmul_2exp		\
+    tmul_2si tmul_2ui tmul_d tmul_fr tmul_q tmul_ui tmul_si	\
+    tmul_z tneg tput_d tput_fr tput_q tput_si tput_ui tput_z	\
+    tq_div tq_sub tround_prec tsec tsech tset tset_d tset_fr	\
+    tset_q tset_si tset_str tset_ui tset_z tsi_div tsi_sub	\
+    tsin tsinh tsqr tsqrt tsub tsub_d tsub_fr tsub_q tsub_ui	\
     tsub_si tsub_z tswap ttan ttanh tunion tui_div tui_sub	\
     tz_div tz_sub tget_version
 
@@ -34,10 +34,11 @@
     cbrt.dat const_catalan.dat const_euler.dat			\
     const_log2.dat const_pi.dat cos.dat cosh.dat cot.dat	\
     diam.dat diam_abs.dat diam_rel.dat div.dat increase.dat	\
-    intersect.dat inv.dat log.dat mag.dat mid.dat mig.dat	\
-    mul.dat mul_d.dat neg.dat put_d.dat put_fr.dat put_q.dat	\
-    put_si.dat put_ui.dat put_z.dat q_div.dat set_d.dat		\
-    set_fr.dat set_q.dat set_si.dat set_ui.dat set_z.dat	\
-    sqr.dat sqrt.dat sub.dat union.dat
+    inp_str.dat intersect.dat inv.dat log.dat mag.dat		\
+    mid.dat mig.dat mul.dat mul_d.dat neg.dat put_d.dat		\
+    put_fr.dat put_q.dat put_si.dat put_ui.dat put_z.dat	\
+    q_div.dat set_d.dat set_fr.dat set_q.dat set_si.dat		\
+    set_ui.dat set_z.dat sqr.dat sqrt.dat sub.dat union.dat
 
 TESTS = $(check_PROGRAMS)
+CLEANFILES = io_str.tmp
\ No newline at end of file

Added: trunk/mpfi/tests/inp_str.dat
===================================================================
--- trunk/mpfi/tests/inp_str.dat	                        (rev 0)
+++ trunk/mpfi/tests/inp_str.dat	2010-06-23 09:20:10 UTC (rev 314)
@@ -0,0 +1,5 @@
+101011101011101001110110111110100000000000111100000000011111010001110001111011010000111111011001101111101100111101000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000011101100110101010011110111111111111111111111111111111111
+   12
+ 9999901   
+1.0001e-54
+1.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

Added: trunk/mpfi/tests/tio_str.c
===================================================================
--- trunk/mpfi/tests/tio_str.c	                        (rev 0)
+++ trunk/mpfi/tests/tio_str.c	2010-06-23 09:20:10 UTC (rev 314)
@@ -0,0 +1,220 @@
+/* tio_str.c -- Test mpfi_inp_str and mpfi_out_str.
+
+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_io.h"
+#include "mpfi-tests.h"
+
+#define TMP_FILENAME "io_str.tmp"
+
+static void
+check_random_interval (mp_prec_t prec_min, mp_prec_t prec_max, mp_prec_t step)
+{
+  FILE *tmp_file;
+  size_t n_written, n_read;
+  int base;
+  mpfi_t i;
+  mpfi_t read;
+  mp_prec_t p;
+
+  mpfi_init2 (i, prec_max);
+  mpfi_init2 (read, prec_max);
+
+  for (p = prec_min; p < prec_max; p += step) {
+    mpfi_set_prec (i, p);
+    mpfi_set_prec (read, p);
+    random_interval (i);
+
+    for (base = 2; base < 37; ++base) {
+      tmp_file = fopen (TMP_FILENAME, "w");
+      if (tmp_file == NULL) {
+        printf ("Internal error: cannot open temporary file.\n");
+
+        exit (1);
+      }
+      n_written = mpfi_out_str (tmp_file, base, 0, i);
+      if (n_written == 0) {
+        printf ("Error: mpfi_out_str (\""TMP_FILENAME"\", base, 0, I) "
+                "failed.\nI = ");
+        mpfi_out_str (stdout, 10, 0, i);
+        printf ("\nbase = %d\n", base);
+
+        exit (1);
+      }
+      if (fclose (tmp_file)) {
+        printf ("Internal error: cannot close temporary file.\n");
+
+        exit (1);
+      }
+
+      tmp_file = fopen (TMP_FILENAME, "r");
+      if (tmp_file == NULL) {
+        printf ("Internal error: cannot open temporary file.\n");
+
+        exit (1);
+      }
+      n_read = mpfi_inp_str (read, tmp_file, base);
+      /* Note: there is a bug in mpfr_out_str (used by mpfi_out_str): it does
+         not return the correct number of written characters for a special
+         values */
+      if (mpfi_is_inside (i, read) == 0
+          || (!MPFI_NAN_P (i) && !MPFI_INF_P (i) && n_read != n_written)) {
+        printf ("Error: mpfi_inp_str (I, \""TMP_FILENAME"\", base) did not "
+                "read correctly the output of mpfi_out_str.\n    interval "
+                "read: \'");
+        mpfi_out_str (stdout, 16, 0, read);
+        printf ("\'\ninterval written: \'");
+        mpfi_out_str (stdout, 16, 0, i);
+        printf ("\'\nbase: %u\n", base);
+
+        if (!MPFI_NAN_P (i) && !MPFI_INF_P (i) && n_read != n_written) {
+          printf ("mpfi_inp_str did not read the complete output of "
+                  "mpfi_out_str.\nnumber of read characters: %d\n"
+                  "expected: %d\n", n_read, n_written);
+        }
+
+        exit (1);
+      }
+      if (fclose (tmp_file)) {
+        printf ("Internal error: cannot close temporary file.\n");
+        exit (1);
+      }
+
+    }
+  }
+
+  mpfi_clear (i);
+  mpfi_clear (read);
+}
+
+static void
+check_file (const char *datafile)
+{
+  FILE *stream_mpfr;
+  FILE *stream_mpfi;
+  int c;
+
+  int base;
+  mp_prec_t p;
+  mpfr_t r;
+  mpfi_t i;
+  size_t n_mpfr, n_mpfi;
+
+  mpfr_init2 (r, 1024);
+  mpfi_init2 (i, 1024);
+
+  stream_mpfr = open_file (datafile);
+  stream_mpfi = open_file (datafile);
+
+  for (p = 2; p < 1024; p += 17) {
+    mpfr_set_prec (r, p);
+    mpfi_set_prec (i, p);
+    for (base = 2; base < 37 ; ++base) {
+      if (fseek (stream_mpfr, 0, SEEK_SET)) {
+        printf ("Internal error: cannot reset position to the start of the "
+                "file \"%s\"\n", datafile);
+
+        exit (1);
+      }
+      if (fseek (stream_mpfi, 0, SEEK_SET)) {
+        printf ("Internal error: cannot reset position to the start of the "
+                "file \"%s\"\n", datafile);
+
+        exit (1);
+      }
+      n_mpfr = mpfr_inp_str (r, stream_mpfr, base, GMP_RNDN);
+      n_mpfi = mpfi_inp_str (i, stream_mpfi, base);
+
+      if (n_mpfr != n_mpfi) {
+        printf ("Error: mpfi_inp_str does not read the same number of "
+                "characters as mpfr_inp_str in file \"%s\" line 1.\n"
+                "    read: %u\nexpected: %u\n", datafile, n_mpfi, n_mpfr);
+
+        exit (1);
+      }
+
+      if (!mpfi_is_inside_fr (r, i)) {
+        printf ("Error: when reading the file \"%s\" line 1, the number R "
+                "read with\nmpfr_inp_str (R, \"%s\", %u, MPFR_RNDN)\nis not "
+                "included in the interval I read with\nmpfi_inp_str "
+                "(I, \"%s\", %u)\nR = ", datafile, datafile, base, datafile,
+                base);
+        mpfr_out_str (stdout, base, 0, r, GMP_RNDN);
+        printf ("(in base %u)\nI = ", base);
+        mpfi_out_str (stdout, base, 0, i);
+        printf ("(in base %u)\n", base);
+
+        exit (1);
+      }
+    }
+
+    while ((c = getc (stream_mpfr)) != EOF) {
+      ungetc (c, stream_mpfr);
+
+      n_mpfr = mpfr_inp_str (r, stream_mpfr, 10, GMP_RNDN);
+      n_mpfi = mpfi_inp_str (i, stream_mpfi, 10);
+
+      if (n_mpfr != n_mpfi) {
+        printf ("Error: mpfi_inp_str does not read the same number of "
+                "characters as mpfr_inp_str in file \"%s\" line 1.\n"
+                "    read: %u\nexpected: %u\n", datafile, n_mpfi, n_mpfr);
+
+        exit (1);
+      }
+
+      if (!mpfi_is_inside_fr (r, i)) {
+        printf ("Error: when reading the file \"%s\" line 1, the number R "
+                "read with\nmpfr_inp_str (R, \"%s\", 10, MPFR_RNDN)\nis not "
+                "included in the interval I read with\nmpfi_inp_str "
+                "(I, \"%s\", 10)\nR = ", datafile, datafile, datafile);
+        mpfr_out_str (stdout, 16, 0, r, GMP_RNDN);
+        printf ("(in base 16)\nI = ");
+        mpfi_out_str (stdout, 16, 0, i);
+        printf ("(in base 16)\n");
+
+        exit (1);
+      }
+    }
+  }
+
+  fclose (stream_mpfr);
+  fclose (stream_mpfi);
+
+  mpfr_clear (r);
+  mpfi_clear (i);
+}
+
+int
+main (int argc, char **argv)
+{
+  test_start ();
+
+  check_random_interval (2, 1000, 43);
+  check_file ("inp_str.dat");
+
+  test_end ();
+
+  return 0;
+}




More information about the Mpfi-commits mailing list