forked from imsky/cobertool
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
34 lines (28 loc) · 998 Bytes
/
main_test.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
package main
import (
"testing"
)
func TestComputeTotalCoverage(t *testing.T) {
sourceFiles := make(map[string][]SourceFile)
a := SourceFile{Lines: []Line{{Number: 1, Hit: true}, {Number: 2, Hit: true}, {Number: 3, Hit: false}}}
b := SourceFile{Lines: []Line{{Number: 1, Hit: false}, {Number: 2, Hit: false}, {Number: 3, Hit: true}}}
sourceFiles["a"] = []SourceFile{a}
coverage := ComputeTotalCoverage(sourceFiles)
if int(coverage) != 66 {
t.Errorf("Incorrect single source file coverage calculation: %v", coverage)
}
sourceFiles["b"] = []SourceFile{b}
coverage = ComputeTotalCoverage(sourceFiles)
if int(coverage) != 50 {
t.Errorf("Incorrect multiple source file coverage calculation: %v", coverage)
}
sourceFiles["a"] = []SourceFile{a, b}
coverage = ComputeTotalCoverage(sourceFiles)
if int(coverage) != 66 {
t.Errorf("Incorrect merged source file coverage calculation: %v", coverage)
}
}
func TestCobertool(t *testing.T) {
main()
Run([]string{"test-report.xml"})
}