新增测试方法

This commit is contained in:
Jay 2019-04-12 10:59:05 +08:00
parent 905f46359a
commit b489eed4ef
9 changed files with 122 additions and 8 deletions

View File

@ -51,18 +51,31 @@ func Test_IntBoolMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get(1), true)
gtest.Assert(m.Get(2), true)
gtest.Assert(m.SetIfNotExistFunc(1, getBool), false)
gtest.Assert(m.SetIfNotExistFunc(4, getBool), true)
gtest.Assert(m.SetIfNotExistFuncLock(2, getBool), false)
gtest.Assert(m.SetIfNotExistFuncLock(3, getBool), true)
}
func Test_IntBoolMap_Batch(t *testing.T) {
m := gmap.NewIntBoolMap()
m.BatchSet(map[int]bool{1: true, 2: false, 3: true})
m.Iterator(intBoolCallBack)
gtest.Assert(m.Map(), map[int]bool{1: true, 2: false, 3: true})
m.BatchRemove([]int{1, 2})
gtest.Assert(m.Map(), map[int]bool{3: true})
}
func Test_IntBoolMap_Iterator(t *testing.T){
m := gmap.NewIntBoolMapFrom(map[int]bool{1: true, 2: false})
m.Iterator(intBoolCallBack)
}
func Test_IntBoolMap_Lock(t *testing.T){
m := gmap.NewIntBoolMapFrom(map[int]bool{1: true, 2: false})
m.LockFunc(func(m map[int]bool) {})
m.RLockFunc(func(m map[int]bool) {})
}
func Test_IntBoolMap_Clone(t *testing.T) {
//clone 方法是深克隆

View File

@ -55,7 +55,11 @@ func Test_IntIntMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get(1), 123)
gtest.Assert(m.Get(2), 123)
gtest.Assert(m.SetIfNotExistFunc(1, getInt), false)
gtest.Assert(m.SetIfNotExistFunc(3, getInt), true)
gtest.Assert(m.SetIfNotExistFuncLock(2, getInt), false)
gtest.Assert(m.SetIfNotExistFuncLock(4, getInt), true)
}
func Test_IntIntMap_Batch(t *testing.T) {
@ -68,6 +72,16 @@ func Test_IntIntMap_Batch(t *testing.T) {
gtest.Assert(m.Map(), map[int]int{3: 3})
}
func Test_IntIntMap_Iterator(t *testing.T){
m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2})
m.Iterator(intIntCallBack)
}
func Test_IntIntMap_Lock(t *testing.T){
m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2})
m.LockFunc(func(m map[int]int) {})
m.RLockFunc(func(m map[int]int) {})
}
func Test_IntIntMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2})

View File

@ -54,20 +54,33 @@ func Test_IntInterfaceMap_Set_Fun(t *testing.T) {
m.GetOrSetFuncLock(2, getInterface)
gtest.Assert(m.Get(1), 123)
gtest.Assert(m.Get(2), 123)
gtest.Assert(m.SetIfNotExistFunc(1, getInterface), false)
gtest.Assert(m.SetIfNotExistFunc(3, getInterface), true)
gtest.Assert(m.SetIfNotExistFuncLock(2, getInterface), false)
gtest.Assert(m.SetIfNotExistFuncLock(4, getInterface), true)
}
func Test_IntInterfaceMap_Batch(t *testing.T) {
m := gmap.NewIntInterfaceMap()
m.BatchSet(map[int]interface{}{1: 1, 2: "2", 3: 3})
m.Iterator(intInterfaceCallBack)
gtest.Assert(m.Map(), map[int]interface{}{1: 1, 2: "2", 3: 3})
m.BatchRemove([]int{1, 2})
gtest.Assert(m.Map(), map[int]interface{}{3: 3})
}
func Test_IntInterfaceMap_Iterator(t *testing.T){
m := gmap.NewIntInterfaceMapFrom(map[int]interface{}{1: 1, 2: "2"})
m.Iterator(intInterfaceCallBack)
}
func Test_IntInterfaceMap_Lock(t *testing.T){
m := gmap.NewIntInterfaceMapFrom(map[int]interface{}{1: 1, 2: "2"})
m.LockFunc(func(m map[int]interface{}) {})
m.RLockFunc(func(m map[int]interface{}) {})
}
func Test_IntInterfaceMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewIntInterfaceMapFrom(map[int]interface{}{1: 1, 2: "2"})

