-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrie_test.go
136 lines (132 loc) · 2.73 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package godata
import (
"testing"
)
func TestTrie(t *testing.T) {
trie := NewTrie()
trie.Insert("😄 嘿嘿嘿")
trie.Insert("😄 嘟嘟嘟")
trie.Insert("😄 你看看我是谁")
trie.Insert("😄 我tm的真帅")
t.Log("test search",trie.Search("😄"))
t.Log(trie.StartsWith("😄"))
t.Log("test search2",trie.Search("😄 嘿嘿嘿"))
for _, v := range trie.Image("😄") {
t.Log("测试结果",string(v))
}
}
func BenchmarkTrie_Insert(b *testing.B) {
trie := NewTrie()
for i := 0; i < b.N; i++ {
trie.Insert("😄 嘿嘿嘿")
}
}
func BenchmarkTrie_Search(b *testing.B) {
trie := NewTrie()
trie.Insert("😄 嘿嘿嘿")
for i := 0; i < b.N; i++ {
trie.Search("😄")
}
}
func BenchmarkTrie_StartsWith(b *testing.B) {
trie := NewTrie()
trie.Insert("😄 嘿嘿嘿")
for i := 0; i < b.N; i++ {
trie.StartsWith("😄")
}
}
func BenchmarkTrie_Image(b *testing.B) {
trie := NewTrie()
trie.Insert("1234")
trie.Insert("12345678")
trie.Insert("2468")
for i := 0; i < b.N; i++ {
trie.Image("1")
}
}
// 测试多字符长字符下的插入和搜索性能
func BenchmarkTrie_Insert2(b *testing.B) {
trie := NewTrie()
for i := 0; i < b.N; i++ {
trie.Insert(w1)
trie.Insert(w2)
trie.Insert(w3)
trie.Insert(w4)
trie.Insert(w5)
trie.Insert(w6)
trie.Insert(w7)
trie.Insert(w8)
trie.Insert(w9)
}
}
func BenchmarkTrie_Search2(b *testing.B) {
trie := NewTrie()
trie.Insert(w1)
trie.Insert(w2)
trie.Insert(w3)
trie.Insert(w4)
trie.Insert(w5)
trie.Insert(w6)
trie.Insert(w7)
trie.Insert(w8)
trie.Insert(w9)
for i := 0; i < b.N; i++ {
trie.Search("google is the greatest company arroud the world")
}
}
func BenchmarkTrie_StartsWith2(b *testing.B) {
trie := NewTrie()
trie.Insert(w1)
trie.Insert(w2)
trie.Insert(w3)
trie.Insert(w4)
trie.Insert(w5)
trie.Insert(w6)
trie.Insert(w7)
trie.Insert(w8)
trie.Insert(w9)
for i := 0; i < b.N; i++ {
trie.StartsWith("google")
}
}
func BenchmarkTrie_Image2(b *testing.B) {
trie := NewTrie()
trie.Insert(w1)
trie.Insert(w2)
trie.Insert(w3)
trie.Insert(w4)
trie.Insert(w5)
trie.Insert(w6)
trie.Insert(w7)
trie.Insert(w8)
trie.Insert(w9)
for i := 0; i < b.N; i++ {
trie.Image("google")
}
}
func TestTrie_Image(t *testing.T) {
trie := NewTrie()
trie.Insert(w1)
trie.Insert(w2)
trie.Insert(w3)
trie.Insert(w4)
trie.Insert(w5)
trie.Insert(w6)
trie.Insert(w7)
trie.Insert(w8)
trie.Insert(w9)
for _,v := range trie.Image("google is my") {
t.Log(string(v))
}
}
var (
w1 = "google is my favorite company"
w2 = "google is my love company"
w3 = "google is very cool"
w4 = "google is so good i like it"
w5 = "google is too big "
w6 = "google is the greatest company arroud the world"
w7 = "google is amazing"
w8 = "google is my lover"
w9 = "i like google"
)