-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcmap_test.go
62 lines (57 loc) · 1.22 KB
/
cmap_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmap
import (
"fmt"
"testing"
)
func TestCMap(t *testing.T) {
cmap := NewConcurrencyMap()
cmap.Set("Foo", "bar")
cmap.Set("Foo1", "bar1")
cmap.Set("Foo2", "bar2")
cmap.SetIfAbsent("Foo", "bar2")
foo, err := cmap.Get("Foo")
if err != nil {
t.Error(err)
return
}
t.Log("Foo:", foo)
t.Log("Keys:", cmap.Keys())
t.Log("Values:", cmap.Values())
t.Log("Map:", cmap.ToMap(), ",Len:", cmap.Len())
foo2, err := cmap.Remove("Foo2")
t.Log("Remove value:", foo2)
t.Log("Map:", cmap.ToMap(), ",Len:", cmap.Len())
}
func TestCMapElements(t *testing.T) {
cmap := NewConcurrencyMap()
for i := 0; i < 10; i++ {
err := cmap.Set(fmt.Sprintf("Foo_%d", i), i)
if err != nil {
t.Error(err)
return
}
}
for element := range cmap.Elements() {
t.Log("Key:", element.Key, ",Value:", element.Value)
}
}
func TestCMapSetGet(t *testing.T) {
var keys []string
keyValue := "test"
for i := 1; i <= 10; i++ {
keyValue = fmt.Sprintf("%s%d", keyValue, i)
keys = append(keys, keyValue)
}
fmt.Println(keys)
cmap := NewConcurrencyMap()
for _, v := range keys {
cmap.Set(v, v)
}
for _, v := range keys {
val, _ := cmap.Get(v)
if v != val.(string) {
t.Error("Not the desired value:", v, val)
return
}
}
}