Skip to content

Commit 330efef

Browse files
committed
Add test
1 parent fbc65e1 commit 330efef

File tree

4 files changed

+6662
-0
lines changed

4 files changed

+6662
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ RUN(NAME test_dict_08 LABELS cpython llvm c)
374374
RUN(NAME test_dict_09 LABELS cpython llvm c)
375375
RUN(NAME test_dict_10 LABELS cpython llvm) # TODO: Add support of dict with string in C backend
376376
RUN(NAME test_dict_11 LABELS cpython llvm c)
377+
RUN(NAME test_dict_bool LABELS cpython llvm)
377378
RUN(NAME test_for_loop LABELS cpython llvm c)
378379
RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
379380
RUN(NAME modules_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)

integration_tests/test_dict_bool.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from lpython import i32, f64
2+
3+
def test_dict_bool():
4+
d_int: dict[bool, i32] = {}
5+
d_float: dict[bool, f64] = {}
6+
d_str: dict[bool, str] = {}
7+
i: i32
8+
j: f64
9+
s: str = ""
10+
l_str: list[str] = ["a", "b", "c", "d"]
11+
12+
for i in range(10):
13+
d_int[True] = i
14+
assert d_int[True] == i
15+
16+
for i in range(10, 20):
17+
d_int[True] = i
18+
d_int[False] = i + 1
19+
assert d_int[True] == d_int[False] - 1
20+
assert d_int[True] == i
21+
22+
d_int[True] = 0
23+
d_int[False] = d_int[True]
24+
25+
for i in range(10, 99):
26+
d_int[i%2 == 0] = d_int[i%2 == 0] + 1
27+
assert d_int[True] == d_int[False] + 1
28+
assert d_int[True] == 45
29+
30+
j = 0.0
31+
while j < 1.0:
32+
d_float[False] = j + 1.0
33+
d_float[True] = d_float[False] * d_float[False]
34+
assert d_float[True] == (j + 1.0) * (j + 1.0)
35+
assert d_float[False] == j + 1.0
36+
j = j + 0.1
37+
38+
d_str[False] = s
39+
40+
for i in range(len(l_str)):
41+
d_str[True] = d_str[False]
42+
s += l_str[i]
43+
d_str[False] = s
44+
assert d_str[True] + l_str[i] == d_str[False]
45+
assert d_str[False] == s
46+
47+
test_dict_bool()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr_json-test_dict_bool-8307f87",
3+
"cmd": "lpython --show-asr --json {infile} -o {outfile}",
4+
"infile": "tests/../integration_tests/test_dict_bool.py",
5+
"infile_hash": "610f4a35f0d800334e086e1e7237c6a69c24631f7d7e542a7f8a6b04",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": "asr_json-test_dict_bool-8307f87.stdout",
9+
"stdout_hash": "db8f6218db5e192034ccb3920652c74d841251b93f00a9da19e2b695",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
13+
}

0 commit comments

Comments
 (0)