Arithmetic

This commit is contained in:
Chuck Smith
2024-01-26 12:13:23 -05:00
parent e34991c081
commit b4cc771baa
6 changed files with 111 additions and 14 deletions

View File

@@ -33,7 +33,7 @@ func runVmTests(t *testing.T, tests []vmTestCase) {
t.Fatalf("vm error: %s", err)
}
stackElem := vm.StackTop()
stackElem := vm.LastPoppedStackElem()
testExpectedObject(t, tt.expected, stackElem)
}
@@ -75,6 +75,14 @@ func TestIntegerArithmetic(t *testing.T) {
{"1", 1},
{"2", 2},
{"1 + 2", 3},
{"1 * 2", 2},
{"4 / 2", 2},
{"50 / 2 * 2 + 10 - 5", 55},
{"5 + 5 + 5 + 5 - 10", 10},
{"2 * 2 * 2 * 2 * 2", 32},
{"5 * 2 + 10", 20},
{"5 + 2 * 10", 25},
{"5 * (2 + 10)", 60},
}
runVmTests(t, tests)