From 62be14d77c1c61c7636e9ffe6b7e0c744ace58c6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 25 Feb 2018 23:43:16 +1100 Subject: [PATCH] tests/unix: Add coverage tests for mpz_set_from_float, mpz_mul_inpl. These new tests cover cases that can't be reached from Python and get coverage of py/mpz.c to 100%. These "unreachable from Python" pieces of code could be removed but they form an integral part of the mpz C API and may be useful for non-Python usage of mpz. --- ports/unix/coverage.c | 33 ++++++++++++++++++++++++++++++++ tests/unix/extra_coverage.py.exp | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 6b6b892856..25376edc02 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -262,6 +262,39 @@ STATIC mp_obj_t extra_coverage(void) { mpz_set_from_int(&mpz, 1); mpz_shl_inpl(&mpz, &mpz, 70); mp_printf(&mp_plat_print, "%d\n", mpz_as_uint_checked(&mpz, &value)); + + // mpz_set_from_float with inf as argument + mpz_set_from_float(&mpz, 1.0 / 0.0); + mpz_as_uint_checked(&mpz, &value); + mp_printf(&mp_plat_print, "%d\n", (int)value); + + // mpz_set_from_float with 0 as argument + mpz_set_from_float(&mpz, 0); + mpz_as_uint_checked(&mpz, &value); + mp_printf(&mp_plat_print, "%d\n", (int)value); + + // mpz_set_from_float with 0