From 3ab6aa3a6d0506e805caa19369bef279c1c789b4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 4 Mar 2017 00:13:27 +0300 Subject: 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_intbig.py | 20 +++++++ tests/basics/array_q.py | 20 ------- 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 ++++++++ tests/basics/bytearray_intbig.py | 1 + tests/basics/bytearray_longint.py | 1 - 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_big1.py | 97 +++++++++++++++++++++++++++++++++ tests/basics/int_bytes.py | 1 - tests/basics/int_bytes_intbig.py | 9 +++ tests/basics/int_bytes_long.py | 7 --- 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_intbig.py | 54 ++++++++++++++++++ tests/basics/int_long.py | 54 ------------------ tests/basics/int_mpz.py | 97 --------------------------------- tests/basics/op_error.py | 1 - tests/basics/op_error_intbig.py | 13 +++++ tests/basics/slice_bignum.py | 5 -- tests/basics/slice_intbig.py | 5 ++ tests/basics/struct1.py | 28 ---------- tests/basics/struct1_intbig.py | 37 +++++++++++++ tests/run-tests | 2 +- 40 files changed, 350 insertions(+), 304 deletions(-) create mode 100644 tests/basics/array_intbig.py delete mode 100644 tests/basics/array_q.py 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 create mode 100644 tests/basics/bytearray_intbig.py delete mode 100644 tests/basics/bytearray_longint.py create mode 100644 tests/basics/bytes_construct_intbig.py create mode 100644 tests/basics/floordivide_intbig.py create mode 100644 tests/basics/int_big1.py create mode 100644 tests/basics/int_bytes_intbig.py delete mode 100644 tests/basics/int_bytes_long.py create mode 100644 tests/basics/int_constfolding_intbig.py create mode 100644 tests/basics/int_divmod_intbig.py create mode 100644 tests/basics/int_intbig.py delete mode 100644 tests/basics/int_long.py delete mode 100644 tests/basics/int_mpz.py create mode 100644 tests/basics/op_error_intbig.py delete mode 100644 tests/basics/slice_bignum.py create mode 100644 tests/basics/slice_intbig.py create mode 100644 tests/basics/struct1_intbig.py (limited to 'tests') diff --git a/tests/basics/array_intbig.py b/tests/basics/array_intbig.py new file mode 100644 index 000000000..2975cd385 --- /dev/null +++ b/tests/basics/array_intbig.py @@ -0,0 +1,20 @@ +# test array('q') and array('Q') + +try: + from array import array +except ImportError: + import sys + print("SKIP") + sys.exit() + +print(array('q')) +print(array('Q')) + +print(array('q', [0])) +print(array('Q', [0])) + +print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1])) +print(array('Q', [0, 1, 2, 2**64-1])) + +print(bytes(array('q', [-1]))) +print(bytes(array('Q', [2**64-1]))) diff --git a/tests/basics/array_q.py b/tests/basics/array_q.py deleted file mode 100644 index 2975cd385..000000000 --- a/tests/basics/array_q.py +++ /dev/null @@ -1,20 +0,0 @@ -# test array('q') and array('Q') - -try: - from array import array -except ImportError: - import sys - print("SKIP") - sys.exit() - -print(array('q')) -print(array('Q')) - -print(array('q', [0])) -print(array('Q', [0])) - -print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1])) -print(array('Q', [0, 1, 2, 2**64-1])) - -print(bytes(array('q', [-1]))) -print(bytes(array('Q', [2**64-1]))) diff --git a/tests/basics/builtin_abs.py b/tests/basics/builtin_abs.py index 788bc450f..142344e22 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 000000000..3dd5ea89f --- /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 f6b6079de..85af406ce 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 000000000..345e1f687 --- /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 c3b865819..26b3ae382 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 000000000..758e83415 --- /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 ffea08e57..704895fbb 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 000000000..0092c0f3a --- /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 7d1c98a7a..95d74257e 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 000000000..7049ca3f5 --- /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 d8ba8e434..6dc48a6fa 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 000000000..4dc28ab46 --- /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 35e143a38..dec7253bb 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 000000000..9f482cbde --- /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_intbig.py b/tests/basics/bytearray_intbig.py new file mode 100644 index 000000000..334eabe12 --- /dev/null +++ b/tests/basics/bytearray_intbig.py @@ -0,0 +1 @@ +print(bytearray(2**65 - (2**65 - 1))) diff --git a/tests/basics/bytearray_longint.py b/tests/basics/bytearray_longint.py deleted file mode 100644 index 334eabe12..000000000 --- a/tests/basics/bytearray_longint.py +++ /dev/null @@ -1 +0,0 @@ -print(bytearray(2**65 - (2**65 - 1))) diff --git a/tests/basics/bytes_construct.py b/tests/basics/bytes_construct.py index 59e02f063..164738767 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 000000000..c32de185f --- /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 930313d6c..60e7634b1 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 000000000..422329fcd --- /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_big1.py b/tests/basics/int_big1.py new file mode 100644 index 000000000..425bc21b6 --- /dev/null +++ b/tests/basics/int_big1.py @@ -0,0 +1,97 @@ +# to test arbitrariy precision integers + +x = 1000000000000000000000000000000 +xn = -1000000000000000000000000000000 +y = 2000000000000000000000000000000 + +# printing +print(x) +print(y) +print('%#X' % (x - x)) # print prefix +print('{:#,}'.format(x)) # print with commas + +# addition +print(x + 1) +print(x + y) +print(x + xn == 0) +print(bool(x + xn)) + +# subtraction +print(x - 1) +print(x - y) +print(y - x) +print(x - x == 0) +print(bool(x - x)) + +# multiplication +print(x * 2) +print(x * y) + +# integer division +print(x // 2) +print(y // x) + +# bit inversion +print(~x) +print(~(-x)) + +# left shift +x = 0x10000000000000000000000 +for i in range(32): + x = x << 1 + print(x) + +# right shift +x = 0x10000000000000000000000 +for i in range(32): + x = x >> 1 + print(x) + +# left shift of a negative number +for i in range(8): + print(-10000000000000000000000000 << i) + print(-10000000000000000000000001 << i) + print(-10000000000000000000000002 << i) + print(-10000000000000000000000003 << i) + print(-10000000000000000000000004 << i) + +# right shift of a negative number +for i in range(8): + print(-10000000000000000000000000 >> i) + print(-10000000000000000000000001 >> i) + print(-10000000000000000000000002 >> i) + print(-10000000000000000000000003 >> i) + print(-10000000000000000000000004 >> i) + +# conversion from string +print(int("123456789012345678901234567890")) +print(int("-123456789012345678901234567890")) +print(int("123456789012345678901234567890abcdef", 16)) +print(int("123456789012345678901234567890ABCDEF", 16)) +print(int("1234567890abcdefghijklmnopqrstuvwxyz", 36)) + +# invalid characters in string +try: + print(int("123456789012345678901234567890abcdef")) +except ValueError: + print('ValueError'); + +# test constant integer with more than 255 chars +x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa +print(x) + +# test parsing ints just on threshold of small to big +# for 32 bit archs +x = 1073741823 # small +x = -1073741823 # small +x = 1073741824 # big +x = -1073741824 # big +# for 64 bit archs +x = 4611686018427387903 # small +x = -4611686018427387903 # small +x = 4611686018427387904 # big +x = -4611686018427387904 # big + +# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones +import sys +print(sys.maxsize + 1 - 1 == sys.maxsize) diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 2f468da44..45965ed46 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_intbig.py b/tests/basics/int_bytes_intbig.py new file mode 100644 index 000000000..39cd67d26 --- /dev/null +++ b/tests/basics/int_bytes_intbig.py @@ -0,0 +1,9 @@ +print((2**64).to_bytes(9, "little")) + +b = bytes(range(20)) + +il = int.from_bytes(b, "little") +ib = int.from_bytes(b, "big") +print(il) +print(ib) +print(il.to_bytes(20, "little")) diff --git a/tests/basics/int_bytes_long.py b/tests/basics/int_bytes_long.py deleted file mode 100644 index 81ebc6cdc..000000000 --- a/tests/basics/int_bytes_long.py +++ /dev/null @@ -1,7 +0,0 @@ -b = bytes(range(20)) - -il = int.from_bytes(b, "little") -ib = int.from_bytes(b, "big") -print(il) -print(ib) -print(il.to_bytes(20, "little")) diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index aa38fa6b8..7bb538378 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 000000000..714f1559a --- /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 3c76cd958..2e878135f 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 000000000..ea8de07f2 --- /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_intbig.py b/tests/basics/int_intbig.py new file mode 100644 index 000000000..a22075d1f --- /dev/null +++ b/tests/basics/int_intbig.py @@ -0,0 +1,54 @@ +# This tests long ints for 32-bit machine + +a = 0x1ffffffff +b = 0x100000000 +print(a) +print(b) +print(a + b) +print(a - b) +print(b - a) +# overflows long long implementation +#print(a * b) +print(a // b) +print(a % b) +print("&", a & b) +print(a | b) +print(a ^ b) +print(a << 3) +print(a >> 1) + +a += b +print(a) +a -= 123456 +print(a) +a *= 257 +print(a) +a //= 257 +print(a) +a %= b +print(a) +a ^= b +print(a) +a |= b +print(a) +a &= b +print("&=", a) +a <<= 5 +print(a) +a >>= 1 +print(a) + +# Test referential integrity of long ints +a = 0x1ffffffff +b = a +a += 1 +print(a) +print(b) + +# Bitwise ops on 64-bit + +a = 0x1ffffffffffffffff +b = 0x10000000000000000 +print("&", a & b) +print(a | b) +print(a ^ b) diff --git a/tests/basics/int_long.py b/tests/basics/int_long.py deleted file mode 100644 index a22075d1f..000000000 --- a/tests/basics/int_long.py +++ /dev/null @@ -1,54 +0,0 @@ -# This tests long ints for 32-bit machine - -a = 0x1ffffffff -b = 0x100000000 -print(a) -print(b) -print(a + b) -print(a - b) -print(b - a) -# overflows long long implementation -#print(a * b) -print(a // b) -print(a % b) -print("&", a & b) -print(a | b) -print(a ^ b) -print(a << 3) -print(a >> 1) - -a += b -print(a) -a -= 123456 -print(a) -a *= 257 -print(a) -a //= 257 -print(a) -a %= b -print(a) -a ^= b -print(a) -a |= b -print(a) -a &= b -print("&=", a) -a <<= 5 -print(a) -a >>= 1 -print(a) - -# Test referential integrity of long ints -a = 0x1ffffffff -b = a -a += 1 -print(a) -print(b) - -# Bitwise ops on 64-bit - -a = 0x1ffffffffffffffff -b = 0x10000000000000000 -print("&", a & b) -print(a | b) -print(a ^ b) diff --git a/tests/basics/int_mpz.py b/tests/basics/int_mpz.py deleted file mode 100644 index 425bc21b6..000000000 --- a/tests/basics/int_mpz.py +++ /dev/null @@ -1,97 +0,0 @@ -# to test arbitrariy precision integers - -x = 1000000000000000000000000000000 -xn = -1000000000000000000000000000000 -y = 2000000000000000000000000000000 - -# printing -print(x) -print(y) -print('%#X' % (x - x)) # print prefix -print('{:#,}'.format(x)) # print with commas - -# addition -print(x + 1) -print(x + y) -print(x + xn == 0) -print(bool(x + xn)) - -# subtraction -print(x - 1) -print(x - y) -print(y - x) -print(x - x == 0) -print(bool(x - x)) - -# multiplication -print(x * 2) -print(x * y) - -# integer division -print(x // 2) -print(y // x) - -# bit inversion -print(~x) -print(~(-x)) - -# left shift -x = 0x10000000000000000000000 -for i in range(32): - x = x << 1 - print(x) - -# right shift -x = 0x10000000000000000000000 -for i in range(32): - x = x >> 1 - print(x) - -# left shift of a negative number -for i in range(8): - print(-10000000000000000000000000 << i) - print(-10000000000000000000000001 << i) - print(-10000000000000000000000002 << i) - print(-10000000000000000000000003 << i) - print(-10000000000000000000000004 << i) - -# right shift of a negative number -for i in range(8): - print(-10000000000000000000000000 >> i) - print(-10000000000000000000000001 >> i) - print(-10000000000000000000000002 >> i) - print(-10000000000000000000000003 >> i) - print(-10000000000000000000000004 >> i) - -# conversion from string -print(int("123456789012345678901234567890")) -print(int("-123456789012345678901234567890")) -print(int("123456789012345678901234567890abcdef", 16)) -print(int("123456789012345678901234567890ABCDEF", 16)) -print(int("1234567890abcdefghijklmnopqrstuvwxyz", 36)) - -# invalid characters in string -try: - print(int("123456789012345678901234567890abcdef")) -except ValueError: - print('ValueError'); - -# test constant integer with more than 255 chars -x = 0x84ce72aa8699df436059f052ac51b6398d2511e49631bcb7e71f89c499b9ee425dfbc13a5f6d408471b054f2655617cbbaf7937b7c80cd8865cf02c8487d30d2b0fbd8b2c4e102e16d828374bbc47b93852f212d5043c3ea720f086178ff798cc4f63f787b9c2e419efa033e7644ea7936f54462dc21a6c4580725f7f0e7d1aaaaaaa -print(x) - -# test parsing ints just on threshold of small to big -# for 32 bit archs -x = 1073741823 # small -x = -1073741823 # small -x = 1073741824 # big -x = -1073741824 # big -# for 64 bit archs -x = 4611686018427387903 # small -x = -4611686018427387903 # small -x = 4611686018427387904 # big -x = -4611686018427387904 # big - -# sys.maxsize is a constant mpz, so test it's compatible with dynamic ones -import sys -print(sys.maxsize + 1 - 1 == sys.maxsize) diff --git a/tests/basics/op_error.py b/tests/basics/op_error.py index 5ba6a80e2..b30b5f0a3 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 000000000..432c05a9f --- /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_bignum.py deleted file mode 100644 index cc820522b..000000000 --- a/tests/basics/slice_bignum.py +++ /dev/null @@ -1,5 +0,0 @@ -# test slicing when arguments are bignums - -print(list(range(10))[(1<<66)>>65:]) -print(list(range(10))[:(1<<66)>>65]) -print(list(range(10))[::(1<<66)>>65]) diff --git a/tests/basics/slice_intbig.py b/tests/basics/slice_intbig.py new file mode 100644 index 000000000..cc820522b --- /dev/null +++ b/tests/basics/slice_intbig.py @@ -0,0 +1,5 @@ +# test slicing when arguments are bignums + +print(list(range(10))[(1<<66)>>65:]) +print(list(range(10))[:(1<<66)>>65]) +print(list(range(10))[::(1<<66)>>65]) diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index d89519a2f..bb6877c78 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("