/
counter.go
62 lines (49 loc) · 1.05 KB
/
counter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package entity
import (
"fmt"
"strconv"
)
type LineCounter struct {
totalLines int
coveredLines int
}
func (c *LineCounter) AddLine(covered bool) {
c.totalLines++
if covered {
c.coveredLines++
}
}
func (c *LineCounter) String() string {
if c.totalLines == 0 {
return "1.00"
}
return fmt.Sprintf("%.2f", float64(c.coveredLines)/float64(c.totalLines))
}
func (c *LineCounter) ValidString() string {
return strconv.Itoa(c.totalLines)
}
func (c *LineCounter) CoveredString() string {
return strconv.Itoa(c.coveredLines)
}
type BranchCounter struct {
totalBranches int
coveredBranches int
}
func (b *BranchCounter) AddBranch(covered bool) {
b.totalBranches++
if covered {
b.coveredBranches++
}
}
func (b *BranchCounter) String() string {
if b.totalBranches == 0 {
return "1.00"
}
return fmt.Sprintf("%.2f", float64(b.coveredBranches)/float64(b.totalBranches))
}
func (b *BranchCounter) ValidString() string {
return strconv.Itoa(b.totalBranches)
}
func (b *BranchCounter) CoveredString() string {
return strconv.Itoa(b.coveredBranches)
}