2024-07-14 11:08:04 +08:00
|
|
|
package Splitstring
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
//单元测试,测试每个函数的功能是否正常
|
|
|
|
|
|
|
|
func TestSplit(t *testing.T) {
|
|
|
|
got := Split("babcbef", "b")
|
|
|
|
want := []string{"", "a", "c", "ef"}
|
|
|
|
if !reflect.DeepEqual(want, got) {
|
|
|
|
t.Errorf("want:%v, but got:%v\n", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSplit2(t *testing.T) {
|
|
|
|
got := Split("a:b:c", ":")
|
|
|
|
want := []string{"a", "b", "c"}
|
|
|
|
if !reflect.DeepEqual(want, got) {
|
|
|
|
t.Errorf("want:%v, but got:%v\n", want, got)
|
|
|
|
}
|
|
|
|
}
|
2024-07-15 21:36:11 +08:00
|
|
|
|
|
|
|
func TestSplit3(t *testing.T) {
|
|
|
|
got := Split("abcef", "bc")
|
|
|
|
want := []string{"a", "ef"}
|
|
|
|
if !reflect.DeepEqual(want, got) {
|
|
|
|
t.Fatalf("want:%v, but got:%v\n", want, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//基准测试
|
|
|
|
|
|
|
|
func BenchmarkSplit(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
Split("a:b:c:d:e:f", ":")
|
|
|
|
}
|
|
|
|
}
|