Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit a96fb51

Browse files
committed
shed: failing test for Index.Offset
1 parent d5387d9 commit a96fb51

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

shed/index_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,3 +1104,60 @@ func TestIndex_HasMulti(t *testing.T) {
11041104
t.Errorf("got %v, want %v", got, want)
11051105
}
11061106
}
1107+
1108+
func generateItems(n int) []Item {
1109+
items := make([]Item, 0, n)
1110+
1111+
for i := 0; i < n; i++ {
1112+
items = append(items, Item{
1113+
Address: []byte(fmt.Sprintf("hash%03d", i)),
1114+
Data: []byte(fmt.Sprintf("data%06d", i)),
1115+
StoreTimestamp: time.Now().UnixNano(),
1116+
})
1117+
}
1118+
1119+
return items
1120+
}
1121+
1122+
func TestIndexOffset(t *testing.T) {
1123+
t.Parallel()
1124+
1125+
db, cleanupFunc := newTestDB(t)
1126+
defer cleanupFunc()
1127+
1128+
index, err := db.NewIndex("retrieval", retrievalIndexFuncs)
1129+
if err != nil {
1130+
t.Fatal(err)
1131+
}
1132+
1133+
items := generateItems(100)
1134+
for _, item := range items {
1135+
index.Put(item)
1136+
}
1137+
1138+
tests := []struct {
1139+
start, offset int
1140+
}{
1141+
{0, 0},
1142+
{0, 1},
1143+
{0, 50},
1144+
{44, 0},
1145+
{10, 10},
1146+
{0, len(items) - 1},
1147+
{10, -3},
1148+
{10, -10},
1149+
{len(items) - 1, 0},
1150+
{len(items) - 2, 1},
1151+
}
1152+
1153+
for _, tc := range tests {
1154+
t.Run(fmt.Sprintf("%d_%d", tc.start, tc.offset), func(tt *testing.T) {
1155+
item, err := index.Offset(&items[tc.start], int64(tc.offset))
1156+
if err != nil {
1157+
tt.Error(err)
1158+
}
1159+
checkItem(tt, item, items[tc.start+tc.offset])
1160+
})
1161+
}
1162+
1163+
}

0 commit comments

Comments
 (0)