View File

@ -60,19 +60,31 @@ func Test_IntStringMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get(1), "z")
gtest.Assert(m.Get(2), "z")
gtest.Assert(m.SetIfNotExistFunc(1, getString), false)
gtest.Assert(m.SetIfNotExistFunc(3, getString), true)
gtest.Assert(m.SetIfNotExistFuncLock(2, getString), false)
gtest.Assert(m.SetIfNotExistFuncLock(4, getString), true)
}
func Test_IntStringMap_Batch(t *testing.T) {
m := gmap.NewIntStringMap()
m.BatchSet(map[int]string{1: "a", 2: "b", 3: "c"})
m.Iterator(intStringCallBack)
gtest.Assert(m.Map(), map[int]string{1: "a", 2: "b",3: "c"})
m.BatchRemove([]int{1, 2})
gtest.Assert(m.Map(), map[int]interface{}{3: "c"})
}
func Test_IntStringMap_Iterator(t *testing.T){
m := gmap.NewIntStringMapFrom(map[int]string{1: "a", 2: "b", 3: "c"})
m.Iterator(intStringCallBack)
}
func Test_IntStringMap_Lock(t *testing.T){
m := gmap.NewIntStringMapFrom(map[int]string{1: "a", 2: "b", 3: "c"})
m.LockFunc(func(m map[int]string) {})
m.RLockFunc(func(m map[int]string) {})
}
func Test_IntStringMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewIntStringMapFrom(map[int]string{1: "a", 2: "b", 3: "c"})

View File

