-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script to find max coverage score from result data
- Loading branch information
1 parent
2f61bbf
commit 4cdcf5f
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
echo "java:" | ||
find $1 -path "*/write-tests/*/java/*/*/evaluation.log" | xargs go run scripts/find-max-coverage/main.go | ||
echo "ruby:" | ||
find $1 -path "*/write-tests/*/ruby/*/*/evaluation.log" | xargs go run scripts/find-max-coverage/main.go | ||
echo "golang:" | ||
find $1 -path "*/write-tests/*/golang/*/*/evaluation.log" | xargs go run scripts/find-max-coverage/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"regexp" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
||
"golang.org/x/exp/maps" | ||
) | ||
|
||
var reTaskFileName = regexp.MustCompile(`Given the following \w+ code file "(.*)" with`) | ||
|
||
func parseTaskFileName(s string) (string, bool) { | ||
if match := reTaskFileName.FindStringSubmatch(s); match != nil { | ||
return match[1], true | ||
} | ||
|
||
return "", false | ||
} | ||
|
||
var reCoverageObjects = regexp.MustCompile(`Executes tests with (\d+) coverage objects`) | ||
|
||
func parseCoverageObjects(s string) (int, bool) { | ||
match := reCoverageObjects.FindStringSubmatch(s) | ||
if match == nil { | ||
return 0, false | ||
} | ||
coverageObjectsText := match[1] | ||
coverageObjects, err := strconv.Atoi(coverageObjectsText) | ||
if err != nil { | ||
panic(fmt.Sprintf("cannot convert %q to integer (%q)", coverageObjectsText, s)) | ||
} | ||
|
||
return coverageObjects, true | ||
} | ||
|
||
func main() { | ||
logFileNames := os.Args[1:] | ||
var logFileData []byte | ||
|
||
for _, logFileName := range logFileNames { | ||
data, err := os.ReadFile(logFileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
logFileData = append(logFileData, data...) | ||
} | ||
|
||
var currentTaskFileName string | ||
bestCoverage := map[string]int{} | ||
|
||
logFileLines := strings.Split(string(logFileData), "\n") | ||
fmt.Printf("Loaded %d log files (total of %d lines)\n", len(logFileNames), len(logFileLines)) | ||
for _, line := range logFileLines { | ||
if taskFileName, ok := parseTaskFileName(line); ok { | ||
currentTaskFileName = taskFileName | ||
} | ||
|
||
if currentCoverageObjects, ok := parseCoverageObjects(line); ok && currentCoverageObjects > bestCoverage[currentTaskFileName] { | ||
bestCoverage[currentTaskFileName] = currentCoverageObjects | ||
} | ||
} | ||
|
||
sum := 0 | ||
taskFileNames := maps.Keys(bestCoverage) | ||
sort.Strings(taskFileNames) | ||
for _, taskFileName := range taskFileNames { | ||
score := bestCoverage[taskFileName] | ||
fmt.Printf(" - %q:%d\n", taskFileName, score) | ||
sum += score | ||
} | ||
fmt.Printf("∑ = %d (weighted: %d)\n", sum, sum*10) | ||
} |