From b489eed4efe22de21618d4d82361078008500a4f Mon Sep 17 00:00:00 2001 From: Jay <976739120@qq.com> Date: Fri, 12 Apr 2019 10:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=8B=E8=AF=95=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/container/gmap/gmap_z_int_bool_test.go | 15 ++++++++++++++- g/container/gmap/gmap_z_int_int_test.go | 14 ++++++++++++++ g/container/gmap/gmap_z_int_interface_test.go | 15 ++++++++++++++- g/container/gmap/gmap_z_int_string_test.go | 14 +++++++++++++- .../gmap_z_interface_interface_basic_test.go | 12 +++++++++++- g/container/gmap/gmap_z_string_bool_test.go | 16 +++++++++++++++- g/container/gmap/gmap_z_string_int_test.go | 15 ++++++++++++++- g/container/gmap/gmap_z_string_interface_test.go | 15 ++++++++++++++- g/container/gmap/gmap_z_string_string_test.go | 14 +++++++++++++- 9 files changed, 122 insertions(+), 8 deletions(-) diff --git a/g/container/gmap/gmap_z_int_bool_test.go b/g/container/gmap/gmap_z_int_bool_test.go index 078bd3077..657212155 100644 --- a/g/container/gmap/gmap_z_int_bool_test.go +++ b/g/container/gmap/gmap_z_int_bool_test.go @@ -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 方法是深克隆 diff --git a/g/container/gmap/gmap_z_int_int_test.go b/g/container/gmap/gmap_z_int_int_test.go index c7151960e..01f785afe 100644 --- a/g/container/gmap/gmap_z_int_int_test.go +++ b/g/container/gmap/gmap_z_int_int_test.go @@ -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}) diff --git a/g/container/gmap/gmap_z_int_interface_test.go b/g/container/gmap/gmap_z_int_interface_test.go index eb5a47598..636cd9dad 100644 --- a/g/container/gmap/gmap_z_int_interface_test.go +++ b/g/container/gmap/gmap_z_int_interface_test.go @@ -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"}) diff --git a/g/container/gmap/gmap_z_int_string_test.go b/g/container/gmap/gmap_z_int_string_test.go index 386e3a710..ef0bad8ea 100644 --- a/g/container/gmap/gmap_z_int_string_test.go +++ b/g/container/gmap/gmap_z_int_string_test.go @@ -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"}) diff --git a/g/container/gmap/gmap_z_interface_interface_basic_test.go b/g/container/gmap/gmap_z_interface_interface_basic_test.go index ead2dae73..4e9d9f4c7 100644 --- a/g/container/gmap/gmap_z_interface_interface_basic_test.go +++ b/g/container/gmap/gmap_z_interface_interface_basic_test.go @@ -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 方法是深克隆 diff --git a/g/container/gmap/gmap_z_string_bool_test.go b/g/container/gmap/gmap_z_string_bool_test.go index 63b251ed3..c8cc0d5f8 100644 --- a/g/container/gmap/gmap_z_string_bool_test.go +++ b/g/container/gmap/gmap_z_string_bool_test.go @@ -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}) diff --git a/g/container/gmap/gmap_z_string_int_test.go b/g/container/gmap/gmap_z_string_int_test.go index 7c1050d46..cb4c234cb 100644 --- a/g/container/gmap/gmap_z_string_int_test.go +++ b/g/container/gmap/gmap_z_string_int_test.go @@ -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 方法是深克隆 diff --git a/g/container/gmap/gmap_z_string_interface_test.go b/g/container/gmap/gmap_z_string_interface_test.go index 74e94115d..e870f22db 100644 --- a/g/container/gmap/gmap_z_string_interface_test.go +++ b/g/container/gmap/gmap_z_string_interface_test.go @@ -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"}) diff --git a/g/container/gmap/gmap_z_string_string_test.go b/g/container/gmap/gmap_z_string_string_test.go index 443878839..653aa56e5 100644 --- a/g/container/gmap/gmap_z_string_string_test.go +++ b/g/container/gmap/gmap_z_string_string_test.go @@ -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"})