Skip to content
Snippets Groups Projects
Commit 086a7616 authored by Damien George's avatar Damien George
Browse files

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

parent 25f12646
No related branches found
No related tags found
No related merge requests found
# 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))
# test bignum comparisons
i = 1 << 65
print(i == 0)
print(i != 0)
print(i < 0)
print(i > 0)
print(i <= 0)
print(i >= 0)
# 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")
# test bignum unary operations
i = 1 << 65
print(bool(i))
print(+i)
print(-i)
print(~i)
# 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment