Skip to content

Commit 3c71a96

Browse files
committed
TEST: Add for Array syntactic sugar
1 parent 3c1e75a commit 3c71a96

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ RUN(NAME array_01 LABELS cpython llvm wasm c)
424424
RUN(NAME array_02 LABELS cpython wasm c)
425425
RUN(NAME array_03 LABELS cpython llvm c)
426426
RUN(NAME array_04 LABELS cpython llvm c)
427+
RUN(NAME array_05 LABELS cpython llvm c)
427428
RUN(NAME bindc_01 LABELS cpython llvm c)
428429
RUN(NAME bindc_02 LABELS cpython llvm c)
429430
RUN(NAME bindc_04 LABELS llvm c NOFAST)

integration_tests/array_05.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from lpython import i32, f64, Array
2+
from numpy import empty, int32, float64
3+
4+
5+
def test_1():
6+
y: Array[f64, 3] = empty([3], dtype=float64)
7+
y[0] = 3.14
8+
y[1] = -4.14
9+
y[2] = 100.100
10+
11+
print(y)
12+
assert abs(y[0] - (3.14)) <= 1e-6
13+
assert abs(y[1] - (-4.14)) <= 1e-6
14+
assert abs(y[2] - (100.100)) <= 1e-6
15+
16+
def test_2():
17+
x: Array[i32, 2, 3] = empty([2, 3], dtype=int32)
18+
19+
x[0, 0] = 5
20+
x[0, 1] = -10
21+
x[0, 2] = 15
22+
x[1, 0] = 4
23+
x[1, 1] = -14
24+
x[1, 2] = 100
25+
26+
print(x)
27+
assert x[0, 0] == 5
28+
assert x[0, 1] == -10
29+
assert x[0, 2] == 15
30+
assert x[1, 0] == 4
31+
assert x[1, 1] == -14
32+
assert x[1, 2] == 100
33+
34+
35+
def main0():
36+
test_1()
37+
test_2()
38+
39+
main0()

0 commit comments

Comments
 (0)