X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=misc_test.go;h=d8c0c7aab2850b0abc14c49e2f00102ac1397d16;hb=HEAD;hp=b7272151c606de170748d35d4b718ed0ac10e82f;hpb=fefeef4ee9eb72f1d245625eac03c289886121ec;p=btrtrc.git diff --git a/misc_test.go b/misc_test.go index b7272151..d8c0c7aa 100644 --- a/misc_test.go +++ b/misc_test.go @@ -5,14 +5,14 @@ import ( "strings" "testing" - "github.com/anacrolix/missinggo/bitmap" "github.com/anacrolix/missinggo/iter" + "github.com/anacrolix/missinggo/v2/bitmap" "github.com/davecgh/go-spew/spew" "github.com/stretchr/testify/assert" ) func TestTorrentOffsetRequest(t *testing.T) { - check := func(tl, ps, off int64, expected request, ok bool) { + check := func(tl, ps, off int64, expected Request, ok bool) { req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off) assert.Equal(t, _ok, ok) assert.Equal(t, req, expected) @@ -20,17 +20,23 @@ func TestTorrentOffsetRequest(t *testing.T) { check(13, 5, 0, newRequest(0, 0, 5), true) check(13, 5, 3, newRequest(0, 0, 5), true) check(13, 5, 11, newRequest(2, 0, 3), true) - check(13, 5, 13, request{}, false) + check(13, 5, 13, Request{}, false) } -func TestIterBitmapsDistinct(t *testing.T) { - var skip, first, second bitmap.Bitmap - skip.Add(1) - first.Add(1, 0, 3) - second.Add(1, 2, 0) - skipCopy := skip.Copy() - assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second))) - assert.Equal(t, []int{1}, skip.ToSortedSlice()) +func BenchmarkIterBitmapsDistinct(t *testing.B) { + t.ReportAllocs() + for i := 0; i < t.N; i += 1 { + var skip, first, second bitmap.Bitmap + skip.Add(1) + first.Add(1, 0, 3) + second.Add(1, 2, 0) + skipCopy := skip.Copy() + t.StartTimer() + output := iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second)) + t.StopTimer() + assert.Equal(t, []interface{}{0, 3, 2}, output) + assert.Equal(t, []bitmap.BitIndex{1}, skip.ToSortedSlice()) + } } func TestSpewConnStats(t *testing.T) {