From 884f00d048ea43edff45c1e61533ce4c264c3d1c Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 28 Aug 2022 19:59:00 -0400 Subject: [PATCH] The division test was wrong --- creature.go | 2 +- creature_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/creature.go b/creature.go index 719f25e..a40039c 100644 --- a/creature.go +++ b/creature.go @@ -117,7 +117,7 @@ func (machine *Machine) Execute(offset int) (err error) { // last word on the stack left := machine.Pop() right := machine.Pop() - if left == 0 && right == 0 { + if right == 0 { err = ErrorDivideByZero return } diff --git a/creature_test.go b/creature_test.go index a3cb62d..39bbd57 100644 --- a/creature_test.go +++ b/creature_test.go @@ -34,23 +34,23 @@ func TestArithmetic(test *testing.T) { PUSH, 3, ADD, - PUSH, 10, PUSH, 4, + PUSH, 10, SUB, PUSH, 7, PUSH, 2, MUL, - PUSH, 12, PUSH, 3, + PUSH, 12, DIV, }, test) - addResult := machine.Pop() - subResult := machine.Pop() - mulResult := machine.Pop() divResult := machine.Pop() + mulResult := machine.Pop() + subResult := machine.Pop() + addResult := machine.Pop() test.Log("add:", addResult) test.Log("sub:", subResult)