diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2012-02-24 11:14:11 +0100 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2012-02-24 11:14:11 +0100 |
commit | 15cafc39ad37fb3f06cd0e769f855b199288fdf4 (patch) | |
tree | e81213fb0aa75cb6d8e069d3fd6caaf0be7c985d /tests/mpq | |
parent | 38a9408ef532be12fb53f765541d32f014302f99 (diff) | |
download | gmp-15cafc39ad37fb3f06cd0e769f855b199288fdf4.tar.gz |
Use macros like NUM, ALLOC, SIZ, etc in mpq/*.
Test some mpq functions that were not used in the testsuite.
Implement q=z (in gmpxx) with mpq_set_z.
Diffstat (limited to 'tests/mpq')
-rw-r--r-- | tests/mpq/Makefile.am | 2 | ||||
-rw-r--r-- | tests/mpq/t-cmp.c | 3 | ||||
-rw-r--r-- | tests/mpq/t-cmp_ui.c | 3 | ||||
-rw-r--r-- | tests/mpq/t-inv.c | 61 |
4 files changed, 62 insertions, 7 deletions
diff --git a/tests/mpq/Makefile.am b/tests/mpq/Makefile.am index 57c6817f9..52df85e12 100644 --- a/tests/mpq/Makefile.am +++ b/tests/mpq/Makefile.am @@ -22,7 +22,7 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/tests 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-md_2exp t-set_f t-set_str + t-inp_str t-inv t-md_2exp t-set_f t-set_str TESTS = $(check_PROGRAMS) # Temporary files used by the tests. Removed automatically if the tests diff --git a/tests/mpq/t-cmp.c b/tests/mpq/t-cmp.c index ac0dc72e7..62a7a9067 100644 --- a/tests/mpq/t-cmp.c +++ b/tests/mpq/t-cmp.c @@ -24,9 +24,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" #include "tests.h" -#define NUM(x) (&((x)->_mp_num)) -#define DEN(x) (&((x)->_mp_den)) - #define SGN(x) ((x) < 0 ? -1 : (x) > 0 ? 1 : 0) int diff --git a/tests/mpq/t-cmp_ui.c b/tests/mpq/t-cmp_ui.c index 3768a77dd..9bf8381e7 100644 --- a/tests/mpq/t-cmp_ui.c +++ b/tests/mpq/t-cmp_ui.c @@ -24,9 +24,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" #include "tests.h" -#define NUM(x) (&((x)->_mp_num)) -#define DEN(x) (&((x)->_mp_den)) - #define SGN(x) ((x) < 0 ? -1 : (x) > 0 ? 1 : 0) int diff --git a/tests/mpq/t-inv.c b/tests/mpq/t-inv.c new file mode 100644 index 000000000..bb9e317af --- /dev/null +++ b/tests/mpq/t-inv.c @@ -0,0 +1,61 @@ +/* Test mpq_inv (and set/get_num/den). + +Copyright 2012 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP 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 3 of the License, or (at your +option) any later version. + +The GNU MP 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 GNU MP Library. If not, see http://www.gnu.org/licenses/. */ + +#include "gmp.h" +#include "gmp-impl.h" +#include "tests.h" + +int +main (int argc, char **argv) +{ + mpq_t a, b; + mpz_t m, n; + const char* s = "-420000000000000000000000"; + + tests_start (); + + mpq_inits (a, b, (mpq_ptr)0); + mpz_inits (m, n, (mpz_ptr)0); + + mpz_set_ui (m, 13); + mpq_set_den (a, m); + mpz_set_str (m, s, 0); + mpq_set_num (a, m); + MPQ_CHECK_FORMAT (a); + mpq_inv (b, a); + MPQ_CHECK_FORMAT (b); + mpq_get_num (n, b); + ASSERT_ALWAYS (mpz_cmp_si (n, -13) == 0); + mpq_neg (b, b); + mpq_inv (a, b); + MPQ_CHECK_FORMAT (a); + mpq_inv (b, b); + MPQ_CHECK_FORMAT (b); + mpq_get_den (n, b); + ASSERT_ALWAYS (mpz_cmp_ui (n, 13) == 0); + mpq_get_num (n, a); + mpz_add (n, n, m); + ASSERT_ALWAYS (mpz_sgn (n) == 0); + + mpq_clears (a, b, (mpq_ptr)0); + mpz_clears (m, n, (mpz_ptr)0); + + tests_end (); + return 0; +} |