1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
Files
go-mixed/maps/hash_map_test.go
2022-05-12 11:32:03 +08:00

26 lines
495 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) {
if _, ok := m[s]; !ok {
t.Fatal("值不存在")
}
})
for k := range m {
assert.True(t, hashMap.Exist(k))
}
}