-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_test.go
71 lines (54 loc) · 1.16 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
package lo
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
func TestKeys(t *testing.T) {
is := assert.New(t)
r1 := Keys[string, int](map[string]int{"foo": 1, "bar": 2})
sort.Sort(sort.StringSlice(r1))
is.Equal(r1, []string{"bar", "foo"})
}
func TestValues(t *testing.T) {
is := assert.New(t)
r1 := Values[string, int](map[string]int{"foo": 1, "bar": 2})
sort.Sort(sort.IntSlice(r1))
is.Equal(r1, []int{1, 2})
}
func TestEntries(t *testing.T) {
is := assert.New(t)
r1 := Entries[string, int](map[string]int{"foo": 1, "bar": 2})
is.EqualValues(r1, []Entry[string, int]{
{
Key: "foo",
Value: 1,
},
{
Key: "bar",
Value: 2,
},
})
}
func TestFromEntries(t *testing.T) {
is := assert.New(t)
r1 := FromEntries[string, int]([]Entry[string, int]{
{
Key: "foo",
Value: 1,
},
{
Key: "bar",
Value: 2,
},
})
is.Len(r1, 2)
is.Equal(r1["foo"], 1)
is.Equal(r1["bar"], 2)
}
func TestAssign(t *testing.T) {
is := assert.New(t)
result1 := Assign[string, int](map[string]int{"a": 1, "b": 2}, map[string]int{"b": 3, "c": 4})
is.Len(result1, 3)
is.Equal(result1, map[string]int{"a": 1, "b": 3, "c": 4})
}