Add test cases

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-12-10 21:33:27 +01:00
parent bfdfd4023e
commit 1124f8d994
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 28 additions and 1 deletions

View File

@ -20,5 +20,5 @@ func SizeStr(size types.BigInt) string {
}
f, _ := r.Float64()
return fmt.Sprintf("%.3f %s", f, Units[i])
return fmt.Sprintf("%.3g %s", f, Units[i])
}

27
cli/utils_test.go Normal file
View File

@ -0,0 +1,27 @@
package cli
import (
"testing"
types "github.com/filecoin-project/lotus/chain/types"
"github.com/stretchr/testify/assert"
)
func TestSizeStr(t *testing.T) {
cases := []struct {
in uint64
out string
}{
{0, "0 B"},
{1, "1 B"},
{1024, "1 KiB"},
{2000, "1.95 KiB"},
{5 << 20, "5 MiB"},
{11 << 60, "11 EiB"},
}
for _, c := range cases {
assert.Equal(t, c.out, SizeStr(types.NewInt(c.in)), "input %+v, produced wrong result", c)
}
}