Files
Go-tool/util/stringMatch/SundayMatch_test.go
T
Huangzj dc5d924a2c feat(Go-Tool):
2021/03/02: 新增字符串匹配 暴力匹配、KMP匹配、SunDay匹配算法
            2021/03/02: 修复Rand包随机获取方法
2021-03-02 13:33:07 +08:00

34 lines
518 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author : huangzj
* @Time : 2021/3/2 11:21
* @Description
*/
package stringMatch
import (
"fmt"
"testing"
)
func TestSundayMatch(t *testing.T) {
s := "abcbvxs"
m := "bcb"
showResult2(s, m)
s = "abcbvxs"
m = "bx"
showResult2(s, m)
s = "abcbvxssdaadsad"
m = "cbvxssdaa"
showResult2(s, m)
}
func showResult2(s, m string) {
i := SundayMatch(s, m)
if i == -1 {
fmt.Println("未找到对应字符串")
} else {
fmt.Println(fmt.Sprintf("匹配到的字符串是:%v", s[i:len(m)+i]))
}
}