diff --git a/g/container/gmap/gmap_z_int_bool_test.go b/g/container/gmap/gmap_z_int_bool_test.go index 657212155..75c06b357 100644 --- a/g/container/gmap/gmap_z_int_bool_test.go +++ b/g/container/gmap/gmap_z_int_bool_test.go @@ -67,14 +67,37 @@ func Test_IntBoolMap_Batch(t *testing.T) { 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) + expect := map[int]bool{1: true, 2: false} + m := gmap.NewIntBoolMapFrom(expect) + m.Iterator(func(k int, v bool) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v bool) bool { + i++ + return true + }) + m.Iterator(func(k int, v bool) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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) {}) + expect := map[int]bool{1: true, 2: false} + m := gmap.NewIntBoolMapFrom(expect) + m.LockFunc(func(m map[int]bool) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]bool) { + gtest.Assert(m, expect) + }) + } func Test_IntBoolMap_Clone(t *testing.T) { diff --git a/g/container/gmap/gmap_z_int_int_test.go b/g/container/gmap/gmap_z_int_int_test.go index 01f785afe..c58437cb4 100644 --- a/g/container/gmap/gmap_z_int_int_test.go +++ b/g/container/gmap/gmap_z_int_int_test.go @@ -73,14 +73,37 @@ func Test_IntIntMap_Batch(t *testing.T) { } func Test_IntIntMap_Iterator(t *testing.T){ - m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2}) - m.Iterator(intIntCallBack) + expect := map[int]int{1: 1, 2: 2} + m := gmap.NewIntIntMapFrom(expect) + m.Iterator(func(k int, v int) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v int) bool { + i++ + return true + }) + m.Iterator(func(k int, v int) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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) {}) + expect := map[int]int{1: 1, 2: 2} + m := gmap.NewIntIntMapFrom(expect) + m.LockFunc(func(m map[int]int) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]int) { + gtest.Assert(m, expect) + }) + } func Test_IntIntMap_Clone(t *testing.T) { //clone 方法是深克隆 diff --git a/g/container/gmap/gmap_z_int_interface_test.go b/g/container/gmap/gmap_z_int_interface_test.go index 636cd9dad..3bfb47fcf 100644 --- a/g/container/gmap/gmap_z_int_interface_test.go +++ b/g/container/gmap/gmap_z_int_interface_test.go @@ -72,14 +72,38 @@ func Test_IntInterfaceMap_Batch(t *testing.T) { 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) + expect := map[int]interface{}{1: 1, 2: "2"} + m := gmap.NewIntInterfaceMapFrom(expect) + m.Iterator(func(k int, v interface{}) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k int, v interface{}) bool { + j++ + return false + }) + gtest.Assert(i, "2") + gtest.Assert(j, 1) + + } 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{}) {}) + expect := map[int]interface{}{1: 1, 2: "2"} + m := gmap.NewIntInterfaceMapFrom(expect) + m.LockFunc(func(m map[int]interface{}) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]interface{}) { + gtest.Assert(m, expect) + }) } func Test_IntInterfaceMap_Clone(t *testing.T) { //clone 方法是深克隆 diff --git a/g/container/gmap/gmap_z_int_string_test.go b/g/container/gmap/gmap_z_int_string_test.go index ef0bad8ea..287fc7b6f 100644 --- a/g/container/gmap/gmap_z_int_string_test.go +++ b/g/container/gmap/gmap_z_int_string_test.go @@ -76,14 +76,38 @@ func Test_IntStringMap_Batch(t *testing.T) { 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) + expect := map[int]string{1: "a", 2: "b"} + m := gmap.NewIntStringMapFrom(expect) + m.Iterator(func(k int, v string) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v string) bool { + i++ + return true + }) + m.Iterator(func(k int, v string) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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) {}) + + expect := map[int]string{1: "a", 2: "b", 3: "c"} + m := gmap.NewIntStringMapFrom(expect) + m.LockFunc(func(m map[int]string) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]string) { + gtest.Assert(m, expect) + }) + } func Test_IntStringMap_Clone(t *testing.T) { //clone 方法是深克隆 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 4e9d9f4c7..7d90591a1 100644 --- a/g/container/gmap/gmap_z_interface_interface_basic_test.go +++ b/g/container/gmap/gmap_z_interface_interface_basic_test.go @@ -69,14 +69,38 @@ func Test_Map_Batch(t *testing.T) { 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) + expect :=map[interface{}]interface{}{1: 1, "key1": "val1"} + + m := gmap.NewFrom(expect) + m.Iterator(func(k interface{}, v interface{}) bool { + gtest.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 + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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{}) {}) + expect :=map[interface{}]interface{}{1: 1, "key1": "val1"} + + m := gmap.NewFrom(expect) + m.LockFunc(func(m map[interface{}]interface{}) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[interface{}]interface{}) { + gtest.Assert(m, expect) + }) } func Test_Map_Clone(t *testing.T) { diff --git a/g/container/gmap/gmap_z_string_bool_test.go b/g/container/gmap/gmap_z_string_bool_test.go index c8cc0d5f8..3e0f2a1c0 100644 --- a/g/container/gmap/gmap_z_string_bool_test.go +++ b/g/container/gmap/gmap_z_string_bool_test.go @@ -6,8 +6,7 @@ import ( "testing" ) - -func StringBoolCallBack( string, bool) bool { +func StringBoolCallBack(string, bool) bool { return true } func Test_StringBoolMap_Basic(t *testing.T) { @@ -65,15 +64,39 @@ func Test_StringBoolMap_Batch(t *testing.T) { 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_Iterator(t *testing.T) { + expect := map[string]bool{"a": true, "b": false} + m := gmap.NewStringBoolMapFrom(expect) + m.Iterator(func(k string, v bool) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v bool) bool { + i++ + return true + }) + m.Iterator(func(k string, v bool) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) + } -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_Lock(t *testing.T) { + expect := map[string]bool{"a": true, "b": false} + + m := gmap.NewStringBoolMapFrom(expect) + m.LockFunc(func(m map[string]bool) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]bool) { + gtest.Assert(m, expect) + }) } func Test_StringBoolMap_Clone(t *testing.T) { diff --git a/g/container/gmap/gmap_z_string_int_test.go b/g/container/gmap/gmap_z_string_int_test.go index cb4c234cb..fad493c19 100644 --- a/g/container/gmap/gmap_z_string_int_test.go +++ b/g/container/gmap/gmap_z_string_int_test.go @@ -70,15 +70,39 @@ func Test_StringIntMap_Batch(t *testing.T) { 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_Iterator(t *testing.T) { + expect := map[string]int{"a": 1, "b": 2} + m := gmap.NewStringIntMapFrom(expect) + m.Iterator(func(k string, v int) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v int) bool { + i++ + return true + }) + m.Iterator(func(k string, v int) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) + } 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) {}) + expect := map[string]int{"a": 1, "b": 2} + + m := gmap.NewStringIntMapFrom(expect) + m.LockFunc(func(m map[string]int) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]int) { + gtest.Assert(m, expect) + }) } func Test_StringIntMap_Clone(t *testing.T) { diff --git a/g/container/gmap/gmap_z_string_interface_test.go b/g/container/gmap/gmap_z_string_interface_test.go index e870f22db..dd1319220 100644 --- a/g/container/gmap/gmap_z_string_interface_test.go +++ b/g/container/gmap/gmap_z_string_interface_test.go @@ -70,14 +70,37 @@ func Test_StringInterfaceMap_Batch(t *testing.T) { } func Test_StringInterfaceMap_Iterator(t *testing.T) { - m := gmap.NewStringInterfaceMapFrom(map[string]interface{}{"a": 1, "b": "2"}) - m.Iterator(stringInterfaceCallBack) + expect := map[string]interface{}{"a": true, "b": false} + m := gmap.NewStringInterfaceMapFrom(expect) + m.Iterator(func(k string, v interface{}) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k string, v interface{}) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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{}) {}) + expect := map[string]interface{}{"a": true, "b": false} + + m := gmap.NewStringInterfaceMapFrom(expect) + m.LockFunc(func(m map[string]interface{}) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]interface{}) { + gtest.Assert(m, expect) + }) } func Test_StringInterfaceMap_Clone(t *testing.T) { //clone 方法是深克隆 diff --git a/g/container/gmap/gmap_z_string_string_test.go b/g/container/gmap/gmap_z_string_string_test.go index 653aa56e5..77caab856 100644 --- a/g/container/gmap/gmap_z_string_string_test.go +++ b/g/container/gmap/gmap_z_string_string_test.go @@ -70,14 +70,37 @@ func Test_StringStringMap_Batch(t *testing.T) { 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) + expect := map[string]string{"a": "a", "b": "b"} + m := gmap.NewStringStringMapFrom(expect) + m.Iterator(func(k string, v string) bool { + gtest.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v string) bool { + i++ + return true + }) + m.Iterator(func(k string, v string) bool { + j++ + return false + }) + gtest.Assert(i, 2) + gtest.Assert(j, 1) } 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) {}) + expect := map[string]string{"a": "a", "b": "b"} + + m := gmap.NewStringStringMapFrom(expect) + m.LockFunc(func(m map[string]string) { + gtest.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]string) { + gtest.Assert(m, expect) + }) } func Test_StringStringMap_Clone(t *testing.T) { //clone 方法是深克隆