forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regular_expressions_test.go
47 lines (40 loc) · 1.08 KB
/
regular_expressions_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
package recursion
import (
"testing"
)
/*
TestRegularExpressions tests solution(s) with the following signature and problem description:
func IsRegularExpressionMatch(input, pattern string) bool
Given an input and a regular expression pattern where
`.` denotes to any character
`*` denotes to zero or more of the proceeding characters
Write a recursive function to return true if the input matches the pattern and false otherwise.
*/
func TestRegularExpressions(t *testing.T) {
tests := []struct {
input, pattern string
match bool
}{
{"", "", true},
{"", "*", false},
{"a", "", false},
{"a", ".", true},
{"a", "*", false},
{"aa", "*", false},
{"aa", "*a", false},
{"aa", "a*", true},
{"aa", ".", false},
{"ab", ".", false},
{"ad", "d", false},
{"ad", ".d", true},
{"da", "*d", false},
{"da", ".*", true},
{"ad", "d", false},
{"abdef", "*d*", false},
}
for i, test := range tests {
if got := IsRegularExpressionMatch(test.input, test.pattern); got != test.match {
t.Errorf("Failed test case %d. Want %t got %t", i, test.match, got)
}
}
}