-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuilder_test.go
56 lines (47 loc) · 1.01 KB
/
builder_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
package ahocorasick
import (
"fmt"
"io/ioutil"
"testing"
)
func TestLoadStrings(t *testing.T) {
tb := NewTrieBuilder()
if err := tb.LoadStrings("doesnt-exists.txt"); err == nil {
t.Errorf("should fail")
}
if err := tb.LoadStrings("./test_data/strings.txt"); err != nil {
t.Error(err)
}
tr := tb.Build()
ibsen, err := ioutil.ReadFile("./test_data/Ibsen.txt")
if err != nil {
t.Error(err)
}
expected := 697
ms := tr.Match(ibsen)
if len(ms) != expected {
for _, m := range ms {
fmt.Println(m)
}
t.Errorf("expected %d matches, got %d\n", expected, len(ms))
}
}
func TestLoadPatterns(t *testing.T) {
tb := NewTrieBuilder()
if err := tb.LoadPatterns("./test_data/patterns.txt"); err != nil {
t.Error(err)
}
tr := tb.Build()
ibsen, err := ioutil.ReadFile("./test_data/Ibsen.txt")
if err != nil {
t.Error(err)
}
expected := 697
ms := tr.Match(ibsen)
if len(ms) != expected {
for _, m := range ms {
fmt.Println(m)
}
t.Errorf("expected %d matches, got %d\n", expected, len(ms))
}
}