forked from JekaMas/go-mutesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
77 lines (63 loc) · 2.44 KB
/
report.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package models
import "math/big"
// ReportFileName File name for json report
var ReportFileName string = "report.json"
// Report Structure for mutation report
type Report struct {
Stats Stats `json:"stats"`
Escaped []Mutant `json:"escaped"`
Timeouted []Mutant `json:"timeouted"`
Killed []Mutant `json:"killed"`
Errored []Mutant `json:"errored"`
}
// Stats There is stats for mutations
type Stats struct {
TotalMutantsCount int64 `json:"totalMutantsCount"`
KilledCount int64 `json:"killedCount"`
NotCoveredCount int64 `json:"notCoveredCount"`
EscapedCount int64 `json:"escapedCount"`
ErrorCount int64 `json:"errorCount"`
SkippedCount int64 `json:"skippedCount"`
TimeOutCount int64 `json:"timeOutCount"`
Msi *big.Float `json:"msi"`
MutationCodeCoverage int64 `json:"mutationCodeCoverage"`
CoveredCodeMsi float64 `json:"coveredCodeMsi"`
DuplicatedCount int64 `json:"-"`
}
// Mutant report by mutant for one mutation on one file
type Mutant struct {
Mutator Mutator `json:"mutator"`
Diff string `json:"diff"`
ProcessOutput string `json:"processOutput,omitempty"`
}
// Mutator mutator and changes in file
type Mutator struct {
MutatorName string `json:"mutatorName"`
OriginalSourceCode string `json:"originalSourceCode"`
MutatedSourceCode string `json:"mutatedSourceCode"`
OriginalFilePath string `json:"originalFilePath"`
OriginalStartLine int64 `json:"originalStartLine"`
}
// Calculate calculation for final report
func (report *Report) Calculate() {
report.Stats.Msi = report.MsiScore()
report.Stats.TotalMutantsCount = report.TotalCount()
}
// MsiScore msi score calculation
func (report *Report) MsiScore() *big.Float {
total := report.TotalCount()
msi := big.NewFloat(0)
if total == 0 {
return msi
}
killedCount := big.NewFloat(float64(report.Stats.KilledCount))
errorCount := big.NewFloat(float64(report.Stats.ErrorCount))
skippedCount := big.NewFloat(float64(report.Stats.SkippedCount))
subTotalSuccess := big.NewFloat(0).Add(killedCount, errorCount)
totalSuccess := big.NewFloat(0).Add(subTotalSuccess, skippedCount)
return msi.Quo(totalSuccess, big.NewFloat(float64(total)))
}
// TotalCount total mutations count
func (report *Report) TotalCount() int64 {
return report.Stats.KilledCount + report.Stats.EscapedCount + report.Stats.ErrorCount + report.Stats.SkippedCount
}