MCPcopy Create free account
hub / github.com/sergi/go-diff / TestMatchBitap

Function TestMatchBitap

diffmatchpatch/match_test.go:52–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestMatchBitap(t *testing.T) {
53 type TestCase struct {
54 Name string
55
56 Text string
57 Pattern string
58 Location int
59
60 Expected int
61 }
62
63 dmp := New()
64 dmp.MatchDistance = 100
65 dmp.MatchThreshold = 0.5
66
67 for i, tc := range []TestCase{
68 {"Exact match #1", "abcdefghijk", "fgh", 5, 5},
69 {"Exact match #2", "abcdefghijk", "fgh", 0, 5},
70 {"Fuzzy match #1", "abcdefghijk", "efxhi", 0, 4},
71 {"Fuzzy match #2", "abcdefghijk", "cdefxyhijk", 5, 2},
72 {"Fuzzy match #3", "abcdefghijk", "bxy", 1, -1},
73 {"Overflow", "123456789xx0", "3456789x0", 2, 2},
74 {"Before start match", "abcdef", "xxabc", 4, 0},
75 {"Beyond end match", "abcdef", "defyy", 4, 3},
76 {"Oversized pattern", "abcdef", "xabcdefy", 0, 0},
77 } {
78 actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
79 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
80 }
81
82 dmp.MatchThreshold = 0.4
83
84 for i, tc := range []TestCase{
85 {"Threshold #1", "abcdefghijk", "efxyhi", 1, 4},
86 } {
87 actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
88 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
89 }
90
91 dmp.MatchThreshold = 0.3
92
93 for i, tc := range []TestCase{
94 {"Threshold #2", "abcdefghijk", "efxyhi", 1, -1},
95 } {
96 actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
97 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
98 }
99
100 dmp.MatchThreshold = 0.0
101
102 for i, tc := range []TestCase{
103 {"Threshold #3", "abcdefghijk", "bcdef", 1, 1},
104 } {
105 actual := dmp.MatchBitap(tc.Text, tc.Pattern, tc.Location)
106 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
107 }
108
109 dmp.MatchThreshold = 0.5

Callers

nothing calls this directly

Calls 2

NewFunction · 0.85
MatchBitapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…