Test for grow
This commit is contained in:
@@ -3,17 +3,7 @@ package test
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
import "github.com/firestuff/subcoding/gen"
|
import "github.com/firestuff/subcoding/gen"
|
||||||
import "github.com/firestuff/subcoding/asm"
|
|
||||||
|
|
||||||
func TestRandProgram(t *testing.T) {
|
func TestRandProgram(t *testing.T) {
|
||||||
for i := 0; i < 100; i++ {
|
gen.RandProgram(4, 4, 0)
|
||||||
prog := gen.RandProgram(4, 4, 0)
|
|
||||||
|
|
||||||
src, err := asm.Disassemble(prog)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Log(src)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
57
test/grow_test.go
Normal file
57
test/grow_test.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
import "github.com/firestuff/subcoding/asm"
|
||||||
|
import "github.com/firestuff/subcoding/grow"
|
||||||
|
|
||||||
|
func TestGrow(t *testing.T) {
|
||||||
|
r := bytes.NewReader([]byte(`
|
||||||
|
global_memory_size: 1
|
||||||
|
function_memory_size: 1
|
||||||
|
instruction_limit: 2
|
||||||
|
samples:
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 0
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 0
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 1
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 5
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 2
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 10
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 100
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 500
|
||||||
|
`))
|
||||||
|
|
||||||
|
def, err := grow.NewDefinition(r)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
prog, err := def.Grow()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
src, err := asm.Disassemble(prog)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := `global_memory_size: 1
|
||||||
|
function_memory_size: 1
|
||||||
|
instruction_limit: 2
|
||||||
|
functions:
|
||||||
|
- - [mul, g0, 5]
|
||||||
|
`
|
||||||
|
if src != expected {
|
||||||
|
t.Fatalf("Expected:\n%sActual:\n%s", expected, src)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user