Fix SizeStr index out of band
add test for it Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
8f1c2b7aa9
commit
2d22f9c3d3
@ -131,7 +131,7 @@ func (bi BigInt) SizeStr() string {
|
||||
den := big.NewRat(1, 1024)
|
||||
|
||||
var i int
|
||||
for f, _ := r.Float64(); f >= 1024 && 1 < len(sizeUnits); f, _ = r.Float64() {
|
||||
for f, _ := r.Float64(); f >= 1024 && i+1 < len(sizeUnits); f, _ = r.Float64() {
|
||||
i++
|
||||
r = r.Mul(r, den)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -69,3 +70,11 @@ func TestSizeStr(t *testing.T) {
|
||||
assert.Equal(t, c.out, NewInt(c.in).SizeStr(), "input %+v, produced wrong result", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSizeStrBig(t *testing.T) {
|
||||
ZiB := big.NewInt(50000)
|
||||
ZiB = ZiB.Lsh(ZiB, 70)
|
||||
|
||||
assert.Equal(t, "5e+04 ZiB", BigInt{Int: ZiB}.SizeStr(), "inout %+v, produced wrong result", ZiB)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user