github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/easy/compat_test.go (about) 1 package easy 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestFilterInt64s(t *testing.T) { 10 slice := []int64{1, 2, 3, 4, 5, 6} 11 got := FilterInt64s(slice, func(i int) bool { 12 return slice[i]%2 == 0 13 }) 14 assert.Equal(t, []int64{2, 4, 6}, got) 15 } 16 17 func TestFilterStrings(t *testing.T) { 18 slice := []string{"a", "ab", "abc", "abcd"} 19 got := FilterStrings(slice, func(i int) bool { 20 return len(slice[i]) > 2 21 }) 22 assert.Equal(t, []string{"abc", "abcd"}, got) 23 } 24 25 func TestDiffInt64s(t *testing.T) { 26 a := []int64{1, 2, 3, 4, 5} 27 b := []int64{4, 5, 6, 7, 8} 28 want1 := []int64{1, 2, 3} 29 assert.Equal(t, want1, DiffInt64s(a, b)) 30 31 want2 := []int64{6, 7, 8} 32 assert.Equal(t, want2, DiffInt64s(b, a)) 33 } 34 35 func TestDiffStrings(t *testing.T) { 36 a := []string{"1", "2", "3", "4", "5"} 37 b := []string{"4", "5", "6", "7", "8"} 38 want1 := []string{"1", "2", "3"} 39 assert.Equal(t, want1, DiffStrings(a, b)) 40 41 want2 := []string{"6", "7", "8"} 42 assert.Equal(t, want2, DiffStrings(b, a)) 43 }