aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 13:39:34 -0500
committerFlu0r1ne <flur01ne@flu0r1ne.net>2021-09-05 13:39:34 -0500
commit54276b73eacfab6a5d6b899bd638f6cfe9499b80 (patch)
tree47f08b247e061489c91e9d98500dfd98d53b5d1b
parent7f3a568983470016bf99baafb4db47c8223c0494 (diff)
downloadplanr-54276b73eacfab6a5d6b899bd638f6cfe9499b80.tar.xz
planr-54276b73eacfab6a5d6b899bd638f6cfe9499b80.zip
Refactor with scoring object
-rw-r--r--cmd/planr/sub/cli.go10
-rw-r--r--cmd/planr/sub/evaluate.go26
-rw-r--r--scoring.go31
3 files changed, 40 insertions, 27 deletions
diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go
index 3c58f4e..e6f2256 100644
--- a/cmd/planr/sub/cli.go
+++ b/cmd/planr/sub/cli.go
@@ -107,16 +107,16 @@ func tcPprint(tr planr.TestResult) {
fmt.Println()
}
-func printResults(passed, tc_total int, earned, points_total float64) {
+func printScoring(score planr.Scoring) {
col_title.Println("Final Results:")
- pprintLabeled("passed", fmt.Sprintf("%d/%d", passed, tc_total));
+ pprintLabeled("passed", fmt.Sprintf("%d/%d", score.Passed, score.Total));
- percent := earned / points_total * 100
+ percent := score.EarnedPoints / score.TotalPoints * 100
- if points_total != 0 {
+ if score.TotalPoints != 0 {
pprintLabeled("score", fmt.Sprintf(
- "%.2f/%.2f ~= %.1f%%", earned, points_total, percent,
+ "%.2f/%.2f ~= %.1f%%", score.EarnedPoints, score.TotalPoints, percent,
));
}
}
diff --git a/cmd/planr/sub/evaluate.go b/cmd/planr/sub/evaluate.go
index c2549be..81c9989 100644
--- a/cmd/planr/sub/evaluate.go
+++ b/cmd/planr/sub/evaluate.go
@@ -4,36 +4,18 @@ import (
"golang.flu0r1ne.net/planr"
)
+
func Evaluate(runner planr.Runner, params []string, cfg planr.Config) {
dieIncompatibleVersion(cfg)
tcs := runner.CollectCases()
trs := runner.Evaluate(tcs)
- earned := 0.0
- total := 0.0
- passed := 0
- for _, tr := range trs {
- cfg := tr.Tc.Config
-
- if cfg.Points != nil {
- points := float64(*cfg.Points)
-
- total += points
-
- if tr.Status == planr.PASSING {
- earned += points
- passed++
- }
- }
+ score := planr.Score(trs)
+ for _, tr := range trs {
tcPprint(tr)
}
- printResults(
- passed,
- len(tcs),
- earned,
- total,
- );
+ printScoring(score)
}
diff --git a/scoring.go b/scoring.go
new file mode 100644
index 0000000..675058a
--- /dev/null
+++ b/scoring.go
@@ -0,0 +1,31 @@
+package planr
+
+type Scoring struct {
+ EarnedPoints float64
+ TotalPoints float64
+ Passed int
+ Total int
+}
+
+func Score(trs []TestResult) Scoring {
+ score := Scoring {}
+
+ for _, tr := range trs {
+ cfg := tr.Tc.Config
+ points := 0.0
+
+ if cfg.Points != nil {
+ points = float64(*cfg.Points)
+ }
+
+ score.TotalPoints += points
+ if tr.Status == PASSING {
+ score.EarnedPoints += points
+ score.Passed++
+ }
+
+ score.Total += 1
+ }
+
+ return score
+}