forked from thoas/go-funk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intersection_test.go
59 lines (43 loc) · 1.54 KB
/
intersection_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
package funk
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIntersect(t *testing.T) {
is := assert.New(t)
r := Intersect([]int{1, 2, 3, 4}, []int{2, 4, 6})
is.Equal(r, []int{2, 4})
r = Intersect([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
is.Equal(r, []string{"foo", "bar"})
r = Intersect([]string{"foo", "bar"}, []string{"foo", "bar", "hello", "bar"})
is.Equal(r, []string{"foo", "bar", "bar"})
}
func TestIntersectString(t *testing.T) {
is := assert.New(t)
r := IntersectString([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
is.Equal(r, []string{"foo", "bar"})
}
func TestDifference(t *testing.T) {
is := assert.New(t)
r1, r2 := Difference([]int{1, 2, 3, 4}, []int{2, 4, 6})
is.Equal(r1, []int{1, 3})
is.Equal(r2, []int{6})
r1, r2 = Difference([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
is.Equal(r1, []string{"hello"})
is.Equal(r2, []string{})
r1, r2 = Difference(map[string]string{"foo": "bar", "hello": "baz"}, map[string]string{"foo": "bar", "bar": "baz"})
is.Equal(r1, map[string]string{"hello": "baz"})
is.Equal(r2, map[string]string{"bar": "baz"})
}
func TestDifferenceString(t *testing.T) {
is := assert.New(t)
r1, r2 := DifferenceString([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
is.Equal(r1, []string{"hello"})
is.Equal(r2, []string{})
}
func TestDifferenceInt64(t *testing.T) {
is := assert.New(t)
r1, r2 := DifferenceInt64([]int64{1, 2, 3, 4}, []int64{4, 6})
is.Equal(r1, []int64{1, 2, 3})
is.Equal(r2, []int64{6})
}