diff options
author | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-23 10:36:47 +0000 |
---|---|---|
committer | thevenyp <thevenyp@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-03-23 10:36:47 +0000 |
commit | 243a2bd11df5ac0fe907fcfe4b8a6ebe39e05735 (patch) | |
tree | ac4348b4e5d95c83d1bf3de6c761a0c0b8e20eb0 /tests/tio_str.c | |
parent | 5d5659ecb95f76a69964bbd240b783b560b576cc (diff) | |
download | mpc-243a2bd11df5ac0fe907fcfe4b8a6ebe39e05735.tar.gz |
src/inp_str.c: Accept just two levels of parentheses
tests/inp_str.dat: tests with number of read characters
tests/tio_str.c: exit when error, test number of read characters.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@495 211d60ee-9f03-0410-a15a-8952a2c7a4e4
Diffstat (limited to 'tests/tio_str.c')
-rw-r--r-- | tests/tio_str.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/tests/tio_str.c b/tests/tio_str.c index 9cbbd35..83ae34d 100644 --- a/tests/tio_str.c +++ b/tests/tio_str.c @@ -32,6 +32,7 @@ MA 02111-1307, USA. */ extern unsigned long line_number; /* character appearing next in the file, may be EOF */ extern int nextchar; +extern const char *rnd_mode[]; static void check_file (const char* file_name) @@ -41,17 +42,18 @@ check_file (const char* file_name) size_t str_len = 255; char *str = NULL; + int tmp; int base; int inex_re; int inex_im; mpc_t expected, got; mpc_rnd_t rnd = MPC_RNDNN; - int inex = 0, inex_expected; + int inex = 0, expected_inex; + size_t expected_size, size; known_signs_t ks = {1, 1}; - size_t sz; fp = open_data_file (file_name); - + str = (char *) malloc (str_len * sizeof (char)); if (str == NULL) { @@ -73,9 +75,11 @@ check_file (const char* file_name) read_ternary (fp, &inex_im); read_mpc (fp, expected, &ks); if (inex_re == TERNARY_ERROR || inex_im == TERNARY_ERROR) - inex_expected = -1; + expected_inex = -1; else - inex_expected = MPC_INEX (inex_re, inex_im); + expected_inex = MPC_INEX (inex_re, inex_im); + read_int (fp, &tmp, "size"); + expected_size = (size_t)tmp; read_int (fp, &base, "base"); read_mpc_rounding_mode (fp, &rnd); @@ -83,11 +87,26 @@ check_file (const char* file_name) ungetc (nextchar, fp); mpfr_set_prec (MPC_RE (got), MPC_PREC_RE (expected)); mpfr_set_prec (MPC_IM (got), MPC_PREC_IM (expected)); - inex = mpc_inp_str (got, fp, &sz, base, rnd); + inex = mpc_inp_str (got, fp, &size, base, rnd); /* 3. compare this result with the expected one */ - /* TODO */ + if (inex != expected_inex || !same_mpc_value (got, expected, ks) + || size != expected_size) + { + printf ("mpc_inp_str failed (line %lu) with rounding mode %s\n", + line_number, rnd_mode[rnd]); + if (inex != expected_inex) + printf(" got inexact value: %d\nexpected inexact value: %d\n", + inex, expected_inex); + if (size != expected_size) + printf (" got size: %lu\nexpected size: %lu\n ", + size, expected_size); + OUT (got); + OUT (expected); + + exit (1); + } nextchar = getc (fp); skip_whitespace_comments (fp); @@ -123,7 +142,7 @@ check_io_str (mpc_ptr read_number, mpc_ptr expected) exit (1); }; - if (mpc_inp_str (read_number, fp, &sz, 10, MPC_RNDNN) == -1) + if (mpc_inp_str (read_number, fp, &sz, 10, MPC_RNDNN) != 0) { printf ("Error: mpc_inp_str cannot correctly re-read number " "in file %s\n", tmp_file); @@ -133,7 +152,7 @@ check_io_str (mpc_ptr read_number, mpc_ptr expected) fclose (fp); /* mpc_cmp set erange flag when an operand is a NaN */ - mpfr_clear_flags (); + mpfr_clear_flags (); if (mpc_cmp (read_number, expected) != 0 || mpfr_erangeflag_p()) { printf ("Error: inp_str o out_str <> Id\n"); @@ -221,7 +240,7 @@ main (void) #ifndef NO_STREAM_REDIRECTION mpc_set_si_si (x, 1, -4, MPC_RNDNN); mpc_div_ui (x, x, 3, MPC_RNDDU); - + check_stdout(z, x); #endif |