-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap_test.go
90 lines (74 loc) · 1.33 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
83
84
85
86
87
88
89
90
package maps
import (
"collections/slices"
"testing"
"github.com/stretchr/testify/assert"
)
func TestKeysValues(t *testing.T) {
m := map[int]string{
1: "one",
2: "two",
3: "three",
}
assert.ElementsMatch(t, []int{1, 2, 3}, slices.YieldAll[[]int](Keys(m)))
assert.ElementsMatch(t, []string{"one", "two", "three"}, slices.YieldAll[[]string](Values(m)))
}
func TestUnion(t *testing.T) {
a := map[int]string{
1: "one",
2: "two",
3: "three",
}
b := map[int]string{
3: "threeb",
4: "four",
5: "five",
}
expected := map[int]string{
1: "one",
2: "two",
3: "threeb",
4: "four",
5: "five",
}
assert.Equal(t, expected, Union(a, b))
assert.NotEqual(t, expected, a)
inplace := UnionInPlace(a, b)
assert.Equal(t, expected, inplace)
assert.Equal(t, inplace, a)
}
func TestIntersect(t *testing.T) {
a := map[int]string{
1: "one",
2: "two",
3: "three",
}
b := map[int]string{
3: "threeb",
4: "four",
5: "five",
1: "one",
}
expected := map[int]string{
1: "one",
3: "threeb",
}
assert.Equal(t, expected, Intersect(a, b))
}
func TestDifference(t *testing.T) {
a := map[int]string{
1: "one",
2: "two",
3: "three",
}
b := map[int]string{
3: "threeb",
4: "four",
5: "five",
1: "one",
}
expected := map[int]string{
2: "two",
}
assert.Equal(t, expected, Difference(a, b))
}