8000 tests/basics: Add tests for equality between bool and int/float/complex. · boris93/micropython@27465e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27465e6

Browse files
committed
tests/basics: Add tests for equality between bool and int/float/complex.
False/True should be implicitly converted to 0/1 when compared with numeric types.
1 parent 9ec1caf commit 27465e6

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

tests/basics/bool1.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@
1010
print(+True)
1111
print(-True)
1212

13+
# comparison with itself
14+
print(False == False)
15+
print(False == True)
16+
print(True == False)
17+
print(True == True)
18+
print(False != False)
19+
print(False != True)
20+
print(True != False)
21+
print(True != True)
22+
23+
# comparison with integers
24+
print(False == 0)
25+
print(0 == False)
26+
print(True == 1)
27+
print(1 == True)
28+
print(True == 2)
29+
print(2 == True)
30+
print(False != 0)
31+
print(0 != False)
32+
print(True != 1)
33+
print(1 != True)
34+
print(True != 2)
35+
print(2 != True)
36+
1337
# unsupported unary op
1438
try:
1539
len(False)

tests/basics/dict1.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@
2323
# equality operator on dicts of same size but with different keys
2424
print({1:1} == {2:1})
2525

26+
# 0 replacing False's item
27+
d = {}
28+
d[False] = 'false'
29+
d[0] = 'zero'
30+
print(d)
31+
32+
# False replacing 0's item
33+
d = {}
34+
d[0] = 'zero'
35+
d[False] = 'false'
36+
print(d)
37+
38+
# 1 replacing True's item
39+
d = {}
40+
d[True] = 'true'
41+
d[1] = 'one'
42+
print(d)
43+
44+
# True replacing 1's item
45+
d = {}
46+
d[1] = 'one'
47+
d[True] = 'true'
48+
print(d)
49+
50+
# mixed bools and integers
51+
d = {False:10, True:11, 2:12}
52+
print(d[0], d[1], d[2])
53+
2654
# value not found
2755
try:
2856
{}[0]

tests/basics/set_add.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
s = {1, 2, 3, 4}
22
print(s.add(5))
33
print(sorted(s))
4+
5+
s = set()
6+
s.add(0)
7+
s.add(False)
8+
print(s)
9+
10+
s = set()
11+
s.add(False)
12+
s.add(0)
13+
print(s)
14+
15+
s = set()
16+
s.add(1)
17+
s.add(True)
18+
print(s)
19+
20+
s = set()
21+
s.add(True)
22+
s.add(1)
23+
print(s)

tests/basics/set_basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
s = {1 + len(s)}
1111
print(s)
1212

13+
# bools mixed with integers
14+
s = {False, True, 0, 1, 2}
15+
print(len(s))
16+
1317
# Sets are not hashable
1418
try:
1519
{s: 1}

tests/float/complex1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
# comparison
3737
print(1j == 1)
3838
print(1j == 1j)
39+
print(0 + 0j == False, 1 + 0j == True)
40+
print(False == 0 + 0j, True == 1 + 0j)
3941

4042
# comparison of nan is special
4143
nan = float('nan') * 1j

tests/float/float1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
print(1.2 <= -3.4)
6565
print(1.2 >= 3.4)
6666
print(1.2 >= -3.4)
67+
print(0.0 == False, 1.0 == True)
68+
print(False == 0.0, True == 1.0)
6769

6870
# comparison of nan is special
6971
nan = float('nan')

0 commit comments

Comments
 (0)
0