-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_list_03.py
64 lines (50 loc) · 1.2 KB
/
test_list_03.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
from lpython import i32, InOut
def test_list_01(n: i32) -> i32:
a: list[i32] = []
i: i32
for i in range(n):
a.append(i)
sum: i32 = 0
for i in range(n):
sum += a[i]
return sum
def test_list_insert_02(x: InOut[list[i32]], n: i32) -> list[i32]:
i: i32
imod: i32
for i in range(n):
imod = i % 3
if imod == 0:
x.insert(0, i + n)
elif imod == 1:
x.insert(len(x), i + n + 1)
elif imod == 2:
x.insert(len(x)//2, i + n + 2)
return x
def test_list_02(n: i32) -> i32:
x: list[i32] = [50, 1]
acc: i32 = 0
i: i32
x = test_list_insert_02(x, n)
for i in range(n):
acc += x[i]
return acc
def test_list_02_string():
x: list[str] = []
y: list[str] = []
string: str
i: i32
for i in range(50):
string = "xd_" + str(i + i % 3)
y.append(string)
imod: i32
for i in range(50):
imod = i % 3
string = "xd_" + str(i + imod)
x.insert(len(x), string)
for i in range(50):
assert x[i] == y[i]
def verify():
assert test_list_01(11) == 55
assert test_list_02(50) == 3628
test_list_02_string()
verify()