Browse Source
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.pull/2851/merge
Paul Sokolovsky
8 years ago
34 changed files with 166 additions and 120 deletions
@ -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)) |
@ -0,0 +1,3 @@ |
|||
# test builtin bin function |
|||
|
|||
print(bin(12345678901234567890)) |
@ -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)) |
@ -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) |
@ -0,0 +1,4 @@ |
|||
# test builtin hex function |
|||
|
|||
print(hex(12345678901234567890)) |
|||
print(hex(0x12345678901234567890)) |
@ -0,0 +1,4 @@ |
|||
# test builtin oct function |
|||
|
|||
print(oct(12345678901234567890)) |
|||
print(oct(0o12345670123456701234)) |
@ -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' |
@ -0,0 +1,4 @@ |
|||
# test construction of bytes from different objects |
|||
|
|||
# long ints |
|||
print(ord(bytes([14953042807679334000 & 0xff]))) |
@ -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) |
@ -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")) |
|||
|
@ -1,3 +1,5 @@ |
|||
print((2**64).to_bytes(9, "little")) |
|||
|
|||
b = bytes(range(20)) |
|||
|
|||
il = int.from_bytes(b, "little") |
@ -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))) |
@ -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) |
@ -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) |
@ -0,0 +1,37 @@ |
|||
try: |
|||
import ustruct as struct |
|||
except: |
|||
try: |
|||
import struct |
|||
except ImportError: |
|||
import sys |
|||
print("SKIP") |
|||
sys.exit() |
|||
|
|||
# check maximum pack on 32-bit machine |
|||
print(struct.pack("<I", 2**32 - 1)) |
|||
print(struct.pack("<I", 0xffffffff)) |
|||
|
|||
# long long ints |
|||
print(struct.pack("<Q", 2**64 - 1)) |
|||
print(struct.pack(">Q", 2**64 - 1)) |
|||
print(struct.pack("<Q", 0xffffffffffffffff)) |
|||
print(struct.pack(">Q", 0xffffffffffffffff)) |
|||
print(struct.pack("<q", -1)) |
|||
print(struct.pack(">q", -1)) |
|||
print(struct.pack("<Q", 1234567890123456789)) |
|||
print(struct.pack("<q", -1234567890123456789)) |
|||
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"\x12\x34\x56\x78\x90\x12\x34\x56")) |
|||
print(struct.unpack("<q", b"\x12\x34\x56\x78\x90\x12\x34\xf6")) |
|||
print(struct.unpack(">q", b"\xf2\x34\x56\x78\x90\x12\x34\x56")) |
|||
|
|||
# check maximum unpack |
|||
print(struct.unpack("<I", b"\xff\xff\xff\xff")) |
|||
print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff")) |
|||
|
|||
# check small int overflow |
|||
print(struct.unpack("<i", b'\xff\xff\xff\x7f')) |
|||
print(struct.unpack("<q", b'\xff\xff\xff\xff\xff\xff\xff\x7f')) |
Loading…
Reference in new issue