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.
This commit is contained in:
parent
9ec1caf42e
commit
27465e6b24
|
@ -10,6 +10,30 @@ print(False or True)
|
|||
print(+True)
|
||||
print(-True)
|
||||
|
||||
# comparison with itself
|
||||
print(False == False)
|
||||
print(False == True)
|
||||
print(True == False)
|
||||
print(True == True)
|
||||
print(False != False)
|
||||
print(False != True)
|
||||
print(True != False)
|
||||
print(True != True)
|
||||
|
||||
# comparison with integers
|
||||
print(False == 0)
|
||||
print(0 == False)
|
||||
print(True == 1)
|
||||
print(1 == True)
|
||||
print(True == 2)
|
||||
print(2 == True)
|
||||
print(False != 0)
|
||||
print(0 != False)
|
||||
print(True != 1)
|
||||
print(1 != True)
|
||||
print(True != 2)
|
||||
print(2 != True)
|
||||
|
||||
# unsupported unary op
|
||||
try:
|
||||
len(False)
|
||||
|
|
|
@ -23,6 +23,34 @@ print({} == {1:1})
|
|||
# equality operator on dicts of same size but with different keys
|
||||
print({1:1} == {2:1})
|
||||
|
||||
# 0 replacing False's item
|
||||
d = {}
|
||||
d[False] = 'false'
|
||||
d[0] = 'zero'
|
||||
print(d)
|
||||
|
||||
# False replacing 0's item
|
||||
d = {}
|
||||
d[0] = 'zero'
|
||||
d[False] = 'false'
|
||||
print(d)
|
||||
|
||||
# 1 replacing True's item
|
||||
d = {}
|
||||
d[True] = 'true'
|
||||
d[1] = 'one'
|
||||
print(d)
|
||||
|
||||
# True replacing 1's item
|
||||
d = {}
|
||||
d[1] = 'one'
|
||||
d[True] = 'true'
|
||||
print(d)
|
||||
|
||||
# mixed bools and integers
|
||||
d = {False:10, True:11, 2:12}
|
||||
print(d[0], d[1], d[2])
|
||||
|
||||
# value not found
|
||||
try:
|
||||
{}[0]
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
s = {1, 2, 3, 4}
|
||||
print(s.add(5))
|
||||
print(sorted(s))
|
||||
|
||||
s = set()
|
||||
s.add(0)
|
||||
s.add(False)
|
||||
print(s)
|
||||
|
||||
s = set()
|
||||
s.add(False)
|
||||
s.add(0)
|
||||
print(s)
|
||||
|
||||
s = set()
|
||||
s.add(1)
|
||||
s.add(True)
|
||||
print(s)
|
||||
|
||||
s = set()
|
||||
s.add(True)
|
||||
s.add(1)
|
||||
print(s)
|
||||
|
|
|
@ -10,6 +10,10 @@ print(sorted(s))
|
|||
s = {1 + len(s)}
|
||||
print(s)
|
||||
|
||||
# bools mixed with integers
|
||||
s = {False, True, 0, 1, 2}
|
||||
print(len(s))
|
||||
|
||||
# Sets are not hashable
|
||||
try:
|
||||
{s: 1}
|
||||
|
|
|
@ -36,6 +36,8 @@ ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
|
|||
# comparison
|
||||
print(1j == 1)
|
||||
print(1j == 1j)
|
||||
print(0 + 0j == False, 1 + 0j == True)
|
||||
print(False == 0 + 0j, True == 1 + 0j)
|
||||
|
||||
# comparison of nan is special
|
||||
nan = float('nan') * 1j
|
||||
|
|
|
@ -64,6 +64,8 @@ print(1.2 <= 3.4)
|
|||
print(1.2 <= -3.4)
|
||||
print(1.2 >= 3.4)
|
||||
print(1.2 >= -3.4)
|
||||
print(0.0 == False, 1.0 == True)
|
||||
print(False == 0.0, True == 1.0)
|
||||
|
||||
# comparison of nan is special
|
||||
nan = float('nan')
|
||||
|
|
Loading…
Reference in New Issue