From 4558d7a3c2677b2a05d836cb2786c1c5a9d210f8 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Thu, 27 Jul 2023 11:54:52 +0800 Subject: [PATCH] test: add test for currentmap --- maputil/concurrentmap_test.go | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/maputil/concurrentmap_test.go b/maputil/concurrentmap_test.go index 31d88dc..ca75d40 100644 --- a/maputil/concurrentmap_test.go +++ b/maputil/concurrentmap_test.go @@ -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 + }) +}