diff options
| author | Damien George | 2020-02-10 22:22:12 +1100 |
|---|---|---|
| committer | Damien George | 2020-02-11 11:06:17 +1100 |
| commit | 27465e6b24e80fdcdaddd015fe8f690122f78ef8 (patch) | |
| tree | 5bc93de146462c95e47eaa4374df6195e97d5e8e /tests/basics | |
| parent | 9ec1caf42e7733b5141b7aecf1b6e58834a94bf7 (diff) | |
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.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/bool1.py | 24 | ||||
| -rw-r--r-- | tests/basics/dict1.py | 28 | ||||
| -rw-r--r-- | tests/basics/set_add.py | 20 | ||||
| -rw-r--r-- | tests/basics/set_basic.py | 4 |
4 files changed, 76 insertions, 0 deletions
diff --git a/tests/basics/bool1.py b/tests/basics/bool1.py index 35d9ed8cc..daabfb17d 100644 --- a/tests/basics/bool1.py +++ b/tests/basics/bool1.py @@ -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) diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py index 0cec51173..cd793c9ed 100644 --- a/tests/basics/dict1.py +++ b/tests/basics/dict1.py @@ -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] diff --git a/tests/basics/set_add.py b/tests/basics/set_add.py index ac81f4849..d8cfdaad9 100644 --- a/tests/basics/set_add.py +++ b/tests/basics/set_add.py @@ -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) diff --git a/tests/basics/set_basic.py b/tests/basics/set_basic.py index 6ea69e4f0..2d1653622 100644 --- a/tests/basics/set_basic.py +++ b/tests/basics/set_basic.py @@ -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} |
