diff --git a/decor/decorators.go b/decor/decorators.go index e427f74..a47e4be 100644 --- a/decor/decorators.go +++ b/decor/decorators.go @@ -349,11 +349,7 @@ if total <= 0 { return 0 } - if current > total { - current = total - } - - p := float64(width) * float64(current) / float64(total) + p := float64(width*current) / float64(total) return int64(round(p)) } diff --git a/decor/percentage_test.go b/decor/percentage_test.go index e0672bb..1066c0c 100644 --- a/decor/percentage_test.go +++ b/decor/percentage_test.go @@ -1,8 +1,10 @@ package decor -import "testing" +import ( + "testing" +) -func TestCalcPersentage(t *testing.T) { +func TestCalcPercentage(t *testing.T) { // key is barWidth testSuite := map[int64]map[string]struct { total, current, expected int64 @@ -18,7 +20,8 @@ "t,c,e{100,50,50}": {100, 50, 50}, "t,c,e{100,99,99}": {100, 99, 99}, "t,c,e{100,100,100}": {100, 100, 100}, - "t,c,e{100,101,100}": {100, 101, 100}, + "t,c,e{100,101,101}": {100, 101, 101}, + "t,c,e{100,102,101}": {100, 102, 102}, "t,c,e{120,0,0}": {120, 0, 0}, "t,c,e{120,10,8}": {120, 10, 8}, "t,c,e{120,15,13}": {120, 15, 13}, @@ -29,7 +32,8 @@ "t,c,e{120,118,98}": {120, 118, 98}, "t,c,e{120,119,99}": {120, 119, 99}, "t,c,e{120,120,100}": {120, 120, 100}, - "t,c,e{120,121,100}": {120, 121, 100}, + "t,c,e{120,121,101}": {120, 121, 101}, + "t,c,e{120,122,101}": {120, 122, 102}, }, 80: { "t,c,e{-1,-1,0}": {-1, -1, 0}, @@ -42,7 +46,8 @@ "t,c,e{100,50,40}": {100, 50, 40}, "t,c,e{100,99,79}": {100, 99, 79}, "t,c,e{100,100,80}": {100, 100, 80}, - "t,c,e{100,101,80}": {100, 101, 80}, + "t,c,e{100,101,81}": {100, 101, 81}, + "t,c,e{100,102,82}": {100, 102, 82}, "t,c,e{120,0,0}": {120, 0, 0}, "t,c,e{120,10,7}": {120, 10, 7}, "t,c,e{120,15,10}": {120, 15, 10}, @@ -53,7 +58,8 @@ "t,c,e{120,118,79}": {120, 118, 79}, "t,c,e{120,119,79}": {120, 119, 79}, "t,c,e{120,120,80}": {120, 120, 80}, - "t,c,e{120,121,80}": {120, 121, 80}, + "t,c,e{120,121,81}": {120, 121, 81}, + "t,c,e{120,122,81}": {120, 122, 81}, }, }