-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorderedmap_test.go
More file actions
46 lines (41 loc) · 865 Bytes
/
orderedmap_test.go
File metadata and controls
46 lines (41 loc) · 865 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
package orderedmap
import (
"testing"
)
func TestBasicSetGetLen(t *testing.T) {
testcases := []struct {
k string
v int
expectLen int
}{
{k: "foo", v: 1, expectLen: 1},
{k: "bar", v: 2, expectLen: 2},
{k: "hey", v: 3, expectLen: 3},
{k: "foo", v: 9, expectLen: 3}, // reset
}
m := New[string, int]()
for _, tt := range testcases {
m.Set(tt.k, tt.v)
want := tt.v
got, ok := m.Get(tt.k)
if !ok || got != want {
t.Errorf("got %v, want %v, ok = %v", got, want, ok)
}
if l := m.Len(); l != tt.expectLen {
t.Errorf("got Len() = %v, expected %v", l, tt.expectLen)
}
}
}
func BenchmarkSet(b *testing.B) {
m := New[string, int]()
for i := 0; i < b.N; i++ {
m.Set("foo", 1)
}
}
func BenchmarkGet(b *testing.B) {
m := New[string, int]()
m.Set("foo", 1)
for i := 0; i < b.N; i++ {
_, _ = m.Get("foo")
}
}