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