8 "github.com/stretchr/testify/assert"
11 func TestIterateKeysWithValues(t *testing.T) {
14 for i := 1; i <= 10; i++ {
15 cmap.Set(fmt.Sprintf("key%d", i), fmt.Sprintf("value%d", i))
19 assert.Equal(t, 10, cmap.Size())
20 assert.Equal(t, 10, len(cmap.Keys()))
21 assert.Equal(t, 10, len(cmap.Values()))
23 // Iterating Keys, checking for matching Value
24 for _, key := range cmap.Keys() {
25 val := strings.Replace(key, "key", "value", -1)
26 assert.Equal(t, val, cmap.Get(key))
29 // Test if all keys are within []Keys()
31 for i := 1; i <= 10; i++ {
32 assert.Contains(t, keys, fmt.Sprintf("key%d", i), "cmap.Keys() should contain key")
38 assert.NotEqual(t, len(keys), len(cmap.Keys()), "[]keys and []Keys() should not be equal, they are copies, one item was removed")
41 func TestContains(t *testing.T) {
44 cmap.Set("key1", "value1")
46 // Test for known values
47 assert.True(t, cmap.Has("key1"))
48 assert.Equal(t, "value1", cmap.Get("key1"))
50 // Test for unknown values
51 assert.False(t, cmap.Has("key2"))
52 assert.Nil(t, cmap.Get("key2"))