forked from filecoin-project/storage-fsm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
45 lines (36 loc) · 1.14 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package sealing
import (
"testing"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/stretchr/testify/assert"
)
func testFill(t *testing.T, n abi.UnpaddedPieceSize, exp []abi.UnpaddedPieceSize) {
f, err := fillersFromRem(n)
assert.NoError(t, err)
assert.Equal(t, exp, f)
var sum abi.UnpaddedPieceSize
for _, u := range f {
sum += u
}
assert.Equal(t, n, sum)
}
func TestFillersFromRem(t *testing.T) {
for i := 8; i < 32; i++ {
// single
ub := abi.PaddedPieceSize(uint64(1) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub})
// 2
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})
// 4
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})
// different 2
ub = abi.PaddedPieceSize(uint64(9) << i).Unpadded()
testFill(t, ub, []abi.UnpaddedPieceSize{ub1, ub4})
}
}