github.com/searKing/golang/go@v1.2.117/exp/slices/intersect_test.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package slices_test 6 7 import ( 8 "fmt" 9 "slices" 10 "testing" 11 12 slices_ "github.com/searKing/golang/go/exp/slices" 13 ) 14 15 var intersectTests = []struct { 16 s1 []int 17 s2 []int 18 want []int 19 }{ 20 { 21 []int{}, 22 []int{}, 23 []int{}, 24 }, 25 { 26 []int{1, 2, 3}, 27 []int{-1, -2, -3}, 28 []int{}, 29 }, 30 { 31 []int{1, 2, 3}, 32 []int{1, -2, -3}, 33 []int{1}, 34 }, 35 { 36 []int{1, 2, 3}, 37 []int{1, -2, 3}, 38 []int{1, 3}, 39 }, 40 { 41 []int{3, 2, 1}, 42 []int{-3, -2, -1}, 43 []int{}, 44 }, 45 } 46 47 func TestIntersectFunc(t *testing.T) { 48 for _, tt := range intersectTests { 49 t.Run(fmt.Sprintf("slices_.Intersect(%v, %v, equal[int])", tt.s1, tt.s2), func(t *testing.T) { 50 { 51 got := slices_.IntersectFunc(tt.s1, tt.s2, equal[int]) 52 if !slices.Equal(got, tt.want) { 53 t.Errorf("slices_.Intersect(%v, %v, equal[int]) = %v, want %v", tt.s1, tt.s2, got, tt.want) 54 } 55 } 56 }) 57 } 58 } 59 60 func TestIntersect(t *testing.T) { 61 for _, tt := range intersectTests { 62 t.Run(fmt.Sprintf("slices_.Intersect(%v, %v)", tt.s1, tt.s2), func(t *testing.T) { 63 { 64 got := slices_.Intersect(tt.s1, tt.s2) 65 if !slices.Equal(got, tt.want) { 66 t.Errorf("slices_.Intersect(%v, %v) = %v, want %v", tt.s1, tt.s2, got, tt.want) 67 } 68 } 69 }) 70 } 71 }