summaryrefslogtreecommitdiff
path: root/tests/micropython
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-10-11 18:54:34 +1100
committerDamien George <damien.p.george@gmail.com>2017-10-11 18:54:34 +1100
commita3afa8cfc46913f471d5eb55da4ae22dee92c25f (patch)
tree09296c9dcd31d6e28ae48e46cce9f08de9123f2d /tests/micropython
parent1b7d6a795149588eb44c1b33dd7c34fe6669460a (diff)
py/emitnative: Implement floor-division and modulo for viper emitter.
Diffstat (limited to 'tests/micropython')
-rw-r--r--tests/micropython/viper_binop_divmod.py18
-rw-r--r--tests/micropython/viper_binop_divmod.py.exp28
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/micropython/viper_binop_divmod.py b/tests/micropython/viper_binop_divmod.py
new file mode 100644
index 000000000..822424982
--- /dev/null
+++ b/tests/micropython/viper_binop_divmod.py
@@ -0,0 +1,18 @@
+# test floor-division and modulo operators
+
+@micropython.viper
+def div(x:int, y:int) -> int:
+ return x // y
+
+@micropython.viper
+def mod(x:int, y:int) -> int:
+ return x % y
+
+def dm(x, y):
+ print(div(x, y), mod(x, y))
+
+for x in (-6, 6):
+ for y in range(-7, 8):
+ if y == 0:
+ continue
+ dm(x, y)
diff --git a/tests/micropython/viper_binop_divmod.py.exp b/tests/micropython/viper_binop_divmod.py.exp
new file mode 100644
index 000000000..4fc971d46
--- /dev/null
+++ b/tests/micropython/viper_binop_divmod.py.exp
@@ -0,0 +1,28 @@
+0 -6
+1 0
+1 -1
+1 -2
+2 0
+3 0
+6 0
+-6 0
+-3 0
+-2 0
+-2 2
+-2 4
+-1 0
+-1 1
+-1 -1
+-1 0
+-2 -4
+-2 -2
+-2 0
+-3 0
+-6 0
+6 0
+3 0
+2 0
+1 2
+1 1
+1 0
+0 6