Skip to content

Commit 17d2c96

Browse files
committed
TEST: Add test for array comparison
1 parent 08472bc commit 17d2c96

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ RUN(NAME array_size_02 LABELS cpython llvm c)
368368
RUN(NAME array_01 LABELS cpython llvm wasm c)
369369
RUN(NAME array_02 LABELS cpython wasm c)
370370
RUN(NAME array_03 LABELS cpython llvm c)
371+
RUN(NAME array_04 LABELS cpython llvm c)
371372
RUN(NAME bindc_01 LABELS cpython llvm c)
372373
RUN(NAME bindc_02 LABELS cpython llvm c)
373374
RUN(NAME bindc_04 LABELS llvm c NOFAST)

integration_tests/array_04.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from lpython import i32, Const
2+
from numpy import empty, int32
3+
4+
def main0():
5+
n: Const[i32] = 1
6+
x: i32[n, n] = empty([n, n], dtype=int32)
7+
y: i32[n, n] = empty([n, n], dtype=int32)
8+
9+
x[0, 0] = -10
10+
y[0, 0] = -10
11+
12+
print(x[0, 0], y[0, 0])
13+
assert x == y
14+
15+
y[0, 0] = 10
16+
print(x[0, 0], y[0, 0])
17+
assert x != y
18+
19+
main0()

tests/errors/arrays_02.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from lpython import (i8, i32, dataclass)
2+
from numpy import (empty, int8)
3+
4+
@dataclass
5+
class Foo:
6+
a : i8[4] = empty(4, dtype=int8)
7+
dim : i32 = 4
8+
9+
def trinary_majority(x : Foo, y : Foo, z : Foo) -> Foo:
10+
foo : Foo = Foo()
11+
i : i32
12+
for i in range(foo.dim):
13+
foo.a[i] = (x.a[i] & y.a[i]) | (y.a[i] & z.a[i]) | (z.a[i] & x.a[i])
14+
return foo
15+
16+
17+
t1 : Foo = Foo()
18+
t1.a = empty(4, dtype=int8)
19+
20+
t2 : Foo = Foo()
21+
t2.a = empty(4, dtype=int8)
22+
23+
t3 : Foo = Foo()
24+
t3.a = empty(4, dtype=int8)
25+
26+
r1 : Foo = trinary_majority(t1, t2, t3)
27+
28+
assert r1.a == t1.a

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@ asr = true
650650
filename = "errors/arrays_01.py"
651651
asr = true
652652

653+
[[test]]
654+
filename = "errors/arrays_02.py"
655+
asr = true
656+
653657
[[test]]
654658
filename = "errors/structs_02.py"
655659
asr = true

0 commit comments

Comments
 (0)