6 "github.com/stretchr/testify/assert"
9 func LengthIterFromSlice(ls []Length) LengthIter {
10 return func() (Length, bool) {
22 type ScanCallbackValue struct {
27 type collectExtents []ScanCallbackValue
29 func (me *collectExtents) scanCallback(i int, e Extent) bool {
30 *me = append(*me, ScanCallbackValue{
37 type newLocater func(LengthIter) Locater
39 func assertLocate(t *testing.T, nl newLocater, ls []Length, needle Extent, firstExpectedIndex int, expectedExtents []Extent) {
40 var actual collectExtents
41 var expected collectExtents
42 for i, e := range expectedExtents {
43 expected.scanCallback(firstExpectedIndex+i, e)
45 nl(LengthIterFromSlice(ls))(needle, actual.scanCallback)
46 assert.EqualValues(t, expected, actual)
49 func testLocater(t *testing.T, newLocater newLocater) {
50 assertLocate(t, newLocater,
51 []Length{1, 0, 2, 0, 3},
54 []Extent{{1, 1}, {0, 0}, {0, 1}})
55 assertLocate(t, newLocater,
56 []Length{1, 0, 2, 0, 3},
60 assertLocate(t, newLocater,
61 []Length{1652, 1514, 1554, 1618, 1546, 129241752, 1537}, // 128737588
71 assertLocate(t, newLocater,
72 []Length{1652, 1514, 1554, 1618, 1546, 129241752, 1537, 1536, 1551}, // 128737588
73 Extent{129236992, 16384},
82 func TestScan(t *testing.T) {
83 testLocater(t, LocaterFromLengthIter)
86 func TestIndex(t *testing.T) {
87 testLocater(t, func(li LengthIter) Locater {
88 return NewIndex(li).Locate