...

Source file src/github.com/thoas/go-funk/intersection_test.go

Documentation: github.com/thoas/go-funk

     1  package funk
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestIntersect(t *testing.T) {
    10  	is := assert.New(t)
    11  
    12  	r := Intersect([]int{1, 2, 3, 4}, []int{2, 4, 6})
    13  	is.Equal(r, []int{2, 4})
    14  
    15  	r = Intersect([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
    16  	is.Equal(r, []string{"foo", "bar"})
    17  
    18  	r = Intersect([]string{"foo", "bar"}, []string{"foo", "bar", "hello", "bar"})
    19  	is.Equal(r, []string{"foo", "bar", "bar"})
    20  }
    21  
    22  func TestIntersectString(t *testing.T) {
    23  	is := assert.New(t)
    24  
    25  	r := IntersectString([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
    26  	is.Equal(r, []string{"foo", "bar"})
    27  }
    28  
    29  func TestDifference(t *testing.T) {
    30  	is := assert.New(t)
    31  
    32  	r1, r2 := Difference([]int{1, 2, 3, 4}, []int{2, 4, 6})
    33  	is.Equal(r1, []int{1, 3})
    34  	is.Equal(r2, []int{6})
    35  
    36  	r1, r2 = Difference([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
    37  	is.Equal(r1, []string{"hello"})
    38  	is.Equal(r2, []string{})
    39  }
    40  
    41  func TestDifferenceString(t *testing.T) {
    42  	is := assert.New(t)
    43  
    44  	r1, r2 := DifferenceString([]string{"foo", "bar", "hello", "bar"}, []string{"foo", "bar"})
    45  	is.Equal(r1, []string{"hello"})
    46  	is.Equal(r2, []string{})
    47  }
    48  
    49  func TestDifferenceInt64(t *testing.T) {
    50  	is := assert.New(t)
    51  
    52  	r1, r2 := DifferenceInt64([]int64{1, 2, 3, 4}, []int64{4, 6})
    53  	is.Equal(r1, []int64{1, 2, 3})
    54  	is.Equal(r2, []int64{6})
    55  }
    56  

View as plain text