summaryrefslogtreecommitdiff
path: root/tests/tset_str.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-14 23:05:51 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-02-14 23:05:51 +0000
commit6e5ffc68a8061e42a2680dd99455f89e2f4f8ca9 (patch)
tree3150eedf9dc6ae8d160042147ff46ac533e723dd /tests/tset_str.c
parentf095a6c8a44a63379841097ddfbf4682e56e4036 (diff)
downloadmpfr-6e5ffc68a8061e42a2680dd99455f89e2f4f8ca9.tar.gz
new coverage tests
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2714 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tset_str.c')
-rw-r--r--tests/tset_str.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/tests/tset_str.c b/tests/tset_str.c
index b0c62c7fa..3427ed341 100644
--- a/tests/tset_str.c
+++ b/tests/tset_str.c
@@ -1,6 +1,6 @@
/* Test file for mpfr_set_str.
-Copyright 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -36,7 +36,7 @@ main (int argc, char *argv[])
unsigned long k, bd, nc, i;
char *str, *str2;
mp_exp_t e;
- int base, logbase, prec, baseprec;
+ int base, logbase, prec, baseprec, ret;
tests_start_mpfr ();
@@ -446,6 +446,36 @@ main (int argc, char *argv[])
exit (1);
}
+ /* check invalid input */
+ mpfr_set_ui (x, 1, GMP_RNDN);
+ ret = mpfr_set_str (x, "1", 37, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1);
+ ret = mpfr_set_str (x, "1E10toto", 10, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1);
+ ret = mpfr_set_str (x, "1p10toto", 16, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1);
+ ret = mpfr_set_str (x, "this_is_an_invalid_number_in_base_36", 36, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0 && ret == -1);
+ mpfr_set_prec (x, 135);
+ ret = mpfr_set_str (x, "thisisavalidnumberinbase36", 36, GMP_RNDN);
+ mpfr_set_prec (y, 135);
+ mpfr_set_str (y, "23833565676460972739462619524519814462546", 10, GMP_RNDN);
+ MPFR_ASSERTN(mpfr_cmp (x, y) == 0 && ret == 0);
+
+ /* coverage test for set_str_binary */
+ mpfr_set_str_binary (x, "NaN");
+ MPFR_ASSERTN(mpfr_nan_p (x));
+ mpfr_set_str_binary (x, "Inf");
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+ mpfr_set_str_binary (x, "+Inf");
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) > 0);
+ mpfr_set_str_binary (x, "-Inf");
+ MPFR_ASSERTN(mpfr_inf_p (x) && mpfr_sgn (x) < 0);
+ mpfr_set_prec (x, 3);
+ mpfr_set_str_binary (x, "0.01E2");
+ MPFR_ASSERTN(mpfr_cmp_ui (x, 1) == 0);
+ mpfr_set_str_binary (x, "-0.01E2");
+ MPFR_ASSERTN(mpfr_cmp_si (x, -1) == 0);
mpfr_clear (x);
mpfr_clear (y);