tests: Add tests for viper binary operations.
This commit is contained in:
parent
3112cde900
commit
44c96b2314
36
tests/micropython/viper_binop_arith.py
Normal file
36
tests/micropython/viper_binop_arith.py
Normal file
@ -0,0 +1,36 @@
|
||||
# test arithmetic operators
|
||||
|
||||
@micropython.viper
|
||||
def add(x:int, y:int):
|
||||
print(x + y)
|
||||
print(y + x)
|
||||
add(1, 2)
|
||||
add(42, 3)
|
||||
add(-1, 2)
|
||||
add(-42, -3)
|
||||
|
||||
@micropython.viper
|
||||
def sub(x:int, y:int):
|
||||
print(x - y)
|
||||
print(y - x)
|
||||
sub(1, 2)
|
||||
sub(42, 3)
|
||||
sub(-1, 2)
|
||||
sub(-42, -3)
|
||||
|
||||
@micropython.viper
|
||||
def shl(x:int, y:int):
|
||||
print(x << y)
|
||||
shl(1, 0)
|
||||
shl(1, 3)
|
||||
shl(1, 30)
|
||||
shl(42, 10)
|
||||
shl(-42, 10)
|
||||
|
||||
@micropython.viper
|
||||
def shr(x:int, y:int):
|
||||
print(x >> y)
|
||||
shr(1, 0)
|
||||
shr(1, 3)
|
||||
shr(42, 2)
|
||||
shr(-42, 2)
|
25
tests/micropython/viper_binop_arith.py.exp
Normal file
25
tests/micropython/viper_binop_arith.py.exp
Normal file
@ -0,0 +1,25 @@
|
||||
3
|
||||
3
|
||||
45
|
||||
45
|
||||
1
|
||||
1
|
||||
-45
|
||||
-45
|
||||
-1
|
||||
1
|
||||
39
|
||||
-39
|
||||
-3
|
||||
3
|
||||
-39
|
||||
39
|
||||
1
|
||||
8
|
||||
1073741824
|
||||
43008
|
||||
-43008
|
||||
1
|
||||
0
|
||||
10
|
||||
-11
|
21
tests/micropython/viper_binop_comp.py
Normal file
21
tests/micropython/viper_binop_comp.py
Normal file
@ -0,0 +1,21 @@
|
||||
# test comparison operators
|
||||
@micropython.viper
|
||||
def f(x:int, y:int):
|
||||
if x < y:
|
||||
print(x, "<", y)
|
||||
if x > y:
|
||||
print(x, ">", y)
|
||||
if x == y:
|
||||
print(x, "==", y)
|
||||
if x <= y:
|
||||
print(x, "<=", y)
|
||||
if x >= y:
|
||||
print(x, ">=", y)
|
||||
if x != y:
|
||||
print(x, "!=", y)
|
||||
|
||||
f(1, 1)
|
||||
f(2, 1)
|
||||
f(1, 2)
|
||||
f(2, -1)
|
||||
f(-2, 1)
|
15
tests/micropython/viper_binop_comp.py.exp
Normal file
15
tests/micropython/viper_binop_comp.py.exp
Normal file
@ -0,0 +1,15 @@
|
||||
1 == 1
|
||||
1 <= 1
|
||||
1 >= 1
|
||||
2 > 1
|
||||
2 >= 1
|
||||
2 != 1
|
||||
1 < 2
|
||||
1 <= 2
|
||||
1 != 2
|
||||
2 > -1
|
||||
2 >= -1
|
||||
2 != -1
|
||||
-2 < 1
|
||||
-2 <= 1
|
||||
-2 != 1
|
Loading…
Reference in New Issue
Block a user