Codebase list golang-github-vbauerster-mpb / d0fb107
internal make sure width is uint Vladimir Bauer 4 years ago
2 changed file(s) with 3 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
22 import "math"
33
44 // Percentage is a helper function, to calculate percentage.
5 func Percentage(total, current int64, width int) float64 {
5 func Percentage(total, current int64, width uint) float64 {
66 if total <= 0 {
77 return 0
88 }
1313 }
1414
1515 // PercentageRound same as Percentage but with math.Round.
16 func PercentageRound(total, current int64, width int) float64 {
16 func PercentageRound(total, current int64, width uint) float64 {
1717 return math.Round(Percentage(total, current, width))
1818 }
33
44 func TestPercentage(t *testing.T) {
55 // key is barWidth
6 testSuite := map[int][]struct {
6 testSuite := map[uint][]struct {
77 name string
88 total int64
99 current int64