-
Notifications
You must be signed in to change notification settings - Fork 1
/
map_enumerable_test.go
71 lines (53 loc) · 1.48 KB
/
map_enumerable_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
package enu_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/yuemori/enu"
)
func TestMapToSlice(t *testing.T) {
t.Parallel()
is := assert.New(t)
r := enu.FromMap(map[int]string{1: "foo", 2: "bar", 3: "baz"}).ToSlice()
is.ElementsMatch([]enu.KeyValuePair[int, string]{
{Key: 1, Value: "foo"},
{Key: 2, Value: "bar"},
{Key: 3, Value: "baz"},
}, r)
}
func TestMapToCount(t *testing.T) {
t.Parallel()
is := assert.New(t)
r := enu.FromMap(map[int]string{1: "foo", 2: "bar", 3: "baz"}).Count()
is.Equal(3, r)
}
func TestMapFilter(t *testing.T) {
t.Parallel()
is := assert.New(t)
r := enu.FromMap(map[int]string{1: "foo", 2: "bar", 3: "baz", 4: "boo"}).Filter(func(kv enu.KeyValuePair[int, string], _ int) bool {
return kv.Key%2 == 0
}).ToMap()
is.Equal(map[int]string{2: "bar", 4: "boo"}, r)
}
func TestMapKeys(t *testing.T) {
t.Parallel()
is := assert.New(t)
r := enu.FromMap(map[int]string{1: "foo", 2: "bar", 3: "baz"}).Keys()
is.ElementsMatch([]int{1, 2, 3}, r)
}
func TestMapValues(t *testing.T) {
t.Parallel()
is := assert.New(t)
r := enu.FromMap(map[int]string{1: "foo", 2: "bar", 3: "baz"}).Values()
is.ElementsMatch([]string{"foo", "bar", "baz"}, r)
}
func TestEnumeratorToMap(t *testing.T) {
t.Parallel()
is := assert.New(t)
e := enu.From([]enu.KeyValuePair[int, string]{
{Key: 1, Value: "foo"},
{Key: 2, Value: "bar"},
{Key: 3, Value: "baz"},
})
r := enu.ToMap[int, string](e).Keys()
is.ElementsMatch([]int{1, 2, 3}, r)
}