6 "github.com/anacrolix/missinggo/bitmap"
7 "github.com/anacrolix/missinggo/iter"
8 "github.com/stretchr/testify/assert"
11 func TestTorrentOffsetRequest(t *testing.T) {
12 check := func(tl, ps, off int64, expected request, ok bool) {
13 req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off)
14 assert.Equal(t, _ok, ok)
15 assert.Equal(t, req, expected)
17 check(13, 5, 0, newRequest(0, 0, 5), true)
18 check(13, 5, 3, newRequest(0, 0, 5), true)
19 check(13, 5, 11, newRequest(2, 0, 3), true)
20 check(13, 5, 13, request{}, false)
23 func TestIterBitmapsDistinct(t *testing.T) {
24 var skip, first, second bitmap.Bitmap
28 skipCopy := skip.Copy()
29 assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second)))
30 assert.Equal(t, []int{1}, skip.ToSortedSlice())