github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/test/slice_test.go (about) 1 package test 2 3 import ( 4 "testing" 5 6 "github.com/isyscore/isc-gobase/isc" 7 ) 8 9 type sliceTestStruct struct { 10 Name string 11 Age int 12 } 13 14 func TestSliceDistinctTo(t *testing.T) { 15 s1 := sliceTestStruct{ 16 Name: "库陈胜", 17 Age: 30, 18 } 19 s2 := sliceTestStruct{ 20 Name: "酷达舒", 21 Age: 29, 22 } 23 s3 := sliceTestStruct{ 24 Name: "库陈胜", 25 Age: 28, 26 } 27 list := []sliceTestStruct{s1, s2, s3} 28 l := isc.SliceDistinctTo(list, func(s sliceTestStruct) string { 29 return s.Name 30 }) 31 t.Logf("%s\n", isc.ToString(l)) 32 b := isc.SliceContains(list, func(s sliceTestStruct) string { 33 return s.Name 34 }, "库陈胜") 35 t.Logf("%v\n", b) 36 }