6 "github.com/stretchr/testify/assert"
8 "github.com/anacrolix/torrent/metainfo"
11 func TestExtentCompleteRequiredLengths(t *testing.T) {
12 info := &metainfo.Info{
13 Files: []metainfo.FileInfo{
14 {Path: []string{"a"}, Length: 2},
15 {Path: []string{"b"}, Length: 3},
18 assert.Empty(t, extentCompleteRequiredLengths(info, 0, 0))
19 assert.EqualValues(t, []requiredLength{
20 {fileIndex: 0, length: 1},
21 }, extentCompleteRequiredLengths(info, 0, 1))
22 assert.EqualValues(t, []requiredLength{
23 {fileIndex: 0, length: 2},
24 }, extentCompleteRequiredLengths(info, 0, 2))
25 assert.EqualValues(t, []requiredLength{
26 {fileIndex: 0, length: 2},
27 {fileIndex: 1, length: 1},
28 }, extentCompleteRequiredLengths(info, 0, 3))
29 assert.EqualValues(t, []requiredLength{
30 {fileIndex: 1, length: 2},
31 }, extentCompleteRequiredLengths(info, 2, 2))
32 assert.EqualValues(t, []requiredLength{
33 {fileIndex: 1, length: 3},
34 }, extentCompleteRequiredLengths(info, 4, 1))
35 assert.Len(t, extentCompleteRequiredLengths(info, 5, 0), 0)
36 assert.Panics(t, func() { extentCompleteRequiredLengths(info, 6, 1) })