-
Notifications
You must be signed in to change notification settings - Fork 20
/
small_table_test.go
64 lines (59 loc) · 1.38 KB
/
small_table_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
package quamina
import (
"fmt"
"testing"
"time"
)
func TestFAMergePerf(t *testing.T) {
words := readWWords(t)
patterns := make([]string, 0, len(words))
for _, word := range words {
pattern := fmt.Sprintf(`{"x": [ "%s" ] }`, string(word))
patterns = append(patterns, pattern)
}
before := time.Now()
q, _ := New()
for _, pattern := range patterns {
err := q.AddPattern(pattern, pattern)
if err != nil {
t.Error("ap: " + err.Error())
}
}
elapsed := float64(time.Since(before).Milliseconds())
for _, word := range words {
event := fmt.Sprintf(`{"x": "%s"}`, string(word))
matches, err := q.MatchesForEvent([]byte(event))
if err != nil {
t.Error("M4: " + err.Error())
}
if len(matches) != 1 {
t.Errorf("wanted 1 got %d", len(matches))
}
}
perSecond := float64(len(patterns)) / (elapsed / 1000.0)
fmt.Printf("%.2f addPatterns/second with letter patterns\n\n", perSecond)
}
func TestUnpack(t *testing.T) {
st1 := newSmallTable()
nextState := faState{
table: st1,
fieldTransitions: nil,
}
nextStep := faNext{states: []*faState{&nextState}}
st := smallTable{
ceilings: []uint8{2, 3, byte(byteCeiling)},
steps: []*faNext{nil, &nextStep, nil},
}
u := unpackTable(&st)
for i := range u {
if i == 2 {
if u[i] != &nextStep {
t.Error("Not in pos 2")
}
} else {
if u[i] != nil {
t.Errorf("Non-nil at %d", i)
}
}
}
}