@ -12,6 +12,7 @@ func getValue() interface{} {
func callBack(k interface{}, v interface{}) bool {
return true
}
func Test_Map_Basic(t *testing.T) {
gtest.Case(t, func() {
m := gmap.New()
@ -63,11 +64,20 @@ func Test_Map_Set_Fun(t *testing.T) {
func Test_Map_Batch(t *testing.T) {
m := gmap.New()
m.BatchSet(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.Iterator(callBack)
gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"})
m.BatchRemove([]interface{}{"key1", 1})
gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
}
func Test_Map_Iterator(t *testing.T){
m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"})
m.Iterator(callBack)
}
func Test_Map_Lock(t *testing.T){
m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"})
m.LockFunc(func(m map[interface{}]interface{}) {})
m.RLockFunc(func(m map[interface{}]interface{}) {})
}
func Test_Map_Clone(t *testing.T) {
//clone 方法是深克隆

View File

@ -49,19 +49,33 @@ func Test_StringBoolMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get("a"), true)
gtest.Assert(m.Get("b"), true)
gtest.Assert(m.SetIfNotExistFunc("a", getBool), false)
gtest.Assert(m.SetIfNotExistFunc("c", getBool), true)
gtest.Assert(m.SetIfNotExistFuncLock("b", getBool), false)
gtest.Assert(m.SetIfNotExistFuncLock("d", getBool), true)
}
func Test_StringBoolMap_Batch(t *testing.T) {
m := gmap.NewStringBoolMap()
m.BatchSet(map[string]bool{"a": true, "b": false, "c": true})
m.Iterator(StringBoolCallBack)
gtest.Assert(m.Map(), map[string]bool{"a": true, "b": false, "c": true})
m.BatchRemove([]string{"a", "b"})
gtest.Assert(m.Map(), map[string]bool{"c": true})
}
func Test_StringBoolMap_Iterator(t *testing.T){
m := gmap.NewStringBoolMapFrom(map[string]bool{"a": true, "b": false})
m.Iterator(StringBoolCallBack)
}
func Test_StringBoolMap_Lock(t *testing.T){
m := gmap.NewStringBoolMapFrom(map[string]bool{"a": true, "b": false})
m.LockFunc(func(m map[string]bool) {})
m.RLockFunc(func(m map[string]bool) {})
}
func Test_StringBoolMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewStringBoolMapFrom(map[string]bool{"a": true, "b": false})

View File

@ -55,18 +55,31 @@ func Test_StringIntMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get("a"), 123)
gtest.Assert(m.Get("b"), 123)
gtest.Assert(m.SetIfNotExistFunc("a", getInt), false)
gtest.Assert(m.SetIfNotExistFunc("c", getInt), true)
gtest.Assert(m.SetIfNotExistFuncLock("b", getInt), false)
gtest.Assert(m.SetIfNotExistFuncLock("d", getInt), true)
}
func Test_StringIntMap_Batch(t *testing.T) {
m := gmap.NewStringIntMap()
m.BatchSet(map[string]int{"a": 1, "b": 2, "c": 3})
m.Iterator(stringIntCallBack)
gtest.Assert(m.Map(), map[string]int{"a": 1, "b": 2, "c": 3})
m.BatchRemove([]string{"a", "b"})
gtest.Assert(m.Map(), map[string]int{"c": 3})
}
func Test_StringBIntMap_Iterator(t *testing.T) {
m := gmap.NewStringIntMapFrom(map[string]int{"a": 1, "b": 2, "c": 3})
m.Iterator(stringIntCallBack)
}
func Test_StringIntMap_Lock(t *testing.T) {
m := gmap.NewStringIntMapFrom(map[string]int{"a": 1, "b": 2, "c": 3})
m.LockFunc(func(m map[string]int) {})
m.RLockFunc(func(m map[string]int) {})
}
func Test_StringIntMap_Clone(t *testing.T) {
//clone 方法是深克隆

View File

@ -53,19 +53,32 @@ func Test_StringInterfaceMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get("a"), 123)
gtest.Assert(m.Get("b"), 123)
gtest.Assert(m.SetIfNotExistFunc("a", getInterface), false)
gtest.Assert(m.SetIfNotExistFunc("c", getInterface), true)
gtest.Assert(m.SetIfNotExistFuncLock("b", getInterface), false)
gtest.Assert(m.SetIfNotExistFuncLock("d", getInterface), true)
}
func Test_StringInterfaceMap_Batch(t *testing.T) {
m := gmap.NewStringInterfaceMap()
m.BatchSet(map[string]interface{}{"a": 1, "b": "2", "c": 3})
m.Iterator(stringInterfaceCallBack)
gtest.Assert(m.Map(), map[string]interface{}{"a": 1, "b": "2", "c": 3})
m.BatchRemove([]string{"a", "b"})
gtest.Assert(m.Map(), map[string]interface{}{"c": 3})
}
func Test_StringInterfaceMap_Iterator(t *testing.T) {
m := gmap.NewStringInterfaceMapFrom(map[string]interface{}{"a": 1, "b": "2"})
m.Iterator(stringInterfaceCallBack)
}
func Test_StringInterfaceMap_Lock(t *testing.T) {
m := gmap.NewStringInterfaceMapFrom(map[string]interface{}{"a": 1, "b": "2"})
m.LockFunc(func(m map[string]interface{}) {})
m.RLockFunc(func(m map[string]interface{}) {})
}
func Test_StringInterfaceMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewStringInterfaceMapFrom(map[string]interface{}{"a": 1, "b": "2"})

View File

@ -54,19 +54,31 @@ func Test_StringStringMap_Set_Fun(t *testing.T) {
gtest.Assert(m.Get("a"), "z")
gtest.Assert(m.Get("b"), "z")
gtest.Assert(m.SetIfNotExistFunc("a", getString), false)
gtest.Assert(m.SetIfNotExistFunc("c", getString), true)
gtest.Assert(m.SetIfNotExistFuncLock("b", getString), false)
gtest.Assert(m.SetIfNotExistFuncLock("d", getString), true)
}
func Test_StringStringMap_Batch(t *testing.T) {
m := gmap.NewStringStringMap()
m.BatchSet(map[string]string{"a": "a", "b": "b", "c": "c"})
m.Iterator(stringStringCallBack)
gtest.Assert(m.Map(), map[string]string{"a": "a", "b": "b", "c": "c"})
m.BatchRemove([]string{"a", "b"})
gtest.Assert(m.Map(), map[string]string{"c": "c"})
}
func Test_StringStringMap_Iterator(t *testing.T) {
m := gmap.NewStringStringMapFrom(map[string]string{"a": "a", "b": "b", "c": "c"})
m.Iterator(stringStringCallBack)
}
func Test_StringStringMap_Lock(t *testing.T) {
m := gmap.NewStringStringMapFrom(map[string]string{"a": "a", "b": "b", "c": "c"})
m.LockFunc(func(m map[string]string) {})
m.RLockFunc(func(m map[string]string) {})
}
func Test_StringStringMap_Clone(t *testing.T) {
//clone 方法是深克隆
m := gmap.NewStringStringMapFrom(map[string]string{"a": "a", "b": "b", "c": "c"})