1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
Files
go-mixed/maps/hash_map_test.go
2022-05-31 13:47:48 +08:00

28 lines
516 B
Go

package maps
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestForEach(t *testing.T) {
m := map[string]any{"b": "b", "a": "a", "d": "d", "c": "c"}
var hashMap = NewHashMap(map[string]any{"b": "b", "a": "a", "d": "d", "c": "c"})
assert.True(t, hashMap.Exist("a"))
assert.Equal(t, len(m), hashMap.Count())
hashMap.ForEach(func(s string, a any) bool {
if _, ok := m[s]; !ok {
t.Fatal("值不存在")
}
return false
})
for k := range m {
assert.True(t, hashMap.Exist(k))
}
}