course/test/groupchild_spilt_string_tes...

31 lines
758 B
Go

package Splitstring
import (
"reflect"
"testing"
)
//子测试
func TestGroupChildSplit(t *testing.T) {
type testCase struct {
str string
sep string
want []string
}
testGroup := map[string]testCase{
"case1": {str: "babcbef", sep: "b", want: []string{"", "a", "c", "ef"}},
"case2": {str: "a:b:c", sep: ":", want: []string{"a", "b", "c"}},
"case3": {str: "abcef", sep: "bc", want: []string{"a", "ef"}},
"case4": {str: "沙河有沙又有河", sep: "有", want: []string{"沙河", "沙又", "河"}},
}
for name, testcase := range testGroup {
t.Run(name, func(t *testing.T) {
got := Split(testcase.str, testcase.sep)
if !reflect.DeepEqual(got, testcase.want) {
t.Errorf("got:%v, want:%v", got, testcase.want)
}
})
}
}