Skip to content

Commit 324c656

Browse files
Add list.count tests
1 parent c26a3df commit 324c656

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

integration_tests/test_list_count.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from lpython import i32
2+
3+
def test_list_count():
4+
i: i32
5+
x: list[i32] = []
6+
7+
for i in range(-5, 0):
8+
assert x.count(i) == 0
9+
x.append(i)
10+
assert x.count(i) == 1
11+
x.append(i)
12+
assert x.count(i) == 2
13+
x.remove(i)
14+
assert x.count(i) == 1
15+
16+
assert x == [-5, -4, -3, -2, -1]
17+
18+
for i in range(0, 5):
19+
assert x.count(i) == 0
20+
x.append(i)
21+
assert x.count(i) == 1
22+
23+
assert x == [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
24+
25+
while len(x)>0:
26+
i = x[-1]
27+
x.remove(i)
28+
assert x.count(i) == 0
29+
30+
assert len(x) == 0
31+
assert x.count(0) == 0
32+
33+
test_list_count()

tests/errors/test_list_count.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from lpython import i32
2+
3+
def test_list_count_error():
4+
a: list[i32]
5+
a = [1, 2, 3]
6+
a.count(1.0)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-test_list_count-4b42498",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/test_list_count.py",
5+
"infile_hash": "01975bd7c4bba02fd811de536b218167da99b532fa955b7bf8339779",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-test_list_count-4b42498.stderr",
11+
"stderr_hash": "f26efcc623b68ca43ef871eb01c8e3cbd1ae464baaa491c6e4969696",
12+
"returncode": 2
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semantic error: Type mismatch in 'count', the types must be compatible
2+
--> tests/errors/test_list_count.py:6:13
3+
|
4+
6 | a.count(1.0)
5+
| ^^^ type mismatch (found: 'f64', expected: 'i32')

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ asr = true
692692
filename = "errors/test_list4.py"
693693
asr = true
694694

695+
[[test]]
696+
filename = "errors/test_list_count.py"
697+
asr = true
698+
695699
[[test]]
696700
filename = "errors/test_set1.py"
697701
asr = true

0 commit comments

Comments
 (0)