|
@@ -3,6 +3,8 @@ package flow_test
|
|
|
import (
|
|
|
"bytes"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
+ "log"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
@@ -17,6 +19,67 @@ import (
|
|
|
func init() {
|
|
|
assert.Quiet = true
|
|
|
}
|
|
|
+func TestError(t *testing.T) {
|
|
|
+ a := assert.A(t)
|
|
|
+
|
|
|
+ f := flow.New()
|
|
|
+ err := errors.New("test")
|
|
|
+ f.Err(err)
|
|
|
+ a.Eq(f.Err(), err, "error should be the same")
|
|
|
+}
|
|
|
+func TestDefOp(t *testing.T) {
|
|
|
+ a := assert.A(t)
|
|
|
+ f := flow.New()
|
|
|
+
|
|
|
+ f.DefOp("2", "vecadd", []float32{1, 1, 1}, []float32{2, 2, 2}) // r:3 3 3
|
|
|
+ a.Eq(f.Err(), nil, "doing DefOp")
|
|
|
+
|
|
|
+ f.DefOp("1", "vecadd", []float32{1, 2, 3}, f.Res("2")) // r: 4 5 6
|
|
|
+ a.Eq(f.Err(), nil, "doing DefOp")
|
|
|
+
|
|
|
+ op := f.Op("vecmul", f.Res("1"), []float32{2, 2, 2}) //r:8 10 12
|
|
|
+ a.Eq(f.Err(), nil, "mul operation")
|
|
|
+ a.NotEq(op, nil, "operation not nil")
|
|
|
+
|
|
|
+ desired := []float32{8, 10, 12}
|
|
|
+ res := op.Process()
|
|
|
+ a.Eq(desired, res, "vector result should match")
|
|
|
+
|
|
|
+ op = f.DefOp("123", "none")
|
|
|
+ op.Process()
|
|
|
+ a.NotEq(f.Err(), nil, "Error should not be nil")
|
|
|
+}
|
|
|
+
|
|
|
+func TestIDGen(t *testing.T) {
|
|
|
+ a := assert.A(t)
|
|
|
+ idTable := []string{"2", "1", "1"}
|
|
|
+
|
|
|
+ f := flow.New()
|
|
|
+ f.SetIDGen(func() string {
|
|
|
+ log.Println("Requesting ID", len(idTable))
|
|
|
+ if len(idTable) == 0 {
|
|
|
+ return "0"
|
|
|
+ }
|
|
|
+ newID := idTable[len(idTable)-1]
|
|
|
+ t.Log("Returning ID", newID)
|
|
|
+ idTable = idTable[:len(idTable)-1]
|
|
|
+ return newID
|
|
|
+ })
|
|
|
+
|
|
|
+ o := f.Op("vecadd", f.In(0), f.In(1))
|
|
|
+ a.Eq(f.Err(), nil, "Should not nil")
|
|
|
+ a.Eq(o.ID(), "1", "id should be 1")
|
|
|
+
|
|
|
+ o = f.Op("vecadd", f.In(0), f.In(1))
|
|
|
+ a.Eq(f.Err(), nil, "Should not nil")
|
|
|
+ a.Eq(o.ID(), "2", "id should be 2")
|
|
|
+
|
|
|
+ c := f.Const(1)
|
|
|
+ f.Const(1)
|
|
|
+ o = f.Op("vecadd", f.In(0), c)
|
|
|
+ a.NotEq(f.Err(), nil, "Should be nil,id generation exausted")
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
func TestSerialize(t *testing.T) {
|
|
|
// Does not text yet
|
|
@@ -112,24 +175,6 @@ func TestCache(t *testing.T) {
|
|
|
assert.Eq(t, res, 4)
|
|
|
}
|
|
|
}
|
|
|
-func TestDefOp(t *testing.T) {
|
|
|
- a := assert.A(t)
|
|
|
- f := flow.New()
|
|
|
-
|
|
|
- f.DefOp("2", "vecadd", []float32{1, 1, 1}, []float32{2, 2, 2}) // r:3 3 3
|
|
|
- a.Eq(f.Err(), nil, "doing DefOp")
|
|
|
-
|
|
|
- f.DefOp("1", "vecadd", []float32{1, 2, 3}, f.Res("2")) // r: 4 5 6
|
|
|
- a.Eq(f.Err(), nil, "doing DefOp")
|
|
|
-
|
|
|
- op := f.Op("vecmul", f.Res("1"), []float32{2, 2, 2}) //r:8 10 12
|
|
|
- a.Eq(f.Err(), nil, "mul operation")
|
|
|
- a.NotEq(op, nil, "operation not nil")
|
|
|
-
|
|
|
- desired := []float32{8, 10, 12}
|
|
|
- res := op.Process()
|
|
|
- a.Eq(desired, res, "vector result should match")
|
|
|
-}
|
|
|
|
|
|
func TestHandler(t *testing.T) {
|
|
|
f, op := prepareComplex()
|