diff options
author | Damien George <damien.p.george@gmail.com> | 2014-10-22 23:05:50 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-10-22 23:05:50 +0100 |
commit | e72be1b999a3337f74a8e5a8f61705666f834d2b (patch) | |
tree | 6275c2b8eb01130f987df7ebe414f6690b971bec /tests/basics/int_divmod.py | |
parent | 5fc42a6c9733bd8f165be7fa8d70fb614ae8de53 (diff) | |
download | micropython-e72be1b999a3337f74a8e5a8f61705666f834d2b.tar.gz micropython-e72be1b999a3337f74a8e5a8f61705666f834d2b.zip |
py: Fix smallint modulo with negative arguments.
Addresses issue #927.
Diffstat (limited to 'tests/basics/int_divmod.py')
-rw-r--r-- | tests/basics/int_divmod.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/basics/int_divmod.py b/tests/basics/int_divmod.py new file mode 100644 index 0000000000..71a990823e --- /dev/null +++ b/tests/basics/int_divmod.py @@ -0,0 +1,21 @@ +# test integer floor division and modulo + +# test all combination of +/-/0 cases +for i in range(-2, 3): + for j in range(-4, 5): + if j != 0: + print(i, j, i // j, i % j, divmod(i, j)) + +# this tests compiler constant folding +print(123 // 7, 123 % 7) +print(-123 // 7, -123 % 7) +print(123 // -7, 123 % -7) +print(-123 // -7, -123 % -7) + +# this tests bignum modulo +a = 987654321987987987987987987987 +b = 19 +print(a % b) +print(a % -b) +print(-a % b) +print(-a % -b) |