-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_list_pop.py
96 lines (79 loc) · 2.05 KB
/
test_list_pop.py
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
96
from lpython import i32, f64
def test_list_pop():
l1: list[i32]
l2: list[tuple[i32, f64]]
l3: list[list[str]]
i: i32
j: i32
total: i32
x: tuple[i32, f64]
l1 = [1, 2, 3]
assert l1.pop() == 3
assert l1 == [1, 2]
l1 = []
total = 10
for i in range(total):
l1.append(i)
if i % 2 == 1:
assert l1.pop() == i
for i in range(total // 2):
assert l1[i] == 2 * i
l2 = [(1, 2.0)]
x = l2.pop()
assert x == (1, 2.0)
assert len(l2) == 0
l2.append((2, 3.0))
assert x == (1, 2.0)
l3 = []
for i in range(total):
l3.insert(0, ["a"])
for j in range(len(l3)):
l3[j] += ["a"]
while len(l3) > 0:
total = len(l3)
assert len(l3.pop()) == total + 1
assert len(l3) == 0
l1 = [0, 1, 2, 3, 4]
assert l1.pop(3) == 3
assert l1.pop(0) == 0
assert l1.pop(len(l1) - 1) == 4
assert l1 == [1, 2]
total = 10
l1 = []
for i in range(total):
l1.append(i)
j = 0
for i in range(total):
assert l1.pop(j - i) == i
j += 1
assert len(l1) == 0
total = 10
l2 = []
for i in range(total):
l2.append((i, f64(i * i)))
j = 0
for i in range(total):
assert l2.pop(j - i) == (i, f64(i * i))
j += 1
assert len(l2) == 0
# list.pop on list constant
print([1, 2, 3, 4, 5].pop())
assert [1, 2, 3, 4, 5].pop() == 5
print([1, 2, 3, 4, 5].pop(3))
assert [1, 2, 3, 4, 5].pop(3) == 4
index: i32 = 1
print([1, 2, 3, 4, 5].pop(index))
assert [1, 2, 3, 4, 5].pop(index) == 2
element_1: i32 = [1, 2, 3, 4, 5].pop()
print(element_1)
assert element_1 == 5
element_2: i32 = [1, 2, 3, 4, 5].pop(2)
print(element_2)
assert element_2 == 3
a: i32 = 5
b: i32 = 3
print([(1, 2), (3, 4), (5, 6)].pop(a//b))
assert [(1, 2), (3, 4), (5, 6)].pop(a//b) == (3, 4)
print([["a", "b"], ["c", "d"], ["e", "f"]].pop())
assert [["a", "b"], ["c", "d"], ["e", "f"]].pop() == ["e", "f"]
test_list_pop()