mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
泛型
This commit is contained in:
31
collections/generics/map_test.go
Normal file
31
collections/generics/map_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package generics_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/charlienet/go-mixed/collections/generics"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIMap(t *testing.T) {
|
||||
k := "abc"
|
||||
v := "bcd"
|
||||
|
||||
var m generics.Map[string, string] = generics.NewConcurrnetMap[string, string]()
|
||||
m.Set(k, v)
|
||||
_, ok := m.Get(k)
|
||||
assert.True(t, ok, "不存在")
|
||||
t.Log(m.Count())
|
||||
|
||||
m.Delete(k)
|
||||
_, ok = m.Get(k)
|
||||
assert.False(t, ok, "不存在")
|
||||
|
||||
t.Log(m.Count())
|
||||
}
|
||||
|
||||
func TestMapCount(t *testing.T) {
|
||||
mm := make(map[string]string)
|
||||
mm["a"] = "b"
|
||||
assert.Equal(t, 1, len(mm))
|
||||
}
|
Reference in New Issue
Block a user