Skip to content

Commit fd4ff4f

Browse files
kabra1110czgdp1807
authored andcommitted
add and update tests
1 parent 97ca7c5 commit fd4ff4f

File tree

7 files changed

+109
-0
lines changed

7 files changed

+109
-0
lines changed

integration_tests/test_dict_14.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from lpython import i32
2+
3+
def test_dict():
4+
d_i32: dict[i32, i32] = {5: 1, 5: 2}
5+
d_str: dict[str, i32] = {'a': 1, 'a': 2}
6+
l_str_1: list[str] = []
7+
l_str_2: list[str] = []
8+
l_i32_1: list[i32] = []
9+
l_i32_2: list[i32] = []
10+
i: i32
11+
s: str
12+
13+
assert len(d_i32) == 1
14+
d_i32.pop(5)
15+
assert len(d_i32) == 0
16+
17+
assert len(d_str) == 1
18+
d_str.pop('a')
19+
assert len(d_str) == 0
20+
21+
d_str = {'a': 2, 'a': 2, 'b': 2, 'c': 3, 'a': 5}
22+
assert len(d_str) == 3
23+
d_str.pop('a')
24+
assert len(d_str) == 2
25+
d_str.pop('b')
26+
assert len(d_str) == 1
27+
28+
d_str['a'] = 20
29+
assert len(d_str) == 2
30+
d_str.pop('c')
31+
assert len(d_str) == 1
32+
33+
l_str_1 = d_str.keys()
34+
for s in l_str_1:
35+
l_str_2.append(s)
36+
assert l_str_2 == ['a']
37+
l_i32_1 = d_str.values()
38+
for i in l_i32_1:
39+
l_i32_2.append(i)
40+
assert l_i32_2 == [20]
41+
42+
d_i32 = {5: 2, 5: 2, 6: 2, 7: 3, 5: 5}
43+
assert len(d_i32) == 3
44+
d_i32.pop(5)
45+
assert len(d_i32) == 2
46+
d_i32.pop(6)
47+
assert len(d_i32) == 1
48+
49+
d_i32[6] = 30
50+
assert len(d_i32) == 2
51+
d_i32.pop(7)
52+
assert len(d_i32) == 1
53+
54+
l_i32_1 = d_i32.keys()
55+
l_i32_2.clear()
56+
for i in l_i32_1:
57+
l_i32_2.append(i)
58+
assert l_i32_2 == [6]
59+
l_i32_1 = d_i32.values()
60+
l_i32_2.clear()
61+
for i in l_i32_1:
62+
l_i32_2.append(i)
63+
assert l_i32_2 == [30]
64+
65+
test_dict()

tests/errors/test_dict15.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from lpython import i32
2+
3+
def test_dict_pop():
4+
d: dict[i32, i32] = {1: 2}
5+
d.pop(1)
6+
d.pop(1)
7+
8+
test_dict_pop()

tests/errors/test_dict16.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from lpython import i32
2+
3+
def test_dict_pop():
4+
d: dict[str, i32] = {'a': 2}
5+
d.pop('a')
6+
d.pop('a')
7+
8+
test_dict_pop()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "runtime-test_dict15-6f3af0d",
3+
"cmd": "lpython {infile}",
4+
"infile": "tests/errors/test_dict15.py",
5+
"infile_hash": "6a0e507b9a9cf659cb433abbdc3435b4c63a6079eadcd7d2c765def1",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "runtime-test_dict15-6f3af0d.stderr",
11+
"stderr_hash": "cb46ef04db0862506d688ebe8830a50afaaead9b0d29b0c007dd149a",
12+
"returncode": 1
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KeyError: The dict does not contain the specified key
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "runtime-test_dict16-c5a958d",
3+
"cmd": "lpython {infile}",
4+
"infile": "tests/errors/test_dict16.py",
5+
"infile_hash": "7b00cfd7f6eac8338897bd99e5d953605f16927ee0f27683146b0182",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "runtime-test_dict16-c5a958d.stderr",
11+
"stderr_hash": "cb46ef04db0862506d688ebe8830a50afaaead9b0d29b0c007dd149a",
12+
"returncode": 1
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
KeyError: The dict does not contain the specified key

0 commit comments

Comments
 (0)