-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie_test.go
45 lines (39 loc) · 937 Bytes
/
trie_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
package problem0208
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
Commands []string
Values []string
Expected []bool
}
var Results = []Result{
{
Commands: []string{"Trie", "insert", "search", "search", "startsWith", "insert", "search"},
Values: []string{"", "apple", "apple", "app", "app", "app", "app"},
Expected: []bool{false, false, true, false, true, false, true},
},
}
func TestMakeTrie(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := make([]bool, len(want))
var trie Trie
for i := range res.Commands {
switch res.Commands[i] {
case "Trie":
trie = Constructor()
case "insert":
trie.Insert(res.Values[i])
case "search":
got[i] = trie.Search(res.Values[i])
case "startsWith":
got[i] = trie.StartsWith(res.Values[i])
}
}
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}