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

ptheveny at users.gforge.inria.fr ptheveny at users.gforge.inria.fr
Jeu 24 Juin 17:10:51 CEST 2010


Author: ptheveny
Date: 2010-06-24 17:10:51 +0200 (Thu, 24 Jun 2010)
New Revision: 337

Added:
   trunk/mpfi/tests/tcmp_ui.c
Modified:
   trunk/mpfi/tests/Makefile.am
Log:
Add tests for mpfi_cmp_ui

Modified: trunk/mpfi/tests/Makefile.am
===================================================================
--- trunk/mpfi/tests/Makefile.am	2010-06-24 15:03:38 UTC (rev 336)
+++ trunk/mpfi/tests/Makefile.am	2010-06-24 15:10:51 UTC (rev 337)
@@ -11,25 +11,25 @@
 
 check_PROGRAMS = tabs tacos tacosh tadd tadd_d tadd_fr		\
     tadd_q tadd_si tadd_ui tadd_z tasin tasinh tatan tatan2	\
-    tatanh tbisect tblow tcbrt tcmp tcmp_d tconst_catalan	\
-    tconst_euler tconst_log2 tconst_pi tcos tcosh tcot tcoth	\
-    tcsc tcsch td_div td_sub tdiam tdiam_abs tdiam_rel tdiv	\
-    tdiv_2exp tdiv_2si tdiv_2ui tdiv_d tdiv_fr tdiv_q		\
-    tdiv_si tdiv_ui tdiv_z terror texp texp2 texpm1 tfr_div	\
-    tfr_sub tget_d tget_endpoints tget_fr thas_zero thypot	\
-    tincrease tinit_set tintersect tinterv_d tinterv_fr		\
-    tinterv_q tinterv_si tinterv_ui tinterv_z tinv tio_str	\
-    tis_empty tis_inside tis_inside_d tis_inside_fr		\
-    tis_inside_q tis_inside_si tis_inside_ui tis_inside_z	\
-    tis_strictly_inside tlog tlog10 tlog1p tlog2 tmag tmid	\
-    tmig tmul tmul_2exp tmul_2si tmul_2ui tmul_d tmul_fr	\
-    tmul_q tmul_si tmul_ui 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_si tsub_ui tsub_z tswap	\
-    ttan ttanh tui_div tui_sub tunion tz_div tz_sub		\
-    tget_version
+    tatanh tbisect tblow tcbrt tcmp tcmp_d tcmp_ui		\
+    tconst_catalan tconst_euler tconst_log2 tconst_pi tcos	\
+    tcosh tcot tcoth tcsc tcsch td_div td_sub tdiam		\
+    tdiam_abs tdiam_rel tdiv tdiv_2exp tdiv_2si tdiv_2ui	\
+    tdiv_d tdiv_fr tdiv_q tdiv_si tdiv_ui tdiv_z terror texp	\
+    texp2 texpm1 tfr_div tfr_sub tget_d tget_endpoints		\
+    tget_fr thas_zero thypot tincrease tinit_set tintersect	\
+    tinterv_d tinterv_fr tinterv_q tinterv_si tinterv_ui	\
+    tinterv_z tinv tio_str tis_empty tis_inside tis_inside_d	\
+    tis_inside_fr tis_inside_q tis_inside_si tis_inside_ui	\
+    tis_inside_z tis_strictly_inside tlog tlog10 tlog1p		\
+    tlog2 tmag tmid tmig tmul tmul_2exp tmul_2si tmul_2ui	\
+    tmul_d tmul_fr tmul_q tmul_si tmul_ui 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_si		\
+    tsub_ui tsub_z tswap ttan ttanh tui_div tui_sub tunion	\
+    tz_div tz_sub tget_version
 
 EXTRA_DIST = abs.dat acos.dat acosh.dat add.dat add_d.dat	\
     add_fr.dat add_q.dat add_si.dat add_ui.dat add_z.dat	\

Added: trunk/mpfi/tests/tcmp_ui.c
===================================================================
--- trunk/mpfi/tests/tcmp_ui.c	                        (rev 0)
+++ trunk/mpfi/tests/tcmp_ui.c	2010-06-24 15:10:51 UTC (rev 337)
@@ -0,0 +1,120 @@
+/* tcmp_ui.c -- Test mpfi_cmp_ui.
+
+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"
+
+#include <limits.h>
+#ifndef ULONG_MAX
+# define ULONG_MAX 4294967295
+#endif
+
+#define ORDER(min, max)                         \
+  do {                                          \
+    if (min > max) {                            \
+      unsigned long tmp;                        \
+      tmp = min;                                \
+      min = max;                                \
+      max = tmp;}                               \
+  } while (0)
+
+static void
+print_error (unsigned long x, mpfi_srcptr i)
+{
+  printf ("Error: mpfi_cmp_ui (x, I) returns %d\nx = %lu\nI = ",
+          mpfi_cmp_ui (i, x), x);
+  mpfi_out_str (stdout, 10, 0, i);
+  printf ("\n");
+
+  exit (1);
+}
+
+static void
+check ()
+{
+  mpfi_t interval;
+  unsigned long a, b, c;
+  int cmp;
+  int i;
+
+  i = 1;
+  a = ULONG_MAX;
+  while (a >>= 1) i++;
+
+  mpfi_init2 (interval, i);
+
+  for (i = 0; i <= 1000; ++i) {
+    /* random numbers a < b < c */
+    a = random_ui ();
+    b = random_ui ();
+    c = random_ui ();
+    ORDER (a, b);
+    ORDER (a, c);
+    ORDER (b, c);
+
+    mpfi_interv_ui (interval, b, c);
+    cmp = mpfi_cmp_ui (interval, a);
+    if (cmp < 0 || (cmp == 0 && a != b)) {
+      print_error (a, interval);
+    }
+    mpfr_set_nan (&(interval->right));
+    if (mpfi_cmp_ui (interval, a) != 1) {
+      print_error (a, interval);
+    }
+
+    mpfi_interv_ui (interval, a, c);
+    if (mpfi_cmp_ui (interval, b) != 0) {
+      print_error (b, interval);
+    }
+    mpfr_set_nan (&(interval->right));
+    if (mpfi_cmp_ui (interval, b) != 1) {
+      print_error (b, interval);
+    }
+
+    mpfi_interv_ui (interval, a, b);
+    cmp = mpfi_cmp_ui (interval, c);
+    if (cmp > 0 || (cmp == 0 && c != b)) {
+      print_error (c, interval);
+    }
+    mpfr_set_nan (&(interval->right));
+    if (mpfi_cmp_ui (interval, c) != 1) {
+      print_error (c, interval);
+    }
+  }
+
+  mpfi_clear (interval);
+}
+
+int
+main (int argc, char **argv)
+{
+  test_start ();
+
+  check ();
+
+  test_end ();
+
+  return 0;
+}




More information about the Mpfi-commits mailing list