From a81539db25d443826e5247fefda8ae73bad64056 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 1 Oct 2015 18:49:37 +0100 Subject: tests: Add further tests for mpz code. --- unix/coverage.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'unix/coverage.c') diff --git a/unix/coverage.c b/unix/coverage.c index 1f52d9cf8..d6514b9cf 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -3,6 +3,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/repl.h" +#include "py/mpz.h" #if defined(MICROPY_UNIX_COVERAGE) @@ -83,6 +84,29 @@ STATIC mp_obj_t extra_coverage(void) { printf("%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9, false)))); } + // mpz + { + printf("# mpz\n"); + + mp_uint_t value; + mpz_t mpz; + mpz_init_zero(&mpz); + + // mpz_as_uint_checked, with success + mpz_set_from_int(&mpz, 12345678); + printf("%d\n", mpz_as_uint_checked(&mpz, &value)); + printf("%d\n", (int)value); + + // mpz_as_uint_checked, with negative arg + mpz_set_from_int(&mpz, -1); + printf("%d\n", mpz_as_uint_checked(&mpz, &value)); + + // mpz_as_uint_checked, with overflowing arg + mpz_set_from_int(&mpz, 1); + mpz_shl_inpl(&mpz, &mpz, 70); + printf("%d\n", mpz_as_uint_checked(&mpz, &value)); + } + return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage); -- cgit v1.2.3