8 "github.com/anacrolix/missinggo/bitmap"
9 "github.com/anacrolix/missinggo/iter"
10 "github.com/davecgh/go-spew/spew"
11 "github.com/stretchr/testify/assert"
14 func TestTorrentOffsetRequest(t *testing.T) {
15 check := func(tl, ps, off int64, expected request, ok bool) {
16 req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off)
17 assert.Equal(t, _ok, ok)
18 assert.Equal(t, req, expected)
20 check(13, 5, 0, newRequest(0, 0, 5), true)
21 check(13, 5, 3, newRequest(0, 0, 5), true)
22 check(13, 5, 11, newRequest(2, 0, 3), true)
23 check(13, 5, 13, request{}, false)
26 func TestIterBitmapsDistinct(t *testing.T) {
27 var skip, first, second bitmap.Bitmap
31 skipCopy := skip.Copy()
32 assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second)))
33 assert.Equal(t, []int{1}, skip.ToSortedSlice())
36 func TestSpewConnStats(t *testing.T) {
37 s := spew.Sdump(ConnStats{})
39 lines := strings.Count(s, "\n")
40 assert.EqualValues(t, 2+reflect.ValueOf(ConnStats{}).NumField(), lines)