Skip to content
Snippets Groups Projects
Commit 3ab6aa3a authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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.
parent 89e570a5
Branches
No related tags found
No related merge requests found
Showing
with 85 additions and 67 deletions
File moved
...@@ -4,11 +4,3 @@ print(abs(False)) ...@@ -4,11 +4,3 @@ print(abs(False))
print(abs(True)) print(abs(True))
print(abs(1)) print(abs(1))
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))
# 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))
...@@ -8,5 +8,4 @@ print(bin(-15)) ...@@ -8,5 +8,4 @@ print(bin(-15))
print(bin(12345)) print(bin(12345))
print(bin(0b10101)) print(bin(0b10101))
print(bin(12345678901234567890))
print(bin(0b10101010101010101010)) print(bin(0b10101010101010101010))
# test builtin bin function
print(bin(12345678901234567890))
...@@ -9,19 +9,7 @@ try: ...@@ -9,19 +9,7 @@ try:
except ZeroDivisionError: except ZeroDivisionError:
print("ZeroDivisionError") print("ZeroDivisionError")
try:
divmod(1 << 65, 0)
except ZeroDivisionError:
print("ZeroDivisionError")
try: try:
divmod('a', 'b') divmod('a', 'b')
except TypeError: except TypeError:
print("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))
# 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))
...@@ -4,8 +4,6 @@ print(hash(False)) ...@@ -4,8 +4,6 @@ print(hash(False))
print(hash(True)) print(hash(True))
print({():1}) # hash tuple print({():1}) # hash tuple
print({(1,):1}) # hash non-empty 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 print(hash in {hash:1}) # hash function
try: try:
...@@ -50,9 +48,3 @@ class E: ...@@ -50,9 +48,3 @@ class E:
def __hash__(self): def __hash__(self):
return True return True
print(hash(E())) print(hash(E()))
# __hash__ returning a large number should be truncated
class F:
def __hash__(self):
return 1 << 70 | 1
print(hash(F()) != 0)
# 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)
...@@ -7,6 +7,3 @@ print(hex(-15)) ...@@ -7,6 +7,3 @@ print(hex(-15))
print(hex(12345)) print(hex(12345))
print(hex(0x12345)) print(hex(0x12345))
print(hex(12345678901234567890))
print(hex(0x12345678901234567890))
# test builtin hex function
print(hex(12345678901234567890))
print(hex(0x12345678901234567890))
...@@ -7,6 +7,3 @@ print(oct(-15)) ...@@ -7,6 +7,3 @@ print(oct(-15))
print(oct(12345)) print(oct(12345))
print(oct(0o12345)) print(oct(0o12345))
print(oct(12345678901234567890))
print(oct(0o12345670123456701234))
# test builtin oct function
print(oct(12345678901234567890))
print(oct(0o12345670123456701234))
...@@ -8,8 +8,6 @@ except NotImplementedError: ...@@ -8,8 +8,6 @@ except NotImplementedError:
print("SKIP") print("SKIP")
sys.exit() sys.exit()
print(pow(555557, 1000002, 1000003))
# 3 arg pow is defined to only work on integers # 3 arg pow is defined to only work on integers
try: try:
print(pow("x", 5, 6)) print(pow("x", 5, 6))
...@@ -25,15 +23,3 @@ try: ...@@ -25,15 +23,3 @@ try:
print(pow(4, 5, "z")) print(pow(4, 5, "z"))
except TypeError: except TypeError:
print("TypeError expected") 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'
# 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'
...@@ -11,9 +11,6 @@ print(bytes(bytearray(4))) ...@@ -11,9 +11,6 @@ print(bytes(bytearray(4)))
print(bytes(array('b', [1, 2]))) print(bytes(array('b', [1, 2])))
print(bytes(array('h', [0x101, 0x202]))) print(bytes(array('h', [0x101, 0x202])))
# long ints
print(ord(bytes([14953042807679334000 & 0xff])))
# constructor value out of range # constructor value out of range
try: try:
bytes([-1]) bytes([-1])
......
# test construction of bytes from different objects
# long ints
print(ord(bytes([14953042807679334000 & 0xff])))
...@@ -12,18 +12,3 @@ print(a // b) ...@@ -12,18 +12,3 @@ print(a // b)
print(a // -b) print(a // -b)
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)
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment