1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

test: add test for currentmap

This commit is contained in:
dudaodong
2023-07-27 11:54:52 +08:00
parent 4715301240
commit 4558d7a3c2

View File

@@ -121,3 +121,49 @@ func TestConcurrentMap_GetAndDelete(t *testing.T) {
}(j)
}
}
func TestConcurrentMap_Has(t *testing.T) {
assert := internal.NewAssert(t, "TestConcurrentMap_Has")
cm := NewConcurrentMap[string, int](100)
var wg1 sync.WaitGroup
wg1.Add(10)
for i := 0; i < 10; i++ {
go func(n int) {
cm.Set(fmt.Sprintf("%d", n), n)
wg1.Done()
}(i)
}
wg1.Wait()
for j := 0; j < 10; j++ {
go func(n int) {
ok := cm.Has(fmt.Sprintf("%d", n))
assert.Equal(true, ok)
}(j)
}
}
func TestConcurrentMap_Range(t *testing.T) {
assert := internal.NewAssert(t, "TestConcurrentMap_Range")
cm := NewConcurrentMap[string, int](100)
var wg1 sync.WaitGroup
wg1.Add(10)
for i := 0; i < 10; i++ {
go func(n int) {
cm.Set(fmt.Sprintf("%d", n), n)
wg1.Done()
}(i)
}
wg1.Wait()
cm.Range(func(key string, value int) bool {
assert.Equal(key, fmt.Sprintf("%d", value))
return true
})
}