Skip to content

Commit 3a9424e

Browse files
committed
Tests: Add tests
1 parent c39f350 commit 3a9424e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ RUN(NAME test_dict_nested1 LABELS cpython llvm)
583583
RUN(NAME test_set_len LABELS cpython llvm)
584584
RUN(NAME test_set_add LABELS cpython llvm)
585585
RUN(NAME test_set_remove LABELS cpython llvm)
586+
RUN(NAME test_set_discard LABELS cpython llvm)
586587
RUN(NAME test_global_set LABELS cpython llvm)
587588
RUN(NAME test_for_loop LABELS cpython llvm c)
588589
RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from lpython import i32
2+
3+
def test_set_discard():
4+
s1: set[i32]
5+
s2: set[tuple[i32, tuple[i32, i32], str]]
6+
s3: set[str]
7+
st1: str
8+
i: i32
9+
j: i32
10+
k: i32
11+
12+
for k in range(2):
13+
s1 = {0}
14+
s2 = {(0, (1, 2), "a")}
15+
for i in range(20):
16+
j = i % 10
17+
s1.add(j)
18+
s2.add((j, (j + 1, j + 2), "a"))
19+
20+
for i in range(10):
21+
s1.discard(i)
22+
s2.discard((i, (i + 1, i + 2), "a"))
23+
assert len(s1) == 10 - 1 - i
24+
assert len(s1) == len(s2)
25+
26+
st1 = "a"
27+
s3 = {st1}
28+
for i in range(20):
29+
s3.add(st1)
30+
if i < 10:
31+
if i > 0:
32+
st1 += "a"
33+
34+
st1 = "a"
35+
for i in range(10):
36+
s3.discard(st1)
37+
assert len(s3) == 10 - 1 - i
38+
if i < 10:
39+
st1 += "a"
40+
41+
for i in range(20):
42+
s1.add(i)
43+
if i % 2 == 0:
44+
s1.discard(i)
45+
assert len(s1) == (i + 1) // 2
46+
47+
48+
test_set_discard()

0 commit comments

Comments
 (0)