github.com/anacrolix/torrent@v1.61.0/misc_test.go (about)

     1  package torrent
     2  
     3  import (
     4  	"reflect"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/davecgh/go-spew/spew"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestTorrentOffsetRequest(t *testing.T) {
    13  	check := func(tl, ps, off int64, expected Request, ok bool) {
    14  		req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off)
    15  		assert.Equal(t, _ok, ok)
    16  		assert.Equal(t, req, expected)
    17  	}
    18  	check(13, 5, 0, newRequest(0, 0, 5), true)
    19  	check(13, 5, 3, newRequest(0, 0, 5), true)
    20  	check(13, 5, 11, newRequest(2, 0, 3), true)
    21  	check(13, 5, 13, Request{}, false)
    22  }
    23  
    24  func TestSpewConnStats(t *testing.T) {
    25  	s := spew.Sdump(ConnStats{})
    26  	t.Logf("\n%s", s)
    27  	lines := strings.Count(s, "\n")
    28  	assert.EqualValues(t, 2+reflect.ValueOf(ConnStats{}).NumField(), lines)
    29  }