We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d67bcce commit 8e47c8eCopy full SHA for 8e47c8e
pkg/testcoverage/coverage/types.go
@@ -4,6 +4,7 @@ import (
4
"bytes"
5
"errors"
6
"fmt"
7
+ "math"
8
"regexp"
9
"strconv"
10
"strings"
@@ -64,7 +65,10 @@ func coveredPercentageF(total, covered int64) float64 {
64
65
return 100
66
}
67
- return float64(covered*100) / float64(total)
68
+ p := float64(covered*100) / float64(total)
69
+
70
+ // round to %.1f
71
+ return float64(int(math.Round(p*10))) / 10
72
73
74
func stripPrefix(name, prefix string) string {
pkg/testcoverage/coverage/types_test.go
@@ -22,6 +22,7 @@ func TestCoveredPercentage(t *testing.T) {
22
{percentage: 10, total: 10, covered: 1},
23
{percentage: 22, total: 9, covered: 2}, // 22.222.. should round down to 22
24
{percentage: 66, total: 9, covered: 6}, // 66.666.. should round down to 66
25
+ {percentage: 73, total: 274, covered: 200},
26
27
28
for _, tc := range tests {
@@ -35,6 +36,7 @@ func TestStatStr(t *testing.T) {
35
36
assert.Equal(t, " 0.0% (0/0)", Stats{}.Str())
37
assert.Equal(t, " 9.1% (1/11)", Stats{Covered: 1, Total: 11}.Str())
38
assert.Equal(t, "22.2% (2/9)", Stats{Covered: 2, Total: 9}.Str())
39
+ assert.Equal(t, "73.0% (200/274)", Stats{Covered: 200, Total: 274}.Str())
40
assert.Equal(t, "100% (10/10)", Stats{Covered: 10, Total: 10}.Str())
41
42
0 commit comments