improve unit testing cases

This commit is contained in:
John
2020-03-20 08:49:40 +08:00
parent 07e65c14a9
commit f18e6f078c
15 changed files with 294 additions and 256 deletions

View File

@ -18,81 +18,95 @@ import (
)
func Test_IntArray_Unique(t *testing.T) {
expect := []int{1, 2, 3, 4, 5, 6}
array := garray.NewIntArray()
array.Append(1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6)
array.Unique()
t.Assert(array.Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []int{1, 2, 3, 4, 5, 6}
array := garray.NewIntArray()
array.Append(1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6)
array.Unique()
t.Assert(array.Slice(), expect)
})
}
func Test_SortedIntArray1(t *testing.T) {
expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
array := garray.NewSortedIntArray()
for i := 10; i > -1; i-- {
array.Add(i)
}
t.Assert(array.Slice(), expect)
t.Assert(array.Add().Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
array := garray.NewSortedIntArray()
for i := 10; i > -1; i-- {
array.Add(i)
}
t.Assert(array.Slice(), expect)
t.Assert(array.Add().Slice(), expect)
})
}
func Test_SortedIntArray2(t *testing.T) {
expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
array := garray.NewSortedIntArray()
for i := 0; i <= 10; i++ {
array.Add(i)
}
t.Assert(array.Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
array := garray.NewSortedIntArray()
for i := 0; i <= 10; i++ {
array.Add(i)
}
t.Assert(array.Slice(), expect)
})
}
func Test_SortedStrArray1(t *testing.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array1 := garray.NewSortedStrArray()
array2 := garray.NewSortedStrArray(true)
for i := 10; i > -1; i-- {
array1.Add(gconv.String(i))
array2.Add(gconv.String(i))
}
t.Assert(array1.Slice(), expect)
t.Assert(array2.Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array1 := garray.NewSortedStrArray()
array2 := garray.NewSortedStrArray(true)
for i := 10; i > -1; i-- {
array1.Add(gconv.String(i))
array2.Add(gconv.String(i))
}
t.Assert(array1.Slice(), expect)
t.Assert(array2.Slice(), expect)
})
}
func Test_SortedStrArray2(t *testing.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array := garray.NewSortedStrArray()
for i := 0; i <= 10; i++ {
array.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
array.Add()
t.Assert(array.Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array := garray.NewSortedStrArray()
for i := 0; i <= 10; i++ {
array.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
array.Add()
t.Assert(array.Slice(), expect)
})
}
func Test_SortedArray1(t *testing.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array := garray.NewSortedArray(func(v1, v2 interface{}) int {
return strings.Compare(gconv.String(v1), gconv.String(v2))
gtest.C(t, func(t *gtest.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
array := garray.NewSortedArray(func(v1, v2 interface{}) int {
return strings.Compare(gconv.String(v1), gconv.String(v2))
})
for i := 10; i > -1; i-- {
array.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
})
for i := 10; i > -1; i-- {
array.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
}
func Test_SortedArray2(t *testing.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
func1 := func(v1, v2 interface{}) int {
return strings.Compare(gconv.String(v1), gconv.String(v2))
}
array := garray.NewSortedArray(func1)
array2 := garray.NewSortedArray(func1, true)
for i := 0; i <= 10; i++ {
array.Add(gconv.String(i))
array2.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
t.Assert(array.Add().Slice(), expect)
t.Assert(array2.Slice(), expect)
gtest.C(t, func(t *gtest.T) {
expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"}
func1 := func(v1, v2 interface{}) int {
return strings.Compare(gconv.String(v1), gconv.String(v2))
}
array := garray.NewSortedArray(func1)
array2 := garray.NewSortedArray(func1, true)
for i := 0; i <= 10; i++ {
array.Add(gconv.String(i))
array2.Add(gconv.String(i))
}
t.Assert(array.Slice(), expect)
t.Assert(array.Add().Slice(), expect)
t.Assert(array2.Slice(), expect)
})
}
func TestNewFromCopy(t *testing.T) {

View File

@ -679,31 +679,31 @@ func TestSortedArray_RemoveValue(t *testing.T) {
}
func TestSortedArray_UnmarshalValue(t *testing.T) {
type T struct {
type V struct {
Name string
Array *garray.SortedArray
}
// JSON
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": []byte(`[2,3,1]`),
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.Slice{1, 2, 3})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
})
// Map
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": g.Slice{2, 3, 1},
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.Slice{1, 2, 3})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
})
}

View File

@ -560,31 +560,31 @@ func TestSortedIntArray_RemoveValue(t *testing.T) {
}
func TestSortedIntArray_UnmarshalValue(t *testing.T) {
type T struct {
type V struct {
Name string
Array *garray.SortedIntArray
}
// JSON
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": []byte(`[2,3,1]`),
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.Slice{1, 2, 3})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
})
// Map
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": g.Slice{2, 3, 1},
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.Slice{1, 2, 3})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
})
}

