Codebase list golang-github-vbauerster-mpb / afa6770
minor: PercentageRound width uint Vladimir Bauer 1 year, 10 months ago
3 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
232232 var tip component
233233 var refilling, filling, padding []byte
234234 var fillCount int
235 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, int64(width)))
235 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, uint(width)))
236236
237237 if curWidth != 0 {
238238 if !stat.Completed || s.tipOnComplete {
242242 }
243243 switch refWidth := 0; {
244244 case stat.Refill != 0:
245 refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, int64(width)))
245 refWidth = int(internal.PercentageRound(stat.Total, stat.Refill, uint(width)))
246246 curWidth -= refWidth
247247 refWidth += curWidth
248248 fallthrough
1313 }
1414
1515 // PercentageRound same as Percentage but with math.Round.
16 func PercentageRound(total, current, width int64) float64 {
17 if total < 0 || current < 0 || width < 0 {
16 func PercentageRound(total, current int64, width uint) float64 {
17 if total < 0 || current < 0 {
1818 return 0
1919 }
20 return math.Round(Percentage(uint(total), uint(current), uint(width)))
20 return math.Round(Percentage(uint(total), uint(current), width))
2121 }
33
44 func TestPercentage(t *testing.T) {
55 // key is barWidth
6 testSuite := map[int64][]struct {
6 testSuite := map[uint][]struct {
77 name string
88 total int64
99 current int64