[Gmp-commit] /var/hg/gmp: tests/mpq/reuse.c: New test (adapted from mpf/reuse.c)
mercurial at gmplib.org
mercurial at gmplib.org
Thu Dec 6 09:34:19 CET 2012
details: /var/hg/gmp/rev/cd0b20b23d2a
changeset: 15163:cd0b20b23d2a
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Thu Dec 06 09:34:11 2012 +0100
description:
tests/mpq/reuse.c: New test (adapted from mpf/reuse.c)
diffstat:
ChangeLog | 5 +
tests/mpq/Makefile.am | 2 +-
tests/mpq/reuse.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 204 insertions(+), 1 deletions(-)
diffs (226 lines):
diff -r 71cab51c5bfe -r cd0b20b23d2a ChangeLog
--- a/ChangeLog Wed Dec 05 22:14:22 2012 +0100
+++ b/ChangeLog Thu Dec 06 09:34:11 2012 +0100
@@ -1,3 +1,8 @@
+2012-12-06 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * tests/mpq/reuse.c: New test (adapted from mpf/reuse.c).
+ * tests/mpq/Makefile.am (check_PROGRAMS): Add reuse.
+
2012-12-05 Niels Möller <nisse at lysator.liu.se>
* mpn/generic/brootinv.c (mpn_brootinv): Make valgrind happier, at
diff -r 71cab51c5bfe -r cd0b20b23d2a tests/mpq/Makefile.am
--- a/tests/mpq/Makefile.am Wed Dec 05 22:14:22 2012 +0100
+++ b/tests/mpq/Makefile.am Thu Dec 06 09:34:11 2012 +0100
@@ -22,7 +22,7 @@
LDADD = $(top_builddir)/tests/libtests.la $(top_builddir)/libgmp.la
check_PROGRAMS = t-aors t-cmp t-cmp_ui t-cmp_si t-equal t-get_d t-get_str \
- t-inp_str t-inv t-md_2exp t-set_f t-set_str io
+ t-inp_str t-inv t-md_2exp t-set_f t-set_str io reuse
TESTS = $(check_PROGRAMS)
# Temporary files used by the tests. Removed automatically if the tests
diff -r 71cab51c5bfe -r cd0b20b23d2a tests/mpq/reuse.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpq/reuse.c Thu Dec 06 09:34:11 2012 +0100
@@ -0,0 +1,198 @@
+/* Test that routines allow reusing a source variable as destination.
+
+Copyright 1996, 2000, 2001, 2002, 2012 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite 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 General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite. If not, see http://www.gnu.org/licenses/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+#if __GMP_LIBGMP_DLL
+
+/* FIXME: When linking to a DLL libgmp, mpq_add etc can't be used as
+ initializers for global variables because they're effectively global
+ variables (function pointers) themselves. Perhaps calling a test
+ function successively with mpq_add etc would be better. */
+
+int
+main (void)
+{
+ printf ("Test suppressed for windows DLL\n");
+ exit (0);
+}
+
+
+#else /* ! DLL_EXPORT */
+
+#ifndef SIZE
+#define SIZE 16
+#endif
+
+void dump_abort (const char *, mpq_t, mpq_t);
+
+typedef void (*dss_func) (mpq_ptr, mpq_srcptr, mpq_srcptr);
+
+dss_func dss_funcs[] =
+{
+ mpq_div, mpq_add, mpq_mul, mpq_sub,
+};
+
+const char *dss_func_names[] =
+{
+ "mpq_div", "mpq_add", "mpq_mul", "mpq_sub",
+};
+
+typedef void (*ds_func) (mpq_ptr, mpq_srcptr);
+
+ds_func ds_funcs[] =
+{
+ mpq_abs, mpq_neg,
+};
+
+const char *ds_func_names[] =
+{
+ "mpq_abs", "mpq_neg",
+};
+
+typedef void (*dsi_func) (mpq_ptr, mpq_srcptr, unsigned long int);
+
+dsi_func dsi_funcs[] =
+{
+ mpq_mul_2exp, mpq_div_2exp
+};
+
+const char *dsi_func_names[] =
+{
+ "mpq_mul_2exp", "mpq_div_2exp"
+};
+
+int
+main (int argc, char **argv)
+{
+ int i;
+ int pass, reps = 100;
+ mpq_t in1, in2, out1;
+ unsigned long int in1i, in2i;
+ mpq_t res1, res2, res3;
+ gmp_randstate_ptr rands;
+
+ tests_start ();
+
+ if (argc > 1)
+ reps = strtol (argv[1], 0, 0);
+
+ rands = RANDS;
+
+ mpq_init (in1);
+ mpq_init (in2);
+ mpq_init (out1);
+ mpq_init (res1);
+ mpq_init (res2);
+ mpq_init (res3);
+
+ for (pass = 1; pass <= reps; pass++)
+ {
+ in2i = urandom ();
+
+ mpz_errandomb (mpq_numref(in1), rands, 512L);
+ mpz_errandomb_nonzero (mpq_denref(in1), rands, 512L);
+ if (in2i & 1)
+ mpz_neg (mpq_numref(in1),mpq_numref(in1));
+ in2i >>= 1;
+ mpq_canonicalize (in1);
+
+ mpz_errandomb (mpq_numref(in2), rands, 512L);
+ mpz_errandomb_nonzero (mpq_denref(in2), rands, 512L);
+ if (in2i & 1)
+ mpz_neg (mpq_numref(in2),mpq_numref(in2));
+ in2i >>= 1;
+ mpq_canonicalize (in2);
+
+ for (i = 0; i < sizeof (dss_funcs) / sizeof (dss_func); i++)
+ {
+ /* Don't divide by 0. */
+ if (i == 0 && mpq_cmp_ui (in2, 0, 1) == 0)
+ continue;
+
+ (dss_funcs[i]) (res1, in1, in2);
+
+ mpq_set (out1, in1);
+ (dss_funcs[i]) (out1, out1, in2);
+ mpq_set (res2, out1);
+
+ mpq_set (out1, in2);
+ (dss_funcs[i]) (out1, in1, out1);
+ mpq_set (res3, out1);
+
+ if (mpq_cmp (res1, res2) != 0)
+ dump_abort (dss_func_names[i], res1, res2);
+ if (mpq_cmp (res1, res3) != 0)
+ dump_abort (dss_func_names[i], res1, res3);
+ }
+
+ for (i = 0; i < sizeof (ds_funcs) / sizeof (ds_func); i++)
+ {
+ (ds_funcs[i]) (res1, in1);
+
+ mpq_set (out1, in1);
+ (ds_funcs[i]) (out1, out1);
+ mpq_set (res2, out1);
+
+ if (mpq_cmp (res1, res2) != 0)
+ dump_abort (ds_func_names[i], res1, res2);
+ }
+
+ in2i %= 65536;
+ for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
+ {
+ (dsi_funcs[i]) (res1, in1, in2i);
+
+ mpq_set (out1, in1);
+ (dsi_funcs[i]) (out1, out1, in2i);
+ mpq_set (res2, out1);
+
+ if (mpq_cmp (res1, res2) != 0)
+ dump_abort (dsi_func_names[i], res1, res2);
+ }
+
+ }
+
+ mpq_clear (in1);
+ mpq_clear (in2);
+ mpq_clear (out1);
+ mpq_clear (res1);
+ mpq_clear (res2);
+ mpq_clear (res3);
+
+ tests_end ();
+ exit (0);
+}
+
+void
+dump_abort (const char *name, mpq_t res1, mpq_t res2)
+{
+ printf ("failure in %s:\n", name);
+ mpq_trace (" res1 ", res1);
+ mpq_trace (" res2 ", res2);
+ abort ();
+}
+
+#endif /* ! DLL_EXPORT */
More information about the gmp-commit
mailing list