MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestLHorspool

Function TestLHorspool

strings/horspool/horspool_test.go:10–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8import "fmt"
9
10func TestLHorspool(t *testing.T) {
11 testCases := []struct {
12 input string
13 pattern string
14 expected int
15 }{
16 {"aaaaXaaa", "X", 4},
17 {"aaaaXXaa", "XX", 4},
18 {"Xaaab", "X", 0},
19 {"XYaab", "XY", 0},
20 {"abcefghXYZ", "XYZ", 7},
21 {"abcefgh€YZ⌘", "€YZ", 7},
22 {"⌘bcefgh€YZ⌘", "€YZ", 7},
23 {"abc", "abc", 0},
24 {"", "", 0},
25 {"a", "", 0},
26 {"a", "a", 0},
27 {"aa", "a", 0},
28 {"aa", "aa", 0},
29 }
30 for _, tc := range testCases {
31 t.Run(fmt.Sprint("test with ", tc.input, " ", tc.pattern), func(t *testing.T) {
32 result, curError := Horspool(tc.input, tc.pattern)
33 if curError != nil {
34 t.Fatalf("Got unexpected error")
35 }
36 if tc.expected != result {
37 t.Fatalf("expected %d, got %d", tc.expected, result)
38 }
39 })
40 }
41}
42
43func TestLHorspoolNotExisintPattern(t *testing.T) {
44 testCases := []struct {

Callers

nothing calls this directly

Calls 1

HorspoolFunction · 0.85

Tested by

no test coverage detected