The division test was wrong

This commit is contained in:
Sasha Koshka 2022-08-28 19:59:00 -04:00
parent 287d23fe36
commit 884f00d048
2 changed files with 6 additions and 6 deletions

View File

@ -117,7 +117,7 @@ func (machine *Machine) Execute(offset int) (err error) {
// last word on the stack // last word on the stack
left := machine.Pop() left := machine.Pop()
right := machine.Pop() right := machine.Pop()
if left == 0 && right == 0 { if right == 0 {
err = ErrorDivideByZero err = ErrorDivideByZero
return return
} }

View File

@ -34,23 +34,23 @@ func TestArithmetic(test *testing.T) {
PUSH, 3, PUSH, 3,
ADD, ADD,
PUSH, 10,
PUSH, 4, PUSH, 4,
PUSH, 10,
SUB, SUB,
PUSH, 7, PUSH, 7,
PUSH, 2, PUSH, 2,
MUL, MUL,
PUSH, 12,
PUSH, 3, PUSH, 3,
PUSH, 12,
DIV, DIV,
}, test) }, test)
addResult := machine.Pop()
subResult := machine.Pop()
mulResult := machine.Pop()
divResult := machine.Pop() divResult := machine.Pop()
mulResult := machine.Pop()
subResult := machine.Pop()
addResult := machine.Pop()
test.Log("add:", addResult) test.Log("add:", addResult)
test.Log("sub:", subResult) test.Log("sub:", subResult)