]> Sergey Matveev's repositories - btrtrc.git/blobdiff - misc_test.go
Drop support for go 1.20
[btrtrc.git] / misc_test.go
index a8bd10f44e9c808941723a9e1810e219add34d18..d8c0c7aab2850b0abc14c49e2f00102ac1397d16 100644 (file)
@@ -1,15 +1,47 @@
 package torrent
 
-import . "gopkg.in/check.v1"
+import (
+       "reflect"
+       "strings"
+       "testing"
 
-func (suite) TestTorrentOffsetRequest(c *C) {
-       check := func(tl, ps, off int64, expected request, ok bool) {
-               req, _ok := torrentOffsetRequest(tl, ps, chunkSize, off)
-               c.Check(_ok, Equals, ok)
-               c.Check(req, Equals, expected)
+       "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) {
+               req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off)
+               assert.Equal(t, _ok, ok)
+               assert.Equal(t, req, expected)
        }
        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 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) {
+       s := spew.Sdump(ConnStats{})
+       t.Logf("\n%s", s)
+       lines := strings.Count(s, "\n")
+       assert.EqualValues(t, 2+reflect.ValueOf(ConnStats{}).NumField(), lines)
 }