tests: Add tests for boundmeth; and bignum cmp, unary, float, error.

This commit is contained in:
Damien George 2015-03-03 16:45:39 +00:00
parent 25f1264699
commit 086a7616dd
5 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,24 @@
# tests basics of bound methods
# uPy and CPython differ when printing a bound method, so just print the type
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
m = A().f
print(m())
# bound method with 1 extra arg
m = A().g
print(m(1))
# bound method with lots of extra args
m = A().h
print(m(1, 2, 3, 4, 5, 6))

View File

@ -0,0 +1,10 @@
# test bignum comparisons
i = 1 << 65
print(i == 0)
print(i != 0)
print(i < 0)
print(i > 0)
print(i <= 0)
print(i >= 0)

View File

@ -0,0 +1,18 @@
# test errors operating on bignum
i = 1 << 65
try:
i << -1
except ValueError:
print("ValueError")
try:
len(i)
except TypeError:
print("TypeError")
try:
1 in i
except TypeError:
print("TypeError")

View File

@ -0,0 +1,8 @@
# test bignum unary operations
i = 1 << 65
print(bool(i))
print(+i)
print(-i)
print(~i)

View File

@ -0,0 +1,13 @@
# test bignum operation with float/complex
i = 1 << 65
# this should convert to float
print("%.5g" % (i / 5))
# these should delegate to float
print("%.5g" % (i * 1.2))
print("%.5g" % (i / 1.2))
# this should delegate to complex
print("%.5g" % (i * 1.2j).imag)