summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-02-25 23:43:16 +1100
committerDamien George <damien.p.george@gmail.com>2018-02-25 23:43:16 +1100
commit62be14d77c1c61c7636e9ffe6b7e0c744ace58c6 (patch)
tree844482c0504c0a1de9f0a2a5241ffc1b00e1aa26
parentf75c7ad1a9dcfa2cfe5ccd12dda7c396a6bd973c (diff)
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.
-rw-r--r--ports/unix/coverage.c33
-rw-r--r--tests/unix/extra_coverage.py.exp6
2 files changed, 39 insertions, 0 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c
index 6b6b89285..25376edc0 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<x<1 as argument
+ mpz_set_from_float(&mpz, 1e-10);
+ mpz_as_uint_checked(&mpz, &value);
+ mp_printf(&mp_plat_print, "%d\n", (int)value);
+
+ // mpz_set_from_float with 1<=x<2 as argument
+ mpz_set_from_float(&mpz, 1.5);
+ mpz_as_uint_checked(&mpz, &value);
+ mp_printf(&mp_plat_print, "%d\n", (int)value);
+
+ // mpz_set_from_float with 2<x as argument
+ mpz_set_from_float(&mpz, 12345);
+ mpz_as_uint_checked(&mpz, &value);
+ mp_printf(&mp_plat_print, "%d\n", (int)value);
+
+ // mpz_mul_inpl with dest==rhs, lhs!=rhs
+ mpz_t mpz2;
+ mpz_set_from_int(&mpz, 2);
+ mpz_init_from_int(&mpz2, 3);
+ mpz_mul_inpl(&mpz, &mpz2, &mpz);
+ mpz_as_uint_checked(&mpz, &value);
+ mp_printf(&mp_plat_print, "%d\n", (int)value);
}
// runtime utils
diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp
index 8a2c6aea9..71b6867ca 100644
--- a/tests/unix/extra_coverage.py.exp
+++ b/tests/unix/extra_coverage.py.exp
@@ -41,6 +41,12 @@ data
12345678
0
0
+0
+0
+0
+1
+12345
+6
# runtime utils
TypeError: unsupported type for __abs__: 'str'
TypeError: unsupported types for __divmod__: 'str', 'str'