luis 7 years ago
parent
commit
89ae2b2daf
3 changed files with 70 additions and 70 deletions
  1. 11 11
      go/src/flow/flow_test.go
  2. 23 23
      go/src/flow/registry/entry_test.go
  3. 36 36
      go/src/flow/registry/registry_test.go

+ 11 - 11
go/src/flow/flow_test.go

@@ -53,16 +53,16 @@ func TestSerialize(t *testing.T) {
 
 }
 func TestConst(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	f := flow.New()
 
 	c := f.Const(1)
 	res := c.Process()
 	//Expect(t).Eq(res, 1)
-	assert.Eq(res, 1, "It should be one")
+	a.Eq(res, 1, "It should be one")
 }
 func TestOp(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	f := flow.New()
 
 	add := f.Op("vecadd",
@@ -73,10 +73,10 @@ func TestOp(t *testing.T) {
 		[]float32{1, 2, 3},
 	)
 	res, err := f.Run(add)
-	assert.Eq(err, nil)
+	a.Eq(err, nil)
 
 	test := []float32{3, 6, 9}
-	assert.Eq(test, res)
+	a.Eq(test, res)
 }
 
 func TestVariable(t *testing.T) {
@@ -112,22 +112,22 @@ func TestCache(t *testing.T) {
 	}
 }
 func TestDefOp(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	f := flow.New()
 
 	f.DefOp("2", "vecadd", []float32{1, 1, 1}, []float32{2, 2, 2}) // r:3 3 3
-	assert.Eq(f.Err(), nil, "doing DefOp")
+	a.Eq(f.Err(), nil, "doing DefOp")
 
 	f.DefOp("1", "vecadd", []float32{1, 2, 3}, f.Res("2")) // r: 4 5 6
-	assert.Eq(f.Err(), nil, "doing DefOp")
+	a.Eq(f.Err(), nil, "doing DefOp")
 
 	op := f.Op("vecmul", f.Res("1"), []float32{2, 2, 2}) //r:8 10 12
-	assert.Eq(f.Err(), nil, "mul operation")
-	assert.NotEq(op, nil, "operation not nil")
+	a.Eq(f.Err(), nil, "mul operation")
+	a.NotEq(op, nil, "operation not nil")
 
 	desired := []float32{8, 10, 12}
 	res := op.Process()
-	assert.Eq(desired, res, "vector result should match")
+	a.Eq(desired, res, "vector result should match")
 }
 
 func TestHandler(t *testing.T) {

+ 23 - 23
go/src/flow/registry/entry_test.go

@@ -7,57 +7,57 @@ import (
 )
 
 func TestNewEntryInvalid(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := registry.NewEntry(r, "string")
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 }
 func TestNewEntryValid(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := registry.NewEntry(r, func(a int) int { return 0 })
-	assert.Eq(e.Err(), nil, "fetching an entry")
+	a.Eq(e.Err(), nil, "fetching an entry")
 }
 
 func TestDescription(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 
 	e := registry.NewEntry(r, func() int { return 0 })
 	e.Categories("a", "b")
-	assert.Eq(e.Err(), nil, "should not fail setting categories")
-	assert.Eq(len(e.Description.Categories), 2, "should have 2 categories")
+	a.Eq(e.Err(), nil, "should not fail setting categories")
+	a.Eq(len(e.Description.Categories), 2, "should have 2 categories")
 
 	e.Input(0, "input doc")
-	assert.Eq(e.Err(), nil, "should not fail setting input description")
-	assert.Eq(len(e.Description.InputDesc), 1, "should have 1 input description")
+	a.Eq(e.Err(), nil, "should not fail setting input description")
+	a.Eq(len(e.Description.InputDesc), 1, "should have 1 input description")
 
 	e.Output("output desc")
-	assert.Eq(e.Err(), nil, "should not fail setting input description")
-	assert.Eq(e.Description.OutputDesc, "output desc", "output description should be the same")
+	a.Eq(e.Err(), nil, "should not fail setting input description")
+	a.Eq(e.Description.OutputDesc, "output desc", "output description should be the same")
 
 	e.Extra("test", 123)
-	assert.Eq(e.Err(), nil, "should not fail setting extra doc")
-	assert.Eq(e.Description.Extra["test"], 123, "extra text should be as expected")
+	a.Eq(e.Err(), nil, "should not fail setting extra doc")
+	a.Eq(e.Description.Extra["test"], 123, "extra text should be as expected")
 }
 func TestDescriptionError(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := registry.NewEntry(r, "string")
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 	e.Categories("a", "b")
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 	e.Input(0, "input doc")
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 	e.Output("output desc")
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 	e.Extra("test", 123)
-	assert.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
+	a.Eq(e.Err(), registry.ErrNotAFunc, "entry is not a function")
 
 }
 
 func TestEntryBatch(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 
 	b := registry.Batch{
@@ -67,10 +67,10 @@ func TestEntryBatch(t *testing.T) {
 	}.Categories("test").
 		Extra("name", 1)
 
-	assert.Eq(len(b), 3, "should have 3 items")
+	a.Eq(len(b), 3, "should have 3 items")
 	for _, e := range b {
-		assert.Eq(e.Description.Categories[0], "test", "It should be of category test")
-		assert.Eq(e.Description.Extra["name"], 1, "It should contain extra")
+		a.Eq(e.Description.Categories[0], "test", "It should be of category test")
+		a.Eq(e.Description.Extra["name"], 1, "It should contain extra")
 	}
 
 }

+ 36 - 36
go/src/flow/registry/registry_test.go

@@ -7,101 +7,101 @@ import (
 )
 
 func TestRegistry(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 
 	r := registry.New()
 	r.Register("vecadd", dummy1)
 
 	e, err := r.Entry("vecadd")
-	assert.Eq(err, nil, "fetching entry")
+	a.Eq(err, nil, "fetching entry")
 
 	d := e.Description
 
-	assert.Eq(len(d.Inputs), 2, "should have 2 outputs")
-	assert.Eq(d.Output, "[]float32", "output type")
+	a.Eq(len(d.Inputs), 2, "should have 2 outputs")
+	a.Eq(d.Output, "[]float32", "output type")
 
 	t.Log(d)
 
 }
 
 func TestEntry(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e, err := r.Entry("bogus")
 
-	assert.NotEq(err, nil, "should get an error")
-	assert.Eq(e, nil, "entry should be nil")
+	a.NotEq(err, nil, "should get an error")
+	a.Eq(e, nil, "entry should be nil")
 
 }
 
 func TestRegister(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := r.Register("func", func(a, b int) int { return 0 })
-	assert.Eq(e.Err(), nil, "should register a function")
+	a.Eq(e.Err(), nil, "should register a function")
 }
 func TestRegisterDuplicate(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	r.Register("func", func(a, b int) int { return 0 })
 	e := r.Register("func", func(b int) int { return 0 })
 
-	assert.Eq(e.Err(), nil, "should allow duplicate")
+	a.Eq(e.Err(), nil, "should allow duplicate")
 }
 func TestRegisterInvalidOutput(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := r.Register("func", func(a int) {})
-	assert.Eq(e.Err(), registry.ErrOutput, "should give output error")
+	a.Eq(e.Err(), registry.ErrOutput, "should give output error")
 }
 
 func TestRegisterInvalidInput(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := r.Register("func", func() int { return 0 })
-	assert.Eq(e.Err(), nil, "should register a func without params")
+	a.Eq(e.Err(), nil, "should register a func without params")
 }
 
 func TestRegistryGet(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := r.Register("func", func() int { return 0 })
-	assert.Eq(e.Err(), nil, "should register func")
+	a.Eq(e.Err(), nil, "should register func")
 
 	fn, err := r.Get("func")
-	assert.Eq(err, nil, "should fetch a function")
-	assert.NotEq(fn, nil, "fn should not be nil")
+	a.Eq(err, nil, "should fetch a function")
+	a.NotEq(fn, nil, "fn should not be nil")
 }
 
 func TestRegistryGetEmpty(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	fn, err := r.Get("notfoundfunc")
-	assert.Eq(err, registry.ErrNotFound, "should fail fetching a unregistered func")
-	assert.Eq(fn, nil, "should return a <nil> func")
+	a.Eq(err, registry.ErrNotFound, "should fail fetching a unregistered func")
+	a.Eq(fn, nil, "should return a <nil> func")
 }
 func TestRegistryGetConstructor(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 	r := registry.New()
 	e := r.Register("func", func() func() int {
 		return func() int {
 			return 0
 		}
 	})
-	assert.Eq(e.Err(), nil, "should register the constructor func")
+	a.Eq(e.Err(), nil, "should register the constructor func")
 
 	ifn, err := r.Get("func")
-	assert.Eq(err, nil, "get should not error")
+	a.Eq(err, nil, "get should not error")
 
 	fn, ok := ifn.(func() int)
-	assert.Eq(ok, true, "function should be the constructor type")
+	a.Eq(ok, true, "function should be the constructor type")
 
 	ret := fn()
-	assert.Eq(ret, 0, "function should return 0")
+	a.Eq(ret, 0, "function should return 0")
 }
 
 func TestRegistryGetConstructorParam(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 
 	r := registry.New()
 	e := r.Register("func2", func(a, b int) func() int {
@@ -109,29 +109,29 @@ func TestRegistryGetConstructorParam(t *testing.T) {
 			return a + b
 		}
 	})
-	assert.Eq(e.Err(), nil)
+	a.Eq(e.Err(), nil)
 	ifn, err := r.Get("func2", 1, 1)
-	assert.Eq(err, nil, "should not fail passing params to constructor")
-	assert.NotEq(ifn, nil, "should return a function")
+	a.Eq(err, nil, "should not fail passing params to constructor")
+	a.NotEq(ifn, nil, "should return a function")
 
 	fn, ok := ifn.(func() int)
-	assert.Eq(ok, true, "function should match the type")
+	a.Eq(ok, true, "function should match the type")
 
 	ret := fn()
-	assert.Eq(ret, 2, "function should execute")
+	a.Eq(ret, 2, "function should execute")
 
 }
 
 func TestDescriptions(t *testing.T) {
-	assert := assert.A(t)
+	a := assert.A(t)
 
 	r := registry.New()
 	r.Register("vecadd", dummy1)
 	r.Register("vecstr", dummy2)
 
 	d, err := r.Descriptions()
-	assert.Eq(err, nil, "should fetch Descriptions")
-	assert.Eq(len(d), 2, "should contain 2 descriptions")
+	a.Eq(err, nil, "should fetch Descriptions")
+	a.Eq(len(d), 2, "should contain 2 descriptions")
 
 	t.Log(d)