Skip to content

Commit 086a761

Browse files
committed
tests: Add tests for boundmeth; and bignum cmp, unary, float, error.
1 parent 25f1264 commit 086a761

5 files changed

Lines changed: 73 additions & 0 deletions

File tree

tests/basics/boundmeth1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# tests basics of bound methods
2+
3+
# uPy and CPython differ when printing a bound method, so just print the type
4+
print(type(repr([].append)))
5+
6+
class A:
7+
def f(self):
8+
return 0
9+
def g(self, a):
10+
return a
11+
def h(self, a, b, c, d, e, f):
12+
return a + b + c + d + e + f
13+
14+
# bound method with no extra args
15+
m = A().f
16+
print(m())
17+
18+
# bound method with 1 extra arg
19+
m = A().g
20+
print(m(1))
21+
22+
# bound method with lots of extra args
23+
m = A().h
24+
print(m(1, 2, 3, 4, 5, 6))

tests/basics/int_big_cmp.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# test bignum comparisons
2+
3+
i = 1 << 65
4+
5+
print(i == 0)
6+
print(i != 0)
7+
print(i < 0)
8+
print(i > 0)
9+
print(i <= 0)
10+
print(i >= 0)

tests/basics/int_big_error.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# test errors operating on bignum
2+
3+
i = 1 << 65
4+
5+
try:
6+
i << -1
7+
except ValueError:
8+
print("ValueError")
9+
10+
try:
11+
len(i)
12+
except TypeError:
13+
print("TypeError")
14+
15+
try:
16+
1 in i
17+
except TypeError:
18+
print("TypeError")

tests/basics/int_big_unary.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# test bignum unary operations
2+
3+
i = 1 << 65
4+
5+
print(bool(i))
6+
print(+i)
7+
print(-i)
8+
print(~i)

tests/float/int_big_float.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# test bignum operation with float/complex
2+
3+
i = 1 << 65
4+
5+
# this should convert to float
6+
print("%.5g" % (i / 5))
7+
8+
# these should delegate to float
9+
print("%.5g" % (i * 1.2))
10+
print("%.5g" % (i / 1.2))
11+
12+
# this should delegate to complex
13+
print("%.5g" % (i * 1.2j).imag)

0 commit comments

Comments
 (0)