tests: Add further tests for mpz code.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user