]> Sergey Matveev's repositories - btrtrc.git/blob - misc_test.go
Implement new request strategy
[btrtrc.git] / misc_test.go
1 package torrent
2
3 import (
4         "testing"
5
6         "github.com/anacrolix/missinggo/bitmap"
7         "github.com/anacrolix/missinggo/iter"
8         "github.com/stretchr/testify/assert"
9 )
10
11 func TestTorrentOffsetRequest(t *testing.T) {
12         check := func(tl, ps, off int64, expected request, ok bool) {
13                 req, _ok := torrentOffsetRequest(tl, ps, defaultChunkSize, off)
14                 assert.Equal(t, _ok, ok)
15                 assert.Equal(t, req, expected)
16         }
17         check(13, 5, 0, newRequest(0, 0, 5), true)
18         check(13, 5, 3, newRequest(0, 0, 5), true)
19         check(13, 5, 11, newRequest(2, 0, 3), true)
20         check(13, 5, 13, request{}, false)
21 }
22
23 func TestIterBitmapsDistinct(t *testing.T) {
24         var skip, first, second bitmap.Bitmap
25         skip.Add(1)
26         first.Add(1, 0, 3)
27         second.Add(1, 2, 0)
28         assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(skip.Copy(), first, second)))
29         assert.Equal(t, []int{1}, skip.ToSortedSlice())
30 }