代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/go-torrent 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package torrent
import (
"testing"
"github.com/RoaringBitmap/roaring"
"github.com/stretchr/testify/assert"
)
func TestFileExclusivePieces(t *testing.T) {
for _, _case := range []struct {
off, size, pieceSize int64
begin, end int
}{
{0, 2, 2, 0, 1},
{1, 2, 2, 1, 1},
{1, 4, 2, 1, 2},
} {
begin, end := byteRegionExclusivePieces(_case.off, _case.size, _case.pieceSize)
assert.EqualValues(t, _case.begin, begin)
assert.EqualValues(t, _case.end, end)
}
}
type testFileBytesLeft struct {
usualPieceSize int64
firstPieceIndex int
endPieceIndex int
fileOffset int64
fileLength int64
completedPieces roaring.Bitmap
expected int64
name string
}
func (me testFileBytesLeft) Run(t *testing.T) {
t.Run(me.name, func(t *testing.T) {
assert.EqualValues(t, me.expected, fileBytesLeft(me.usualPieceSize, me.firstPieceIndex, me.endPieceIndex, me.fileOffset, me.fileLength, &me.completedPieces))
})
}
func TestFileBytesLeft(t *testing.T) {
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 1,
endPieceIndex: 1,
fileOffset: 1,
fileLength: 0,
expected: 0,
name: "ZeroLengthFile",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 2,
firstPieceIndex: 1,
endPieceIndex: 2,
fileOffset: 1,
fileLength: 1,
expected: 1,
name: "EndOfSecondPiece",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 0,
endPieceIndex: 1,
fileOffset: 1,
fileLength: 1,
expected: 1,
name: "FileInFirstPiece",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 0,
endPieceIndex: 1,
fileOffset: 1,
fileLength: 1,
expected: 1,
name: "LandLocked",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 1,
endPieceIndex: 3,
fileOffset: 4,
fileLength: 4,
expected: 4,
name: "TwoPieces",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 1,
endPieceIndex: 4,
fileOffset: 5,
fileLength: 7,
expected: 7,
name: "ThreePieces",
}.Run(t)
testFileBytesLeft{
usualPieceSize: 3,
firstPieceIndex: 1,
endPieceIndex: 4,
fileOffset: 5,
fileLength: 7,
expected: 0,
completedPieces: func() (ret roaring.Bitmap) {
ret.AddRange(0, 5)
return
}(),
name: "ThreePiecesCompletedAll",
}.Run(t)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。