Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ func (d Discard) Execute(executor *Executor) error {
type Addition struct{}

func (a Addition) Execute(executor *Executor) error {
lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

rhs, errRhs := executor.Pop()
if errRhs != nil {
return errRhs
}

lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

executor.Push(lhs + rhs)

return nil
Expand All @@ -81,16 +81,16 @@ func (a Addition) Execute(executor *Executor) error {
type Subtraction struct{}

func (s Subtraction) Execute(executor *Executor) error {
lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

rhs, errRhs := executor.Pop()
if errRhs != nil {
return errRhs
}

lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

executor.Push(lhs - rhs)

return nil
Expand All @@ -99,16 +99,16 @@ func (s Subtraction) Execute(executor *Executor) error {
type Multiplication struct{}

func (m Multiplication) Execute(executor *Executor) error {
lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

rhs, errRhs := executor.Pop()
if errRhs != nil {
return errRhs
}

lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

executor.Push(lhs * rhs)

return nil
Expand All @@ -117,16 +117,16 @@ func (m Multiplication) Execute(executor *Executor) error {
type Division struct{}

func (d Division) Execute(executor *Executor) error {
lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

rhs, errRhs := executor.Pop()
if errRhs != nil {
return errRhs
}

lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

executor.Push(lhs / rhs)

return nil
Expand All @@ -135,16 +135,16 @@ func (d Division) Execute(executor *Executor) error {
type Modulo struct{}

func (m Modulo) Execute(executor *Executor) error {
lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

rhs, errRhs := executor.Pop()
if errRhs != nil {
return errRhs
}

lhs, errLhs := executor.Pop()
if errLhs != nil {
return errLhs
}

executor.Push(lhs % rhs)

return nil
Expand Down
7 changes: 4 additions & 3 deletions instructions_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package whitespace_go

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func newExecutor() *Executor {
Expand Down Expand Up @@ -63,7 +64,7 @@ func TestAddition(t *testing.T) {

func TestSubtraction(t *testing.T) {
executor := newExecutor()
executor.stack = []int{1, 2}
executor.stack = []int{2, 1}

subtraction := Subtraction{}
subtraction.Execute(executor)
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestDivision(t *testing.T) {

func TestModulo(t *testing.T) {
executor := newExecutor()
executor.stack = []int{3, 5}
executor.stack = []int{5, 3}

modulo := Modulo{}
modulo.Execute(executor)
Expand Down