2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-10 19:16:36 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-02-10 19:16:36 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
2020-02-10 19:16:36 +00:00
|
|
|
func testFill(t *testing.T, n abi.UnpaddedPieceSize, exp []abi.UnpaddedPieceSize) {
|
2020-01-15 20:49:11 +00:00
|
|
|
f, err := fillersFromRem(n)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, exp, f)
|
|
|
|
|
2020-02-10 19:16:36 +00:00
|
|
|
var sum abi.UnpaddedPieceSize
|
2020-01-15 20:49:11 +00:00
|
|
|
for _, u := range f {
|
|
|
|
sum += u
|
|
|
|
}
|
|
|
|
assert.Equal(t, n, sum)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFillersFromRem(t *testing.T) {
|
|
|
|
for i := 8; i < 32; i++ {
|
|
|
|
// single
|
2020-02-10 19:16:36 +00:00
|
|
|
ub := abi.PaddedPieceSize(uint64(1) << i).Unpadded()
|
|
|
|
testFill(t, ub, []abi.UnpaddedPieceSize{ub})
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// 2
|
2020-02-10 19:16:36 +00:00
|
|
|
ub = abi.PaddedPieceSize(uint64(5) << i).Unpadded()
|
|
|
|
ub1 := abi.PaddedPieceSize(uint64(1) << i).Unpadded()
|
|
|
|
ub3 := abi.PaddedPieceSize(uint64(4) << i).Unpadded()
|
|
|
|
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub3})
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// 4
|
2020-02-10 19:16:36 +00:00
|
|
|
ub = abi.PaddedPieceSize(uint64(15) << i).Unpadded()
|
|
|
|
ub2 := abi.PaddedPieceSize(uint64(2) << i).Unpadded()
|
|
|
|
ub4 := abi.PaddedPieceSize(uint64(8) << i).Unpadded()
|
|
|
|
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub2, ub3, ub4})
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// different 2
|
2020-02-10 19:16:36 +00:00
|
|
|
ub = abi.PaddedPieceSize(uint64(9) << i).Unpadded()
|
|
|
|
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
2020-01-29 20:01:20 +00:00
|
|
|
}
|