tests: Add tests for boundmeth; and bignum cmp, unary, float, error.
This commit is contained in:
parent
25f1264699
commit
086a7616dd
24
tests/basics/boundmeth1.py
Normal file
24
tests/basics/boundmeth1.py
Normal 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))
|
10
tests/basics/int_big_cmp.py
Normal file
10
tests/basics/int_big_cmp.py
Normal 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)
|
18
tests/basics/int_big_error.py
Normal file
18
tests/basics/int_big_error.py
Normal 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")
|
8
tests/basics/int_big_unary.py
Normal file
8
tests/basics/int_big_unary.py
Normal file
@ -0,0 +1,8 @@
|
||||
# test bignum unary operations
|
||||
|
||||
i = 1 << 65
|
||||
|
||||
print(bool(i))
|
||||
print(+i)
|
||||
print(-i)
|
||||
print(~i)
|
13
tests/float/int_big_float.py
Normal file
13
tests/float/int_big_float.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user