forked from bytewayio/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcurrent_map_test.go
More file actions
47 lines (38 loc) · 829 Bytes
/
concurrent_map_test.go
File metadata and controls
47 lines (38 loc) · 829 Bytes
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
package cypress
import (
"testing"
)
func TestConcurrentMap(t *testing.T) {
m := NewConcurrentMap()
m.Put("key1", "value1")
m.Put("key2", 100)
v1, ok := m.Get("key1")
if !ok {
t.Error("key1 must be there")
return
}
if v1.(string) != "value1" {
t.Error("value for key1 expected to be value1 but got", v1.(string))
}
v2, ok := m.Get("key2")
if !ok {
t.Error("key2 must be there")
return
}
if v2.(int) != 100 {
t.Error("value for key2 expected to be 100 but got", v2.(int))
}
v3 := m.GetOrCompute("key3", func() interface{} { return 400 })
if v3 != 400 {
t.Error("unexpected value for v3", v3, "expected 400")
return
}
v4, ok := m.Get("key3")
if !ok {
t.Error("key3 must be there")
return
}
if v4.(int) != 400 {
t.Error("value for key3 expected to be 400 but got", v4.(int))
}
}