Skip to content

Commit 3ab1512

Browse files
committed
[ENH] correct mistakes and add tests
1 parent 46858aa commit 3ab1512

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

execution/execution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def mul():
7676
def div():
7777
if len(Stack) < 2:
7878
raise Exception('Stack is too small (< 2), cannot div')
79-
Stack[-2] = Stack[-2] / Stack[-1]
79+
Stack[-2] = int(Stack[-2] / Stack[-1])
8080
pop()
8181

8282
def mod():

tests.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,22 @@ def compare_list(l1, l2, wil=False):
188188
execution_tests = [
189189
([('push', 1)], ([1], {}, {}, {}), 'push'),
190190
([('push', 1), 'dup'], ([1, 1], {}, {}, {}), 'dup'),
191-
([('push', 2), 'dup', 'add'], ([4], {}, {}, {}), 'add'),
192-
([('label', 0)], ([], {}, {0: 1}, {}), 'label 0'),
193191
([('push', 1), ('push', 2), ('copy', 1)], ([1, 2, 1], {}, {}, {}), 'copy'),
194192
([('push', 1), ('push', 2), 'swap'], ([2, 1], {}, {}, {}), 'swap'),
195193
([('push', 10), 'pop'], ([], {}, {}, {}), 'pop'),
194+
([('push', 1), ('push', 2), ('push', 3), ('slide', 2)], ([3], {}, {}, {}), 'slide'),
195+
([('push', 2), 'dup', 'add'], ([4], {}, {}, {}), 'add'),
196196
([('push', 3), 'dup', 'sub'], ([0], {}, {}, {}), 'sub'),
197-
([('push', 1), ('push', 2), ('push', 3), ('slide', 2)], ([3], {}, {}, {}), 'slide')
197+
([('push', 3), 'dup', 'mul'], ([9], {}, {}, {}), 'mul'),
198+
([('push', 5), ('push', 2), 'div'], ([2], {}, {}, {}), 'div'),
199+
([('push', 5), ('push', 2), 'mod'], ([1], {}, {}, {}), 'mod'),
200+
([('push', 'ad1'), ('push', 2), 'store'], ([], {'ad1': 2}, {}, {}), 'store'),
201+
([('push', 'ad1'), ('push', 2), 'store', ('push', 'ad1'), 'retri'], ([2], {'ad1': 2}, {}, {}), 'retrieve'),
202+
([('label', 0)], ([], {}, {0: 1}, {}), 'label 0'),
198203
]
199204
for t in execution_tests:
200205
restore_context()
201206
if perform_test(t):
202207
print('[{}OK{}] {}'.format(bcolors.OKGREEN, bcolors.ENDC, t[2]))
203208
else:
204-
print('[{}KO{}] {}, got: ({} {} {} {}), expected: {}'.format(bcolors.FAIL, bcolors.ENDC, t[2], Stack, Heap, Labels, Routines, t[1]))
209+
print('[{}KO{}] {}, got: ({} {} {} {}), expected: {}'.format(bcolors.FAIL, bcolors.ENDC, t[2], ex.Stack, ex.Heap, ex.Labels, ex.Routines, t[1]))

0 commit comments

Comments
 (0)