forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_for_fix.py
More file actions
103 lines (83 loc) · 1.76 KB
/
Copy pathtest_for_fix.py
File metadata and controls
103 lines (83 loc) · 1.76 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
96
97
98
99
100
101
102
103
from lpython import i32, str
def test_list_iter():
lst: list[i32] = [1, 2, 3, 4, 5]
total: i32 = 0
x: i32
for x in lst:
total += x
assert total == 15
print("list iteration ok")
def test_string_iter():
s: str = "hello"
chars: list[str] = []
ch: str
for ch in s:
chars.append(ch)
assert chars == ["h", "e", "l", "l", "o"]
print("string iteration ok")
def test_range_iter():
sum1: i32 = 0
i: i32
for i in range(5):
sum1 += i
assert sum1 == 10
print("range iteration ok")
def test_nested():
mat: list[list[i32]] = [[1, 2], [3, 4]]
total: i32 = 0
row: list[i32]
elem: i32
for row in mat:
for elem in row:
total += elem
assert total == 10
print("nested iteration ok")
def test_empty():
lst2: list[i32] = []
count: i32 = 0
_: i32
for _ in lst2:
count += 1
assert count == 0
print("empty iteration ok")
def test_single():
lst3: list[i32] = [42]
val: i32 = 0
x: i32
for x in lst3:
val = x
assert val == 42
print("single iteration ok")
def test_step_range():
sum2: i32 = 0
i: i32
for i in range(0, 10, 2):
sum2 += i
assert sum2 == 20
print("step range ok")
def test_negative_step():
sum3: i32 = 0
i: i32
for i in range(10, 0, -2):
sum3 += i
assert sum3 == 30
print("negative step range ok")
def test_while_loop():
i: i32 = 0
total: i32 = 0
while i < 5:
total += i
i += 1
assert total == 10
print("while loop ok")
# Main
test_list_iter()
test_string_iter()
test_range_iter()
test_nested()
test_empty()
test_single()
test_step_range()
test_negative_step()
test_while_loop()
print("All tests passed")