8 "github.com/anacrolix/missinggo/iter"
9 "github.com/anacrolix/missinggo/v2/bitmap"
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 BenchmarkIterBitmapsDistinct(t *testing.B) {
28 for i := 0; i < t.N; i += 1 {
29 var skip, first, second bitmap.Bitmap
33 skipCopy := skip.Copy()
35 output := iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second))
37 assert.Equal(t, []interface{}{0, 3, 2}, output)
38 assert.Equal(t, []bitmap.BitIndex{1}, skip.ToSortedSlice())
42 func TestSpewConnStats(t *testing.T) {
43 s := spew.Sdump(ConnStats{})
45 lines := strings.Count(s, "\n")
46 assert.EqualValues(t, 2+reflect.ValueOf(ConnStats{}).NumField(), lines)