File: intersection_test.go

package info (click to toggle)
golang-github-thoas-go-funk 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 504 kB
  • sloc: makefile: 10
file content (59 lines) | stat: -rw-r--r-- 1,575 bytes parent folder | download
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})
}