-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_search_test.go
43 lines (37 loc) · 938 Bytes
/
add_search_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
package problem0211
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
Commands []string
Values []string
Expected []bool
}
var Results = []Result{
{
Commands: []string{"WordDictionary", "addWord", "addWord", "addWord", "search", "search", "search", "search"},
Values: []string{"", "bad", "dad", "mad", "pad", "bad", ".ad", "b.."},
Expected: []bool{false, false, false, false, false, true, true, true},
},
}
func TestMakeTrie(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := make([]bool, len(want))
var wordDict WordDictionary
for i := range res.Commands {
switch res.Commands[i] {
case "WordDictionary":
wordDict = Constructor()
case "addWord":
wordDict.AddWord(res.Values[i])
case "search":
got[i] = wordDict.Search(res.Values[i])
}
}
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}