-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex_matching_test.go
60 lines (53 loc) · 1.26 KB
/
regex_matching_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package problem0010
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
Str string
Pat string
Expected bool
}
/*
Constraints:
1 <= s.length <= 20
1 <= p.length <= 30
s contains only lowercase English letters.
p contains only lowercase English letters, '.', and '*'.
It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
*/
var Results = []Result{
{"aa", "a", false},
{"aa", "aa", true},
{"aab", "aac", false},
{"aabca", "aabca", true},
{"aa", "a*", true},
{"ab", ".b", true},
{"ab", ".*", true},
{"a", "ab*", true},
{"aaaa", "aa*", true},
{"abc", "a", false},
{"abbd", "ab*d", true},
{"acd", "ab*d", false},
{"abbcccd", "acd", false},
{"a", "aaa*", false},
{"abcd", "a.*d", true},
{"abcde", "a.*d", false},
{"abcdef", "a.c.e.", true},
{"acdef", "a.c.e.", false},
{"aaba", "ab*a*c*a", false},
{"xy", "xa*b*c*y", true},
{"xay", "xa*b*c*y", true},
{"xaby", "xa*b*c*y", true},
{"xby", "xa*b*c*y", true},
{"xbay", "xa*b*c*y", false},
}
func TestRegexMatch(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := isMatch(res.Str, res.Pat)
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}