/
main.go
executable file
·68 lines (56 loc) · 1.55 KB
/
main.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
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/gladmo/leetcode/leet"
"github.com/gladmo/leetcode/questions/serial/medium/211/golang/solution"
)
func main() {
testNamePre := "word-dictionary"
testLog := leet.NewTestLog(6)
defer testLog.Render()
idx := 1
trie := solution.Constructor()
got := trie.Search("a")
want := false
if got != want {
testLog.Fail(idx, fmt.Sprintf("%s-%v", testNamePre, want), fmt.Sprintf("want: %v, got %v.", want, got))
} else {
testLog.Pass(idx, fmt.Sprintf("%s-%v", testNamePre, want))
}
idx++
trie.AddWord("bad")
trie.AddWord("dad")
trie.AddWord("mad")
got = trie.Search("pad")
want = false
if got != want {
testLog.Fail(idx, fmt.Sprintf("%s-%v", testNamePre, want), fmt.Sprintf("want: %v, got %v.", want, got))
} else {
testLog.Pass(idx, fmt.Sprintf("%s-%v", testNamePre, want))
}
idx++
got = trie.Search("bad")
want = true
if got != want {
testLog.Fail(idx, fmt.Sprintf("%s-%v", testNamePre, want), fmt.Sprintf("want: %v, got %v.", want, got))
} else {
testLog.Pass(idx, fmt.Sprintf("%s-%v", testNamePre, want))
}
idx++
got = trie.Search(".ad")
want = true
if got != want {
testLog.Fail(idx, fmt.Sprintf("%s-%v", testNamePre, want), fmt.Sprintf("want: %v, got %v.", want, got))
} else {
testLog.Pass(idx, fmt.Sprintf("%s-%v", testNamePre, want))
}
idx++
got = trie.Search("b..")
want = true
if got != want {
testLog.Fail(idx, fmt.Sprintf("%s-%v", testNamePre, want), fmt.Sprintf("want: %v, got %v.", want, got))
} else {
testLog.Pass(idx, fmt.Sprintf("%s-%v", testNamePre, want))
}
idx++
}