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