-
Notifications
You must be signed in to change notification settings - Fork 159
/
sfx_tree_test.go
53 lines (40 loc) · 1.49 KB
/
sfx_tree_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
package main
import (
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_Suffix_Tree(t *testing.T) {
root := newSuffixTreeRoot()
Convey("Google should not be found", t, func() {
root.insert("cn", "114.114.114.114")
root.sinsert([]string{"baidu", "cn"}, "166.111.8.28")
root.sinsert([]string{"sina", "cn"}, "114.114.114.114")
v, found := root.search(strings.Split("google.com", "."))
So(found, ShouldEqual, false)
v, found = root.search(strings.Split("baidu.cn", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "166.111.8.28")
})
Convey("Google should be found", t, func() {
root.sinsert(strings.Split("com", "."), "")
root.sinsert(strings.Split("google.com", "."), "8.8.8.8")
root.sinsert(strings.Split("twitter.com", "."), "8.8.8.8")
root.sinsert(strings.Split("scholar.google.com", "."), "208.67.222.222")
v, found := root.search(strings.Split("google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("www.google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("scholar.google.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "208.67.222.222")
v, found = root.search(strings.Split("twitter.com", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "8.8.8.8")
v, found = root.search(strings.Split("baidu.cn", "."))
So(found, ShouldEqual, true)
So(v, ShouldEqual, "166.111.8.28")
})
}