1package match
2
3import (
4	"reflect"
5	"testing"
6)
7
8func TestMaxIndex(t *testing.T) {
9	for id, test := range []struct {
10		limit    int
11		fixture  string
12		index    int
13		segments []int
14	}{
15		{
16			3,
17			"abc",
18			0,
19			[]int{0, 1, 2, 3},
20		},
21		{
22			3,
23			"abcdef",
24			0,
25			[]int{0, 1, 2, 3},
26		},
27	} {
28		p := NewMax(test.limit)
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
39func BenchmarkIndexMax(b *testing.B) {
40	m := NewMax(10)
41
42	for i := 0; i < b.N; i++ {
43		_, s := m.Index(bench_pattern)
44		releaseSegments(s)
45	}
46}
47
48func BenchmarkIndexMaxParallel(b *testing.B) {
49	m := NewMax(10)
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