View File

@ -569,31 +569,31 @@ func TestSortedStrArray_RemoveValue(t *testing.T) {
}
func TestSortedStrArray_UnmarshalValue(t *testing.T) {
type T struct {
type V struct {
Name string
Array *garray.SortedStrArray
}
// JSON
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": []byte(`["1","3","2"]`),
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
})
// Map
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(g.Map{
"name": "john",
"array": g.SliceStr{"1", "3", "2"},
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"})
t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
})
}

View File

@ -52,75 +52,86 @@ func Test_Map_Basic(t *testing.T) {
})
}
func Test_Map_Set_Fun(t *testing.T) {
m := gmap.New()
m.GetOrSetFunc("fun", getValue)
m.GetOrSetFuncLock("funlock", getValue)
t.Assert(m.Get("funlock"), 3)
t.Assert(m.Get("fun"), 3)
m.GetOrSetFunc("fun", getValue)
t.Assert(m.SetIfNotExistFunc("fun", getValue), false)
t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false)
gtest.C(t, func(t *gtest.T) {
m := gmap.New()
m.GetOrSetFunc("fun", getValue)
m.GetOrSetFuncLock("funlock", getValue)
t.Assert(m.Get("funlock"), 3)
t.Assert(m.Get("fun"), 3)
m.GetOrSetFunc("fun", getValue)
t.Assert(m.SetIfNotExistFunc("fun", getValue), false)
t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false)
})
}
func Test_Map_Batch(t *testing.T) {
m := gmap.New()
m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.Removes([]interface{}{"key1", 1})
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
gtest.C(t, func(t *gtest.T) {
m := gmap.New()
m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.Removes([]interface{}{"key1", 1})
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
})
}
func Test_Map_Iterator(t *testing.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"}
gtest.C(t, func(t *gtest.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"}
m := gmap.NewFrom(expect)
m.Iterator(func(k interface{}, v interface{}) bool {
t.Assert(expect[k], v)
return true
m := gmap.NewFrom(expect)
m.Iterator(func(k interface{}, v interface{}) bool {
t.Assert(expect[k], v)
return true
})
// 断言返回值对遍历控制
i := 0
j := 0
m.Iterator(func(k interface{}, v interface{}) bool {
i++
return true
})
m.Iterator(func(k interface{}, v interface{}) bool {
j++
return false
})
t.Assert(i, 2)
t.Assert(j, 1)
})
// 断言返回值对遍历控制
i := 0
j := 0
m.Iterator(func(k interface{}, v interface{}) bool {
i++
return true
})
m.Iterator(func(k interface{}, v interface{}) bool {
j++
return false
})
t.Assert(i, 2)
t.Assert(j, 1)
}
func Test_Map_Lock(t *testing.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"}
m := gmap.NewFrom(expect)
m.LockFunc(func(m map[interface{}]interface{}) {
t.Assert(m, expect)
})
m.RLockFunc(func(m map[interface{}]interface{}) {
t.Assert(m, expect)
gtest.C(t, func(t *gtest.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"}
m := gmap.NewFrom(expect)
m.LockFunc(func(m map[interface{}]interface{}) {
t.Assert(m, expect)
})
m.RLockFunc(func(m map[interface{}]interface{}) {
t.Assert(m, expect)
})
})
}
func Test_Map_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"})
m_clone := m.Clone()
m.Remove(1)
//修改原 map,clone 后的 map 不影响
t.AssertIN(1, m_clone.Keys())
gtest.C(t, func(t *gtest.T) {
//clone 方法是深克隆
m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"})
m_clone := m.Clone()
m.Remove(1)
//修改原 map,clone 后的 map 不影响
t.AssertIN(1, m_clone.Keys())
m_clone.Remove("key1")
//修改clone map,原 map 不影响
t.AssertIN("key1", m.Keys())
m_clone.Remove("key1")
//修改clone map,原 map 不影响
t.AssertIN("key1", m.Keys())
})
}
func Test_Map_Basic_Merge(t *testing.T) {
m1 := gmap.New()
m2 := gmap.New()
m1.Set("key1", "val1")
m2.Set("key2", "val2")
m1.Merge(m2)
t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"})
gtest.C(t, func(t *gtest.T) {
m1 := gmap.New()
m2 := gmap.New()
m1.Set("key1", "val1")
m2.Set("key2", "val2")
m1.Merge(m2)
t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"})
})
}

View File

@ -24,7 +24,7 @@ var nf gpool.NewFunc = func() (i interface{}, e error) {
var assertIndex int = 0
var ef gpool.ExpireFunc = func(i interface{}) {
assertIndex++
t.Assert(i, assertIndex)
gtest.Assert(i, assertIndex)
}
func Test_Gpool(t *testing.T) {

View File

@ -104,11 +104,13 @@ func Test_RedBlackTree_Get_Set_Var(t *testing.T) {
}
func Test_RedBlackTree_Batch(t *testing.T) {
m := gtree.NewRedBlackTree(gutil.ComparatorString)
m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.Removes([]interface{}{"key1", 1})
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
gtest.C(t, func(t *gtest.T) {
m := gtree.NewRedBlackTree(gutil.ComparatorString)
m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.Removes([]interface{}{"key1", 1})
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
})
}
func Test_RedBlackTree_Iterator(t *testing.T) {
@ -117,22 +119,24 @@ func Test_RedBlackTree_Iterator(t *testing.T) {
index := 0
expect := map[interface{}]interface{}{"key4": "val4", 1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}
m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, expect)
m.Iterator(func(k interface{}, v interface{}) bool {
t.Assert(k, keys[index])
index++
t.Assert(expect[k], v)
return true
})
m.IteratorDesc(func(k interface{}, v interface{}) bool {
index--
t.Assert(k, keys[index])
t.Assert(expect[k], v)
return true
})
gtest.C(t, func(t *gtest.T) {
m.Iterator(func(k interface{}, v interface{}) bool {
t.Assert(k, keys[index])
index++
t.Assert(expect[k], v)
return true
})
m.IteratorDesc(func(k interface{}, v interface{}) bool {
index--
t.Assert(k, keys[index])
t.Assert(expect[k], v)
return true
})
})
m.Print()
// 断言返回值对遍历控制
gtest.C(t, func(t *gtest.T) {
@ -201,16 +205,18 @@ func Test_RedBlackTree_IteratorFrom(t *testing.T) {
}
func Test_RedBlackTree_Clone(t *testing.T) {
//clone 方法是深克隆
m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"})
m_clone := m.Clone()
m.Remove(1)
//修改原 map,clone 后的 map 不影响
t.AssertIN(1, m_clone.Keys())
gtest.C(t, func(t *gtest.T) {
//clone 方法是深克隆
m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"})
m_clone := m.Clone()
m.Remove(1)
//修改原 map,clone 后的 map 不影响
t.AssertIN(1, m_clone.Keys())
m_clone.Remove("key1")
//修改clone map,原 map 不影响
t.AssertIN("key1", m.Keys())
m_clone.Remove("key1")
//修改clone map,原 map 不影响
t.AssertIN("key1", m.Keys())
})
}
func Test_RedBlackTree_LRNode(t *testing.T) {

View File

@ -390,18 +390,18 @@ func Test_Json(t *testing.T) {
}
func Test_UnmarshalValue(t *testing.T) {
type T struct {
type V struct {
Name string
Var *gvar.Var
}
gtest.C(t, func(t *gtest.T) {
var t *T
var v *V
err := gconv.Struct(map[string]interface{}{
"name": "john",
"var": "v",
}, &t)
}, &v)
t.Assert(err, nil)
t.Assert(t.Name, "john")
t.Assert(t.Var.String(), "v")
t.Assert(v.Name, "john")
t.Assert(v.Var.String(), "v")
})
}

View File

@ -36,7 +36,7 @@ func init() {
"name": true,
"type": true,
}, false)
t.Assert(err, nil)
gtest.Assert(err, nil)
configNode = gdb.ConfigNode{
Host: "127.0.0.1",
Port: "3306",

View File

@ -1510,23 +1510,25 @@ func Test_Model_Delete(t *testing.T) {
func Test_Model_Offset(t *testing.T) {
table := createInitTable()
defer dropTable(table)
result, err := db.Table(table).Limit(2).Offset(5).Order("id").Select()
t.Assert(err, nil)
t.Assert(len(result), 2)
t.Assert(result[0]["id"], 6)
tgit.Assert(result[1]["id"], 7)
gtest.C(t, func(t *gtest.T) {
result, err := db.Table(table).Limit(2).Offset(5).Order("id").Select()
t.Assert(err, nil)
t.Assert(len(result), 2)
t.Assert(result[0]["id"], 6)
t.Assert(result[1]["id"], 7)
})
}
func Test_Model_ForPage(t *testing.T) {
table := createInitTable()
defer dropTable(table)
result, err := db.Table(table).ForPage(3, 3).Order("id").Select()
t.Assert(err, nil)
t.Assert(len(result), 3)
t.Assert(result[0]["id"], 7)
t.Assert(result[1]["id"], 8)
gtest.C(t, func(t *gtest.T) {
result, err := db.Table(table).Page(3, 3).Order("id").All()
t.Assert(err, nil)
t.Assert(len(result), 3)
t.Assert(result[0]["id"], 7)
t.Assert(result[1]["id"], 8)
})
}
func Test_Model_Option_Map(t *testing.T) {

View File

@ -102,7 +102,7 @@ func Test_TX_Prepare(t *testing.T) {
if err != nil {
gtest.Error(err)
}
t.Assert(array[0], "100")
gtest.Assert(array[0], "100")
if err := rows.Close(); err != nil {
gtest.Error(err)
}

View File

@ -14,71 +14,75 @@ import (
)
func Test_LeEncodeAndLeDecode(t *testing.T) {
for k, v := range testData {
ve := gbinary.LeEncode(v)
ve1 := gbinary.LeEncodeByLength(len(ve), v)
gtest.C(t, func(t *gtest.T) {
for k, v := range testData {
ve := gbinary.LeEncode(v)
ve1 := gbinary.LeEncodeByLength(len(ve), v)
//t.Logf("%s:%v, encoded:%v\n", k, v, ve)
switch v.(type) {
case int:
t.Assert(gbinary.LeDecodeToInt(ve), v)
t.Assert(gbinary.LeDecodeToInt(ve1), v)
case int8:
t.Assert(gbinary.LeDecodeToInt8(ve), v)
t.Assert(gbinary.LeDecodeToInt8(ve1), v)
case int16:
t.Assert(gbinary.LeDecodeToInt16(ve), v)
t.Assert(gbinary.LeDecodeToInt16(ve1), v)
case int32:
t.Assert(gbinary.LeDecodeToInt32(ve), v)
t.Assert(gbinary.LeDecodeToInt32(ve1), v)
case int64:
t.Assert(gbinary.LeDecodeToInt64(ve), v)
t.Assert(gbinary.LeDecodeToInt64(ve1), v)
case uint:
t.Assert(gbinary.LeDecodeToUint(ve), v)
t.Assert(gbinary.LeDecodeToUint(ve1), v)
case uint8:
t.Assert(gbinary.LeDecodeToUint8(ve), v)
t.Assert(gbinary.LeDecodeToUint8(ve1), v)
case uint16:
t.Assert(gbinary.LeDecodeToUint16(ve1), v)
t.Assert(gbinary.LeDecodeToUint16(ve), v)
case uint32:
t.Assert(gbinary.LeDecodeToUint32(ve1), v)
t.Assert(gbinary.LeDecodeToUint32(ve), v)
case uint64:
t.Assert(gbinary.LeDecodeToUint64(ve), v)
t.Assert(gbinary.LeDecodeToUint64(ve1), v)
case bool:
t.Assert(gbinary.LeDecodeToBool(ve), v)
t.Assert(gbinary.LeDecodeToBool(ve1), v)
case string:
t.Assert(gbinary.LeDecodeToString(ve), v)
t.Assert(gbinary.LeDecodeToString(ve1), v)
case float32:
t.Assert(gbinary.LeDecodeToFloat32(ve), v)
t.Assert(gbinary.LeDecodeToFloat32(ve1), v)
case float64:
t.Assert(gbinary.LeDecodeToFloat64(ve), v)
t.Assert(gbinary.LeDecodeToFloat64(ve1), v)
default:
if v == nil {
continue
//t.Logf("%s:%v, encoded:%v\n", k, v, ve)
switch v.(type) {
case int:
t.Assert(gbinary.LeDecodeToInt(ve), v)
t.Assert(gbinary.LeDecodeToInt(ve1), v)
case int8:
t.Assert(gbinary.LeDecodeToInt8(ve), v)
t.Assert(gbinary.LeDecodeToInt8(ve1), v)
case int16:
t.Assert(gbinary.LeDecodeToInt16(ve), v)
t.Assert(gbinary.LeDecodeToInt16(ve1), v)
case int32:
t.Assert(gbinary.LeDecodeToInt32(ve), v)
t.Assert(gbinary.LeDecodeToInt32(ve1), v)
case int64:
t.Assert(gbinary.LeDecodeToInt64(ve), v)
t.Assert(gbinary.LeDecodeToInt64(ve1), v)
case uint:
t.Assert(gbinary.LeDecodeToUint(ve), v)
t.Assert(gbinary.LeDecodeToUint(ve1), v)
case uint8:
t.Assert(gbinary.LeDecodeToUint8(ve), v)
t.Assert(gbinary.LeDecodeToUint8(ve1), v)
case uint16:
t.Assert(gbinary.LeDecodeToUint16(ve1), v)
t.Assert(gbinary.LeDecodeToUint16(ve), v)
case uint32:
t.Assert(gbinary.LeDecodeToUint32(ve1), v)
t.Assert(gbinary.LeDecodeToUint32(ve), v)
case uint64:
t.Assert(gbinary.LeDecodeToUint64(ve), v)
t.Assert(gbinary.LeDecodeToUint64(ve1), v)
case bool:
t.Assert(gbinary.LeDecodeToBool(ve), v)
t.Assert(gbinary.LeDecodeToBool(ve1), v)
case string:
t.Assert(gbinary.LeDecodeToString(ve), v)
t.Assert(gbinary.LeDecodeToString(ve1), v)
case float32:
t.Assert(gbinary.LeDecodeToFloat32(ve), v)
t.Assert(gbinary.LeDecodeToFloat32(ve1), v)
case float64:
t.Assert(gbinary.LeDecodeToFloat64(ve), v)
t.Assert(gbinary.LeDecodeToFloat64(ve1), v)
default:
if v == nil {
continue
}
res := make([]byte, len(ve))
err := gbinary.LeDecode(ve, res)
if err != nil {
t.Errorf("test data: %s, %v, error:%v", k, v, err)
}
t.Assert(res, v)
}
res := make([]byte, len(ve))
err := gbinary.LeDecode(ve, res)
if err != nil {
t.Errorf("test data: %s, %v, error:%v", k, v, err)
}
t.Assert(res, v)
}
}
})
}
func Test_LeEncodeStruct(t *testing.T) {
user := User{"wenzi1", 999, "www.baidu.com"}
ve := gbinary.LeEncode(user)
s := gbinary.LeDecodeToString(ve)
t.Assert(string(s), s)
gtest.C(t, func(t *gtest.T) {
user := User{"wenzi1", 999, "www.baidu.com"}
ve := gbinary.LeEncode(user)
s := gbinary.LeDecodeToString(ve)
t.Assert(s, s)
})
}

View File

@ -44,14 +44,15 @@ func TestRowEncodeAndDecode(t *testing.T) {
}
func TestBuildQuery(t *testing.T) {
src := url.Values{
"a": {"a2", "a1"},
"b": {"b2", "b1"},
"c": {"c1", "c2"},
}
expect := "a=a2&a=a1&b=b2&b=b1&c=c1&c=c2"
t.Assert(gurl.BuildQuery(src), expect)
gtest.C(t, func(t *gtest.T) {
src := url.Values{
"a": {"a2", "a1"},
"b": {"b2", "b1"},
"c": {"c1", "c2"},
}
expect := "a=a2&a=a1&b=b2&b=b1&c=c1&c=c2"
t.Assert(gurl.BuildQuery(src), expect)
})
}
func TestParseURL(t *testing.T) {

View File

@ -105,7 +105,7 @@ func Test_Package_Timeout(t *testing.T) {
break
}
time.Sleep(time.Second)
t.Assert(conn.SendPkg(data), nil)
gtest.Assert(conn.SendPkg(data), nil)
}
})
go s.Run()
@ -141,7 +141,7 @@ func Test_Package_Option(t *testing.T) {
if err != nil {
break
}
t.Assert(conn.SendPkg(data, option), nil)
gtest.Assert(conn.SendPkg(data, option), nil)
}
})
go s.Run()

View File

@ -105,7 +105,7 @@ func Test_Pool_Package_Timeout(t *testing.T) {
break
}
time.Sleep(time.Second)
t.Assert(conn.SendPkg(data), nil)
gtest.Assert(conn.SendPkg(data), nil)
}
})
go s.Run()
@ -141,7 +141,7 @@ func Test_Pool_Package_Option(t *testing.T) {
if err != nil {
break
}
t.Assert(conn.SendPkg(data, option), nil)
gtest.Assert(conn.SendPkg(data, option), nil)
}
})
go s.Run()