adventofcode/2019/intcode-processor/processor_test.go

35 lines
662 B
Go
Raw Normal View History

package intcodeprocessor
2019-12-04 16:43:01 +00:00
import (
"testing"
)
2019-12-04 20:16:41 +00:00
func TestNewAddProgram(t *testing.T) {
strt := []int{1, 0, 0, 0, 99}
want := []int{2, 0, 0, 0, 99}
p := NewProgram(strt)
p.Run()
if !intSliceEquals(p.GetCode(), want) {
t.Errorf("Program.GetCode() = %q, want %q", p.GetCode(), want)
2019-12-04 16:43:01 +00:00
}
}
2019-12-04 20:16:41 +00:00
func TestNewMultProgram(t *testing.T) {
strt := []int{2, 3, 0, 3, 99}
want := []int{2, 3, 0, 6, 99}
p := NewProgram(strt)
p.Run()
if !intSliceEquals(p.GetCode(), want) {
t.Errorf("Program.GetCode() = %q, want %q", p.GetCode(), want)
}
}
func intSliceEquals(s1, s2 []int) bool {
for k := range s1 {
if s1[k] != s2[k] {
return false
}
}
return true
}