Skip to content

Commit 6bf590f

Browse files
ubaidskcertik
authored andcommitted
TEST: Add tests for unary op for unsigned ints
1 parent 57bbbd9 commit 6bf590f

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ RUN(NAME test_unary_op_01 LABELS cpython llvm c) # unary minus
558558
RUN(NAME test_unary_op_02 LABELS cpython llvm c) # unary plus
559559
RUN(NAME test_unary_op_03 LABELS cpython llvm c wasm) # unary bitinvert
560560
RUN(NAME test_unary_op_04 LABELS cpython llvm c) # unary bitinvert
561+
RUN(NAME test_unary_op_05 LABELS cpython llvm c) # unsigned unary minus, plus
562+
RUN(NAME test_unary_op_06 LABELS cpython llvm c) # unsigned unary bitnot
561563
RUN(NAME test_bool_binop LABELS cpython llvm c)
562564
RUN(NAME test_issue_518 LABELS cpython llvm c NOFAST)
563565
RUN(NAME structs_01 LABELS cpython llvm c)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from lpython import u16, u32, u64
2+
3+
def f():
4+
5+
i: u16
6+
i = u16(67)
7+
print(-i, +i, -(-i))
8+
assert -i == u16(65469)
9+
assert +i == u16(67)
10+
assert -(-i) == u16(67)
11+
12+
j: u32
13+
j = u32(25)
14+
print(-j, +j, -(-j))
15+
assert -j == u32(4294967271)
16+
assert +j == u32(25)
17+
assert -(-j) == u32(25)
18+
19+
k: u64
20+
k = u64(100000000000123)
21+
print(-k, +k, -(-k))
22+
# TODO: We are unable to store the following u64 in AST/R
23+
# assert -k == u64(18446644073709551493)
24+
assert +k == u64(100000000000123)
25+
assert -(-k) == u64(100000000000123)
26+
27+
f()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from lpython import i32, i64, u16, u64, f32, f64
2+
3+
def f():
4+
5+
i: i32
6+
j: i64
7+
i = -67
8+
j = i64(0)
9+
10+
print(i, j)
11+
print(not i, not j)
12+
assert (not i) == False
13+
assert (not j) == True
14+
15+
k: u16
16+
l: u64
17+
k = u16(0)
18+
l = u64(55)
19+
20+
print(k, l)
21+
print(not k, not l)
22+
assert (not k) == True
23+
assert (not l) == False
24+
25+
m: f32
26+
n: f64
27+
m = f32(0.0)
28+
n = -3.14
29+
30+
print(m, n)
31+
print(not m, not n)
32+
assert (not m) == True
33+
assert (not n) == False
34+
35+
f()

0 commit comments

Comments
 (0)