forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin_tuple.py
More file actions
95 lines (69 loc) · 2.31 KB
/
builtin_tuple.py
File metadata and controls
95 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from testutils import assert_raises
assert (1, 2) == (1, 2)
x = (1, 2)
assert x[0] == 1
y = (1,)
assert y[0] == 1
assert x + y == (1, 2, 1)
assert x * 3 == (1, 2, 1, 2, 1, 2)
assert 3 * x == (1, 2, 1, 2, 1, 2)
assert x * 0 == ()
assert x * -1 == () # integers less than zero treated as 0
assert y < x, "tuple __lt__ failed"
assert x > y, "tuple __gt__ failed"
b = (1, 2, 3)
assert b.index(2) == 1
recursive_list = []
recursive = (recursive_list,)
recursive_list.append(recursive)
assert repr(recursive) == "([(...)],)"
assert (None, "", 1).index(1) == 2
assert 1 in (None, "", 1)
class Foo(object):
def __eq__(self, x):
return False
foo = Foo()
assert (foo,) == (foo,)
a = (1, 2, 3)
a += (1,)
assert a == (1, 2, 3, 1)
b = (55, *a)
assert b == (55, 1, 2, 3, 1)
assert () is () # noqa
a = ()
b = ()
assert a is b
assert (1,).__ne__((2,))
assert not (1,).__ne__((1,))
# tuple gt, ge, lt, le
assert_raises(TypeError, lambda: (0, ()) < (0, 0))
assert_raises(TypeError, lambda: (0, ()) <= (0, 0))
assert_raises(TypeError, lambda: (0, ()) > (0, 0))
assert_raises(TypeError, lambda: (0, ()) >= (0, 0))
assert_raises(TypeError, lambda: (0, 0) < (0, ()))
assert_raises(TypeError, lambda: (0, 0) <= (0, ()))
assert_raises(TypeError, lambda: (0, 0) > (0, ()))
assert_raises(TypeError, lambda: (0, 0) >= (0, ()))
assert (0, 0) < (1, -1)
assert (0, 0) < (0, 0, 1)
assert (0, 0) < (0, 0, -1)
assert (0, 0) <= (0, 0, -1)
assert not (0, 0, 0, 0) <= (0, -1)
assert (0, 0) > (-1, 1)
assert (0, 0) >= (-1, 1)
assert (0, 0, 0) >= (-1, 1)
assert (0, 0) <= (0, 1)
assert (0, 0) <= (0, 0)
assert (0, 0) <= (0, 0)
assert not (0, 0) > (0, 0)
assert not (0, 0) < (0, 0)
assert not (float("nan"), float("nan")) <= (float("nan"), 1)
assert not (float("nan"), float("nan")) <= (float("nan"), float("nan"))
assert not (float("nan"), float("nan")) >= (float("nan"), float("nan"))
assert not (float("nan"), float("nan")) < (float("nan"), float("nan"))
assert not (float("nan"), float("nan")) > (float("nan"), float("nan"))
assert (float("inf"), float("inf")) >= (float("inf"), 1)
assert (float("inf"), float("inf")) <= (float("inf"), float("inf"))
assert (float("inf"), float("inf")) >= (float("inf"), float("inf"))
assert not (float("inf"), float("inf")) < (float("inf"), float("inf"))
assert not (float("inf"), float("inf")) > (float("inf"), float("inf"))