diff options
Diffstat (limited to 'src/unittest.c')
-rw-r--r-- | src/unittest.c | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/src/unittest.c b/src/unittest.c index d02ceea..4bbb436 100644 --- a/src/unittest.c +++ b/src/unittest.c @@ -77,7 +77,7 @@ static const char* error_code_to_string(MPErrorCode error) static void test(char* expression, char* expected, int expected_error) { MPErrorCode error; - MPNumber result; + MPNumber result = mp_new(); char result_str[1024] = ""; error = mp_equation_parse(expression, &options, &result, NULL); @@ -110,6 +110,7 @@ static void test(char* expression, char* expected, int expected_error) fail("'%s' -> error %s, expected error %s", expression, error_code_to_string(error), error_code_to_string(expected_error)); } } + mp_clear(result); } @@ -594,54 +595,35 @@ static void test_equations() static void print_number(MPNumber* x) { - int i, j; - - printf("sign=%d exponent=%d fraction=%d", x->sign, x->exponent, x->fraction[0]); - - for (i = 1; i < MP_SIZE; i++) - { - for (j = i; j < MP_SIZE && x->fraction[j] == 0; j++) - { - /* nothing*/ - } - - if (j == MP_SIZE) - { - printf(",..."); - break; - } - - printf(",%d", x->fraction[i]); - } + mpc_out_str(stdout, 10, 5, x->num, MPC_RNDNN); } static void test_string(const char* number) { - MPNumber t; + MPNumber t = mp_new(); mp_set_from_string(number, 10, &t); printf("MPNumber(%s) -> {", number); print_number(&t); printf("}\n"); + mp_clear(&t); } static void test_integer(int number) { - MPNumber t; + MPNumber t = mp_new(); mp_set_from_integer(number, &t); printf("MPNumber(%d) -> {", number); print_number(&t); printf("}\n"); + mp_clear(&t); } -#include "mp-private.h" static void test_numbers() { - printf("base=%d\n", MP_BASE); - test_integer(0); test_integer(1); test_integer(-1); @@ -687,11 +669,12 @@ static void try(const char* string, bool result, bool expected) static void test_mp() { - MPNumber zero, one, minus_one; - - mp_set_from_integer(0, &zero); - mp_set_from_integer(1, &one); - mp_set_from_integer(-1, &minus_one); + MPNumber zero = mp_new(); + MPNumber one = mp_new(); + MPNumber minus_one = mp_new(); + mp_set_from_integer(0, &zero); + mp_set_from_integer(1, &one); + mp_set_from_integer(-1, &minus_one); try("mp_is_zero(-1)", mp_is_zero(&minus_one), false); try("mp_is_zero(0)", mp_is_zero(&zero), true); @@ -766,6 +749,8 @@ static void test_mp() try("mp_is_less_equal(-1, -1)", mp_is_less_equal (&minus_one, &minus_one), true); try("mp_is_less_equal(-1, 0)", mp_is_less_equal (&minus_one, &zero), true); try("mp_is_less_equal(-1, 1)", mp_is_less_equal (&minus_one, &one), true); + + mp_clear(&zero); mp_clear(&one); mp_clear(&minus_one); } |