Generalized tests

This commit is contained in:
Sasha Koshka 2022-08-28 18:29:10 -04:00
parent 21aaaede8e
commit 045bd2ef6d
1 changed files with 27 additions and 31 deletions

View File

@ -2,12 +2,8 @@ package creature
import "testing" import "testing"
func TestPush(test *testing.T) { func runMachineTest(program []int, test *testing.T) (machine *Machine) {
machine := Machine { machine = &Machine { Program: program }
Program: []int {
0x0, 654,
},
}
err := machine.Execute(0) err := machine.Execute(0)
if err != nil { if err != nil {
@ -15,6 +11,14 @@ func TestPush(test *testing.T) {
test.Fail() test.Fail()
} }
return
}
func TestPush(test *testing.T) {
machine := runMachineTest ([]int {
0x0, 654,
}, test)
result := machine.Pop() result := machine.Pop()
test.Log("popped:", result) test.Log("popped:", result)
@ -25,31 +29,23 @@ func TestPush(test *testing.T) {
} }
func TestArithmetic(test *testing.T) { func TestArithmetic(test *testing.T) {
machine := Machine { machine := runMachineTest([]int {
Program: []int { 0x0, 2,
0x0, 2, 0x0, 3,
0x0, 3, 0x4,
0x4,
0x0, 10,
0x0, 10, 0x0, 4,
0x0, 4, 0x5,
0x5,
0x0, 7,
0x0, 7, 0x0, 2,
0x0, 2, 0x6,
0x6,
0x0, 12,
0x0, 12, 0x0, 3,
0x0, 3, 0x7,
0x7, }, test)
},
}
err := machine.Execute(0)
if err != nil {
test.Log("machine exited with error:", err)
test.Fail()
}
addResult := machine.Pop() addResult := machine.Pop()
subResult := machine.Pop() subResult := machine.Pop()