-
Notifications
You must be signed in to change notification settings - Fork 2
/
findSubstring_test.go
41 lines (37 loc) · 1.21 KB
/
findSubstring_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package substringwithconcatenationofallwords
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_findSubstring(t *testing.T) {
assert.Equal(t, []int{}, findSubstring("", []string{""}))
assert.Equal(t, []int{0}, findSubstring("a", []string{"a"}))
assert.Equal(t, []int{1}, findSubstring("acaacc",
[]string{"ca", "ac"}))
assert.Equal(t, []int{1}, findSubstring("ababaab",
[]string{"ab", "ba", "ba"}))
assert.Equal(t, []int{1, 3}, findSubstring("abaababbaba",
[]string{"ab", "ba", "ab", "ba"}))
assert.Equal(t, []int{0, 2, 1}, findSubstring("aaaaaaaa",
[]string{"aa", "aa", "aa"}))
assert.Equal(t, []int{0, 9}, findSubstring("barfoothefoobarman",
[]string{"foo", "bar"}))
assert.Equal(t, []int{8}, findSubstring("wordgoodgoodgoodbestword",
[]string{"word", "good", "best", "good"}))
assert.Equal(t, []int{6, 9, 12}, findSubstring("barfoofoobarthefoobarman",
[]string{"bar", "foo", "the"}))
}
func Benchmark_findSubstring(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
findSubstring("", []string{""})
findSubstring("acaacc",
[]string{"ca", "ac"})
findSubstring("ababaab",
[]string{"ab", "ba", "ba"})
}
})
}