First test

This commit is contained in:
Ian Gulliver
2021-11-15 20:36:02 -10:00
parent 2c063e5382
commit be6b726851
2 changed files with 48 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
package main package vm
import "bytes" import "bytes"
import "encoding/hex" import "encoding/hex"

47
state_test.go Normal file
View File

@@ -0,0 +1,47 @@
package vm
import "encoding/hex"
import "strings"
import "testing"
func TestFirst(t *testing.T) {
asm := [][]string{
[]string{
"0000020000000000010000000000000000000000000000000000000000000001",
"0000000100000000000000000000000000000001000000000000000000000000",
"0000030100000000010000000000000000000000000000000000000000000003",
"000004010000000000000000fffffffffffffffd000000000000000000000000",
},
[]string{
"0000020000000000020000000000000000000000000000000000000000000001",
},
}
functionByteCode := [][]byte{}
for _, fnc := range asm {
fncString := strings.Join(fnc, "")
byteCode, err := hex.DecodeString(fncString)
if err != nil {
t.Fatal(err)
}
functionByteCode = append(functionByteCode, byteCode)
}
state, err := NewState(functionByteCode)
if err != nil {
t.Fatal(err)
}
state.Execute()
if state.Error != nil {
t.Fatal(state)
}
if state.GlobalMemory[0] != 3 {
t.Fatal(state.GlobalMemory[0])
}
}