...
1 package match
2
3 import (
4 "reflect"
5 "testing"
6 )
7
8 func TestPrefixIndex(t *testing.T) {
9 for id, test := range []struct {
10 prefix string
11 fixture string
12 index int
13 segments []int
14 }{
15 {
16 "ab",
17 "abc",
18 0,
19 []int{2, 3},
20 },
21 {
22 "ab",
23 "fffabfff",
24 3,
25 []int{2, 3, 4, 5},
26 },
27 } {
28 p := NewPrefix(test.prefix)
29 index, segments := p.Index(test.fixture)
30 if index != test.index {
31 t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index)
32 }
33 if !reflect.DeepEqual(segments, test.segments) {
34 t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments)
35 }
36 }
37 }
38
39 func BenchmarkIndexPrefix(b *testing.B) {
40 m := NewPrefix("qew")
41
42 for i := 0; i < b.N; i++ {
43 _, s := m.Index(bench_pattern)
44 releaseSegments(s)
45 }
46 }
47
48 func BenchmarkIndexPrefixParallel(b *testing.B) {
49 m := NewPrefix("qew")
50
51 b.RunParallel(func(pb *testing.PB) {
52 for pb.Next() {
53 _, s := m.Index(bench_pattern)
54 releaseSegments(s)
55 }
56 })
57 }
58
View as plain text