diff --git a/cmd/go-mutesting/main.go b/cmd/go-mutesting/main.go index d36a996..830f40d 100644 --- a/cmd/go-mutesting/main.go +++ b/cmd/go-mutesting/main.go @@ -152,6 +152,20 @@ type mutationStats struct { skipped int } +func (ms *mutationStats) Score() float64 { + total := ms.Total() + + if total == 0 { + return 0.0 + } + + return float64(ms.passed) / float64(total) +} + +func (ms *mutationStats) Total() int { + return ms.passed + ms.failed + ms.skipped +} + func mainCmd(args []string) int { var opts = &options{} var mutationBlackList = map[string]struct{}{} @@ -317,7 +331,7 @@ MUTATOR: } if !opts.Exec.NoExec { - fmt.Printf("The mutation score is %f (%d passed, %d failed, %d duplicated, %d skipped, total is %d)\n", float64(stats.passed)/float64(stats.passed+stats.failed), stats.passed, stats.failed, stats.duplicated, stats.skipped, stats.passed+stats.failed+stats.duplicated+stats.skipped) + fmt.Printf("The mutation score is %f (%d passed, %d failed, %d duplicated, %d skipped, total is %d)\n", stats.Score(), stats.passed, stats.failed, stats.duplicated, stats.skipped, stats.Total()) } else { fmt.Println("Cannot do a mutation testing summary since no exec command was executed.") } diff --git a/cmd/go-mutesting/main_test.go b/cmd/go-mutesting/main_test.go index 34e2a3a..83d1f50 100644 --- a/cmd/go-mutesting/main_test.go +++ b/cmd/go-mutesting/main_test.go @@ -15,7 +15,7 @@ func TestMain(t *testing.T) { "../../example", []string{"--debug", "--exec-timeout", "1"}, returnOk, - "The mutation score is 0.538462 (7 passed, 6 failed, 9 duplicated, 0 skipped, total is 22)", + "The mutation score is 0.538462 (7 passed, 6 failed, 9 duplicated, 0 skipped, total is 13)", ) } @@ -25,7 +25,7 @@ func TestMainRecursive(t *testing.T) { "../../example", []string{"--debug", "--exec-timeout", "1", "./..."}, returnOk, - "The mutation score is 0.571429 (8 passed, 6 failed, 9 duplicated, 0 skipped, total is 23)", + "The mutation score is 0.571429 (8 passed, 6 failed, 9 duplicated, 0 skipped, total is 14)", ) } @@ -35,7 +35,7 @@ func TestMainFromOtherDirectory(t *testing.T) { "../..", []string{"--debug", "--exec-timeout", "1", "github.com/zimmski/go-mutesting/example"}, returnOk, - "The mutation score is 0.538462 (7 passed, 6 failed, 9 duplicated, 0 skipped, total is 22)", + "The mutation score is 0.538462 (7 passed, 6 failed, 9 duplicated, 0 skipped, total is 13)", ) }