From 3ab6aa3a6d0506e805caa19369bef279c1c789b4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 4 Mar 2017 00:13:27 +0300 Subject: [PATCH] tests/basic: Split tests into working with small ints and not working. Tests which don't work with small ints are suffixed with _intbig.py. Some of these may still work with long long ints and need to be reclassified later. --- tests/basics/{array_q.py => array_intbig.py} | 0 tests/basics/builtin_abs.py | 8 ---- tests/basics/builtin_abs_intbig.py | 9 +++++ tests/basics/builtin_bin.py | 1 - tests/basics/builtin_bin_intbig.py | 3 ++ tests/basics/builtin_divmod.py | 12 ------ tests/basics/builtin_divmod_intbig.py | 13 +++++++ tests/basics/builtin_hash.py | 8 ---- tests/basics/builtin_hash_intbig.py | 10 +++++ tests/basics/builtin_hex.py | 3 -- tests/basics/builtin_hex_intbig.py | 4 ++ tests/basics/builtin_oct.py | 3 -- tests/basics/builtin_oct_intbig.py | 4 ++ tests/basics/builtin_pow3.py | 14 ------- tests/basics/builtin_pow3_intbig.py | 23 ++++++++++++ ...tearray_longint.py => bytearray_intbig.py} | 0 tests/basics/bytes_construct.py | 3 -- tests/basics/bytes_construct_intbig.py | 4 ++ tests/basics/floordivide.py | 15 -------- tests/basics/floordivide_intbig.py | 15 ++++++++ tests/basics/{int_mpz.py => int_big1.py} | 0 tests/basics/int_bytes.py | 1 - ...{int_bytes_long.py => int_bytes_intbig.py} | 2 + tests/basics/int_constfolding.py | 14 ------- tests/basics/int_constfolding_intbig.py | 19 ++++++++++ tests/basics/int_divmod.py | 8 ---- tests/basics/int_divmod_intbig.py | 9 +++++ tests/basics/{int_long.py => int_intbig.py} | 0 tests/basics/op_error.py | 1 - tests/basics/op_error_intbig.py | 13 +++++++ .../{slice_bignum.py => slice_intbig.py} | 0 tests/basics/struct1.py | 28 -------------- tests/basics/struct1_intbig.py | 37 +++++++++++++++++++ tests/run-tests | 2 +- 34 files changed, 166 insertions(+), 120 deletions(-) rename tests/basics/{array_q.py => array_intbig.py} (100%) create mode 100644 tests/basics/builtin_abs_intbig.py create mode 100644 tests/basics/builtin_bin_intbig.py create mode 100644 tests/basics/builtin_divmod_intbig.py create mode 100644 tests/basics/builtin_hash_intbig.py create mode 100644 tests/basics/builtin_hex_intbig.py create mode 100644 tests/basics/builtin_oct_intbig.py create mode 100644 tests/basics/builtin_pow3_intbig.py rename tests/basics/{bytearray_longint.py => bytearray_intbig.py} (100%) create mode 100644 tests/basics/bytes_construct_intbig.py create mode 100644 tests/basics/floordivide_intbig.py rename tests/basics/{int_mpz.py => int_big1.py} (100%) rename tests/basics/{int_bytes_long.py => int_bytes_intbig.py} (78%) create mode 100644 tests/basics/int_constfolding_intbig.py create mode 100644 tests/basics/int_divmod_intbig.py rename tests/basics/{int_long.py => int_intbig.py} (100%) create mode 100644 tests/basics/op_error_intbig.py rename tests/basics/{slice_bignum.py => slice_intbig.py} (100%) create mode 100644 tests/basics/struct1_intbig.py diff --git a/tests/basics/array_q.py b/tests/basics/array_intbig.py similarity index 100% rename from tests/basics/array_q.py rename to tests/basics/array_intbig.py diff --git a/tests/basics/builtin_abs.py b/tests/basics/builtin_abs.py index 788bc450f8..142344e226 100644 --- a/tests/basics/builtin_abs.py +++ b/tests/basics/builtin_abs.py @@ -4,11 +4,3 @@ print(abs(False)) print(abs(True)) print(abs(1)) print(abs(-1)) - -# bignum -print(abs(123456789012345678901234567890)) -print(abs(-123456789012345678901234567890)) - -# edge cases for 32 and 64 bit archs (small int overflow when negating) -print(abs(-0x3fffffff - 1)) -print(abs(-0x3fffffffffffffff - 1)) diff --git a/tests/basics/builtin_abs_intbig.py b/tests/basics/builtin_abs_intbig.py new file mode 100644 index 0000000000..3dd5ea89fa --- /dev/null +++ b/tests/basics/builtin_abs_intbig.py @@ -0,0 +1,9 @@ +# test builtin abs + +# bignum +print(abs(123456789012345678901234567890)) +print(abs(-123456789012345678901234567890)) + +# edge cases for 32 and 64 bit archs (small int overflow when negating) +print(abs(-0x3fffffff - 1)) +print(abs(-0x3fffffffffffffff - 1)) diff --git a/tests/basics/builtin_bin.py b/tests/basics/builtin_bin.py index f6b6079de5..85af406ce3 100644 --- a/tests/basics/builtin_bin.py +++ b/tests/basics/builtin_bin.py @@ -8,5 +8,4 @@ print(bin(-15)) print(bin(12345)) print(bin(0b10101)) -print(bin(12345678901234567890)) print(bin(0b10101010101010101010)) diff --git a/tests/basics/builtin_bin_intbig.py b/tests/basics/builtin_bin_intbig.py new file mode 100644 index 0000000000..345e1f6873 --- /dev/null +++ b/tests/basics/builtin_bin_intbig.py @@ -0,0 +1,3 @@ +# test builtin bin function + +print(bin(12345678901234567890)) diff --git a/tests/basics/builtin_divmod.py b/tests/basics/builtin_divmod.py index c3b8658197..26b3ae3824 100644 --- a/tests/basics/builtin_divmod.py +++ b/tests/basics/builtin_divmod.py @@ -9,19 +9,7 @@ try: except ZeroDivisionError: print("ZeroDivisionError") -try: - divmod(1 << 65, 0) -except ZeroDivisionError: - print("ZeroDivisionError") - try: divmod('a', 'b') except TypeError: print("TypeError") - -# bignum -l = (1 << 65) + 123 -print(divmod(3, l)) -print(divmod(l, 5)) -print(divmod(l + 3, l)) -print(divmod(l * 20, l + 2)) diff --git a/tests/basics/builtin_divmod_intbig.py b/tests/basics/builtin_divmod_intbig.py new file mode 100644 index 0000000000..758e834151 --- /dev/null +++ b/tests/basics/builtin_divmod_intbig.py @@ -0,0 +1,13 @@ +# test builtin divmod + +try: + divmod(1 << 65, 0) +except ZeroDivisionError: + print("ZeroDivisionError") + +# bignum +l = (1 << 65) + 123 +print(divmod(3, l)) +print(divmod(l, 5)) +print(divmod(l + 3, l)) +print(divmod(l * 20, l + 2)) diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py index ffea08e575..704895fbb6 100644 --- a/tests/basics/builtin_hash.py +++ b/tests/basics/builtin_hash.py @@ -4,8 +4,6 @@ print(hash(False)) print(hash(True)) print({():1}) # hash tuple print({(1,):1}) # hash non-empty tuple -print({1 << 66:1}) # hash big int -print({-(1 << 66):2}) # hash negative big int print(hash in {hash:1}) # hash function try: @@ -50,9 +48,3 @@ class E: def __hash__(self): return True print(hash(E())) - -# __hash__ returning a large number should be truncated -class F: - def __hash__(self): - return 1 << 70 | 1 -print(hash(F()) != 0) diff --git a/tests/basics/builtin_hash_intbig.py b/tests/basics/builtin_hash_intbig.py new file mode 100644 index 0000000000..0092c0f3ad --- /dev/null +++ b/tests/basics/builtin_hash_intbig.py @@ -0,0 +1,10 @@ +# test builtin hash function + +print({1 << 66:1}) # hash big int +print({-(1 << 66):2}) # hash negative big int + +# __hash__ returning a large number should be truncated +class F: + def __hash__(self): + return 1 << 70 | 1 +print(hash(F()) != 0) diff --git a/tests/basics/builtin_hex.py b/tests/basics/builtin_hex.py index 7d1c98a7a9..95d74257ec 100644 --- a/tests/basics/builtin_hex.py +++ b/tests/basics/builtin_hex.py @@ -7,6 +7,3 @@ print(hex(-15)) print(hex(12345)) print(hex(0x12345)) - -print(hex(12345678901234567890)) -print(hex(0x12345678901234567890)) diff --git a/tests/basics/builtin_hex_intbig.py b/tests/basics/builtin_hex_intbig.py new file mode 100644 index 0000000000..7049ca3f55 --- /dev/null +++ b/tests/basics/builtin_hex_intbig.py @@ -0,0 +1,4 @@ +# test builtin hex function + +print(hex(12345678901234567890)) +print(hex(0x12345678901234567890)) diff --git a/tests/basics/builtin_oct.py b/tests/basics/builtin_oct.py index d8ba8e4346..6dc48a6fae 100644 --- a/tests/basics/builtin_oct.py +++ b/tests/basics/builtin_oct.py @@ -7,6 +7,3 @@ print(oct(-15)) print(oct(12345)) print(oct(0o12345)) - -print(oct(12345678901234567890)) -print(oct(0o12345670123456701234)) diff --git a/tests/basics/builtin_oct_intbig.py b/tests/basics/builtin_oct_intbig.py new file mode 100644 index 0000000000..4dc28ab46f --- /dev/null +++ b/tests/basics/builtin_oct_intbig.py @@ -0,0 +1,4 @@ +# test builtin oct function + +print(oct(12345678901234567890)) +print(oct(0o12345670123456701234)) diff --git a/tests/basics/builtin_pow3.py b/tests/basics/builtin_pow3.py index 35e143a388..dec7253bbd 100644 --- a/tests/basics/builtin_pow3.py +++ b/tests/basics/builtin_pow3.py @@ -8,8 +8,6 @@ except NotImplementedError: print("SKIP") sys.exit() -print(pow(555557, 1000002, 1000003)) - # 3 arg pow is defined to only work on integers try: print(pow("x", 5, 6)) @@ -25,15 +23,3 @@ try: print(pow(4, 5, "z")) except TypeError: print("TypeError expected") - -# Tests for 3 arg pow with large values - -# This value happens to be prime -x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 -y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 - -print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 -print(hex(pow(2, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, x-1, x))) # Should be 1, since x is prime -print(hex(pow(y, y-1, x))) # Should be a 'big value' -print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/builtin_pow3_intbig.py b/tests/basics/builtin_pow3_intbig.py new file mode 100644 index 0000000000..9f482cbde7 --- /dev/null +++ b/tests/basics/builtin_pow3_intbig.py @@ -0,0 +1,23 @@ +# test builtin pow() with integral values +# 3 arg version + +try: + print(pow(3, 4, 7)) +except NotImplementedError: + import sys + print("SKIP") + sys.exit() + +print(pow(555557, 1000002, 1000003)) + +# Tests for 3 arg pow with large values + +# This value happens to be prime +x = 0xd48a1e2a099b1395895527112937a391d02d4a208bce5d74b281cf35a57362502726f79a632f063a83c0eba66196712d963aa7279ab8a504110a668c0fc38a7983c51e6ee7a85cae87097686ccdc359ee4bbf2c583bce524e3f7836bded1c771a4efcb25c09460a862fc98e18f7303df46aaeb34da46b0c4d61d5cd78350f3edb60e6bc4befa712a849 +y = 0x3accf60bb1a5365e4250d1588eb0fe6cd81ad495e9063f90880229f2a625e98c59387238670936afb2cafc5b79448e4414d6cd5e9901aa845aa122db58ddd7b9f2b17414600a18c47494ed1f3d49d005a5 + +print(hex(pow(2, 200, x))) # Should not overflow, just 1 << 200 +print(hex(pow(2, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, x-1, x))) # Should be 1, since x is prime +print(hex(pow(y, y-1, x))) # Should be a 'big value' +print(hex(pow(y, y-1, y))) # Should be a 'big value' diff --git a/tests/basics/bytearray_longint.py b/tests/basics/bytearray_intbig.py similarity index 100% rename from tests/basics/bytearray_longint.py rename to tests/basics/bytearray_intbig.py diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py index 59e02f063c..1647387675 100644 --- a/tests/basics/bytes_construct.py +++ b/tests/basics/bytes_construct.py @@ -11,9 +11,6 @@ print(bytes(bytearray(4))) print(bytes(array('b', [1, 2]))) print(bytes(array('h', [0x101, 0x202]))) -# long ints -print(ord(bytes([14953042807679334000 & 0xff]))) - # constructor value out of range try: bytes([-1]) diff --git a/tests/basics/bytes_construct_intbig.py b/tests/basics/bytes_construct_intbig.py new file mode 100644 index 0000000000..c32de185ff --- /dev/null +++ b/tests/basics/bytes_construct_intbig.py @@ -0,0 +1,4 @@ +# test construction of bytes from different objects + +# long ints +print(ord(bytes([14953042807679334000 & 0xff]))) diff --git a/tests/basics/floordivide.py b/tests/basics/floordivide.py index 930313d6c1..60e7634b1b 100644 --- a/tests/basics/floordivide.py +++ b/tests/basics/floordivide.py @@ -12,18 +12,3 @@ print(a // b) print(a // -b) print(-a // b) print(-a // -b) - -if True: - a = 987654321987987987987987987987 - b = 19 - - print(a // b) - print(a // -b) - print(-a // b) - print(-a // -b) - a = 10000000000000000000000000000000000000000000 - b = 100 - print(a // b) - print(a // -b) - print(-a // b) - print(-a // -b) diff --git a/tests/basics/floordivide_intbig.py b/tests/basics/floordivide_intbig.py new file mode 100644 index 0000000000..422329fcd5 --- /dev/null +++ b/tests/basics/floordivide_intbig.py @@ -0,0 +1,15 @@ +# check modulo matches python definition + +a = 987654321987987987987987987987 +b = 19 + +print(a // b) +print(a // -b) +print(-a // b) +print(-a // -b) +a = 10000000000000000000000000000000000000000000 +b = 100 +print(a // b) +print(a // -b) +print(-a // b) +print(-a // -b) diff --git a/tests/basics/int_mpz.py b/tests/basics/int_big1.py similarity index 100% rename from tests/basics/int_mpz.py rename to tests/basics/int_big1.py diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 2f468da444..45965ed464 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -1,7 +1,6 @@ print((10).to_bytes(1, "little")) print((111111).to_bytes(4, "little")) print((100).to_bytes(10, "little")) -print((2**64).to_bytes(9, "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) diff --git a/tests/basics/int_bytes_long.py b/tests/basics/int_bytes_intbig.py similarity index 78% rename from tests/basics/int_bytes_long.py rename to tests/basics/int_bytes_intbig.py index 81ebc6cdcd..39cd67d26f 100644 --- a/tests/basics/int_bytes_long.py +++ b/tests/basics/int_bytes_intbig.py @@ -1,3 +1,5 @@ +print((2**64).to_bytes(9, "little")) + b = bytes(range(20)) il = int.from_bytes(b, "little") diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index aa38fa6b80..7bb5383785 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -7,19 +7,11 @@ print(+100) # negation print(-1) print(-(-1)) -print(-0x3fffffff) # 32-bit edge case -print(-0x3fffffffffffffff) # 64-bit edge case -print(-(-0x3fffffff - 1)) # 32-bit edge case -print(-(-0x3fffffffffffffff - 1)) # 64-bit edge case # 1's complement print(~0) print(~1) print(~-1) -print(~0x3fffffff) # 32-bit edge case -print(~0x3fffffffffffffff) # 64-bit edge case -print(~(-0x3fffffff - 1)) # 32-bit edge case -print(~(-0x3fffffffffffffff - 1)) # 64-bit edge case # addition print(1 + 2) @@ -37,9 +29,3 @@ print(123 // 7, 123 % 7) print(-123 // 7, -123 % 7) print(123 // -7, 123 % -7) print(-123 // -7, -123 % -7) - -# zero big-num on rhs -print(1 + ((1 << 65) - (1 << 65))) - -# negative big-num on rhs -print(1 + (-(1 << 65))) diff --git a/tests/basics/int_constfolding_intbig.py b/tests/basics/int_constfolding_intbig.py new file mode 100644 index 0000000000..714f1559a6 --- /dev/null +++ b/tests/basics/int_constfolding_intbig.py @@ -0,0 +1,19 @@ +# tests int constant folding in compiler + +# negation +print(-0x3fffffff) # 32-bit edge case +print(-0x3fffffffffffffff) # 64-bit edge case +print(-(-0x3fffffff - 1)) # 32-bit edge case +print(-(-0x3fffffffffffffff - 1)) # 64-bit edge case + +# 1's complement +print(~0x3fffffff) # 32-bit edge case +print(~0x3fffffffffffffff) # 64-bit edge case +print(~(-0x3fffffff - 1)) # 32-bit edge case +print(~(-0x3fffffffffffffff - 1)) # 64-bit edge case + +# zero big-num on rhs +print(1 + ((1 << 65) - (1 << 65))) + +# negative big-num on rhs +print(1 + (-(1 << 65))) diff --git a/tests/basics/int_divmod.py b/tests/basics/int_divmod.py index 3c76cd958c..2e878135f0 100644 --- a/tests/basics/int_divmod.py +++ b/tests/basics/int_divmod.py @@ -5,11 +5,3 @@ 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 bignum modulo -a = 987654321987987987987987987987 -b = 19 -print(a % b) -print(a % -b) -print(-a % b) -print(-a % -b) diff --git a/tests/basics/int_divmod_intbig.py b/tests/basics/int_divmod_intbig.py new file mode 100644 index 0000000000..ea8de07f24 --- /dev/null +++ b/tests/basics/int_divmod_intbig.py @@ -0,0 +1,9 @@ +# test integer floor division and modulo + +# this tests bignum modulo +a = 987654321987987987987987987987 +b = 19 +print(a % b) +print(a % -b) +print(-a % b) +print(-a % -b) diff --git a/tests/basics/int_long.py b/tests/basics/int_intbig.py similarity index 100% rename from tests/basics/int_long.py rename to tests/basics/int_intbig.py diff --git a/tests/basics/op_error.py b/tests/basics/op_error.py index 5ba6a80e26..b30b5f0a35 100644 --- a/tests/basics/op_error.py +++ b/tests/basics/op_error.py @@ -23,7 +23,6 @@ test_exc("bytearray() // 2", TypeError) # object with buffer protocol needed on rhs test_exc("bytearray(1) + 1", TypeError) -test_exc("(1 << 70) in 1", TypeError) # unsupported subscription test_exc("1[0]", TypeError) diff --git a/tests/basics/op_error_intbig.py b/tests/basics/op_error_intbig.py new file mode 100644 index 0000000000..432c05a9fe --- /dev/null +++ b/tests/basics/op_error_intbig.py @@ -0,0 +1,13 @@ +# test errors from bad operations (unary, binary, etc) + +def test_exc(code, exc): + try: + exec(code) + print("no exception") + except exc: + print("right exception") + except: + print("wrong exception") + +# object with buffer protocol needed on rhs +test_exc("(1 << 70) in 1", TypeError) diff --git a/tests/basics/slice_bignum.py b/tests/basics/slice_intbig.py similarity index 100% rename from tests/basics/slice_bignum.py rename to tests/basics/slice_intbig.py diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index d89519a2fa..bb6877c785 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -37,34 +37,6 @@ s = struct.pack("BHBI", 10, 100, 200, 300) v = struct.unpack("BHBI", s) print(v == (10, 100, 200, 300)) -# check maximum pack on 32-bit machine -print(struct.pack("Q", 2**64 - 1)) -print(struct.pack("Q", 0xffffffffffffffff)) -print(struct.pack("q", -1)) -print(struct.pack("Q", 1234567890123456789)) -print(struct.pack(">q", -1234567890123456789)) -print(struct.unpack("Q", b"\x12\x34\x56\x78\x90\x12\x34\x56")) -print(struct.unpack("q", b"\xf2\x34\x56\x78\x90\x12\x34\x56")) - -# check maximum unpack -print(struct.unpack("Q", 2**64 - 1)) +print(struct.pack("Q", 0xffffffffffffffff)) +print(struct.pack("q", -1)) +print(struct.pack("Q", 1234567890123456789)) +print(struct.pack(">q", -1234567890123456789)) +print(struct.unpack("Q", b"\x12\x34\x56\x78\x90\x12\x34\x56")) +print(struct.unpack("q", b"\xf2\x34\x56\x78\x90\x12\x34\x56")) + +# check maximum unpack +print(struct.unpack("