diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-06-07 16:03:24 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-06-07 16:03:24 +0000 |
commit | 34988245890b4ab6b92dcf808f8484f9cacdf47e (patch) | |
tree | 6a1dd0f865d54f2a9e2951dcca6b53c08a3b4905 /tests/tsum.c | |
parent | ea0eb9b1fdb96ac533146ac2188fe77fb9ef10ec (diff) | |
download | mpfr-34988245890b4ab6b92dcf808f8484f9cacdf47e.tar.gz |
Improve test by adding special cases.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3626 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tsum.c')
-rw-r--r-- | tests/tsum.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/tsum.c b/tests/tsum.c index 8d49be8b9..953495585 100644 --- a/tests/tsum.c +++ b/tests/tsum.c @@ -197,6 +197,64 @@ test_sum (mp_prec_t f, unsigned long n) free (tab); } +static +void check_special (void) +{ + mpfr_t tab[3], r; + mpfr_ptr *tabp[3]; + int i; + + mpfr_inits (tab[0], tab[1], tab[2], r, NULL); + tabp[0] = tab[0]; + tabp[1] = tab[1]; + tabp[2] = tab[2]; + + i = mpfr_sum (r, &tabp, 0, GMP_RNDN); + if (!MPFR_IS_ZERO (r) || !MPFR_IS_POS (r) || i != 0) + { + printf ("Special case n==0 failed!\n"); + exit (1); + } + + mpfr_set_ui (tab[0], 42, GMP_RNDN); + i = mpfr_sum (r, &tabp, 1, GMP_RNDN); + if (mpfr_cmp_ui (r, 42) || i != 0) + { + printf ("Special case n==1 failed!\n"); + exit (1); + } + + mpfr_set_ui (tab[1], 17, GMP_RNDN); + MPFR_SET_NAN (tab[2]); + i = mpfr_sum (r, &tabp, 3, GMP_RNDN); + if (!MPFR_IS_NAN (r) || i != 0) + { + printf ("Special case NAN failed!\n"); + exit (1); + } + + MPFR_SET_INF (tab[2]); + MPFR_SET_POS (tab[2]); + i = mpfr_sum (r, &tabp, 3, GMP_RNDN); + if (!MPFR_IS_INF (r) || !MPFR_IS_POS (r) || i != 0) + { + printf ("Special case +INF failed!\n"); + exit (1); + } + + MPFR_SET_INF (tab[2]); + MPFR_SET_NEG (tab[2]); + i = mpfr_sum (r, &tabp, 3, GMP_RNDN); + if (!MPFR_IS_INF (r) || !MPFR_IS_NEG (r) || i != 0) + { + printf ("Special case -INF failed!\n"); + exit (1); + } + + mpfr_clears (tab[0], tab[1], tab[2], r, NULL); +} + + int main (void) { @@ -205,6 +263,7 @@ main (void) tests_start_mpfr (); + check_special (); test_sort (1764, 1026); for (p = 2 ; p < 1764 ; p+=17) for (n = 2 ; n < 1026 ; n+=42+p) |