Added simple test case for arithmetic
This commit is contained in:
parent
a2b64fcc19
commit
dabd2df07c
56
creature_test.go
Normal file
56
creature_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package creature
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
machine.Execute(0)
|
||||||
|
addResult := machine.Pop()
|
||||||
|
subResult := machine.Pop()
|
||||||
|
mulResult := machine.Pop()
|
||||||
|
divResult := machine.Pop()
|
||||||
|
|
||||||
|
test.Log("add:", addResult)
|
||||||
|
test.Log("sub:", subResult)
|
||||||
|
test.Log("mul:", mulResult)
|
||||||
|
test.Log("div:", divResult)
|
||||||
|
|
||||||
|
if addResult != 5 {
|
||||||
|
test.Log("add result should be", 5)
|
||||||
|
test.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
if subResult != 6 {
|
||||||
|
test.Log("sub result should be", 6)
|
||||||
|
test.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
if mulResult != 14 {
|
||||||
|
test.Log("mul result should be", 14)
|
||||||
|
test.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
if divResult != 4 {
|
||||||
|
test.Log("div result should be", 4)
|
||||||
|
test.Fail()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user