-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_test.go
82 lines (78 loc) · 1.77 KB
/
map_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package kgo
import (
"testing"
)
func TestHasKey(t *testing.T) {
type args[K comparable, V any] struct {
m map[K]V
k K
}
type testCase[K comparable, V any] struct {
name string
args args[K, V]
want bool
}
tests := []testCase[string, int]{
{
name: "exists", args: args[string, int]{m: map[string]int{"k": 1}, k: "k"}, want: true,
},
{
name: "notExists", args: args[string, int]{m: map[string]int{"k": 1}, k: "kk"}, want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HasKey(tt.args.m, tt.args.k); got != tt.want {
t.Errorf("HasKey() = %v, want %v", got, tt.want)
}
})
}
}
func TestMapKeys(t *testing.T) {
type args[K comparable, V any] struct {
m map[K]V
}
type testCase[K comparable, V any] struct {
name string
args args[K, V]
want []K
}
tests := []testCase[string, int]{
{name: "string keys", args: args[string, int]{map[string]int{"a": 1, "b": 2, "c": 3}}, want: []string{"b", "a", "c"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MapKeys[string, int](tt.args.m); !ContainsAll(got, tt.want) {
t.Errorf("MapKeys() = %v, want %v", got, tt.want)
}
})
}
}
func TestMapKeysEmptyStruct(t *testing.T) {
type args[K comparable, V any] struct {
m map[K]V
}
type testCase[K comparable, V any] struct {
name string
args args[K, V]
want []K
}
tests := []testCase[int64, struct{}]{
{
name: "string keys",
args: args[int64, struct{}]{
map[int64]struct{}{
1: {},
2: {},
3: {},
},
}, want: []int64{1, 2, 3}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MapKeys[int64, struct{}](tt.args.m); !ContainsAll(got, tt.want) {
t.Errorf("MapKeys() = %v, want %v", got, tt.want)
}
})
}
}