package reporter import ( "encoding/json" "fmt" "io" "strings" "github.com/Mond1c/judge/runner" ) func Text(w io.Writer, result *runner.SuiteResult) { if result.BuildLog != "" { fmt.Fprintf(w, "=== BUILD LOG ===\n%s\n", result.BuildLog) } for _, gr := range result.Groups { passed := gr.Passed total := gr.Total pct := 0.0 if total > 0 { pct = float64(passed) / float64(total) * 100 } fmt.Fprintf(w, "\n┌─ group %q weight=%.2f score=%.4f\n", gr.Name, gr.Weight, gr.Score) fmt.Fprintf(w, "│ %d/%d passed (%.0f%%)\n", passed, total, pct) for _, tr := range gr.Tests { icon := "✓" if tr.Status != runner.StatusPass { icon = "✗" } fmt.Fprintf(w, "│ %s [%s] %s (%dms)\n", icon, tr.Status, tr.Name, tr.Elapsed.Milliseconds()) for _, f := range tr.Failures { for _, line := range strings.Split(f, "\n") { fmt.Fprintf(w, "│ %s\n", line) } } } fmt.Fprintf(w, "└─\n") } fmt.Fprintf(w, "\n══ TOTAL SCORE: %.4f / 1.0000 ══\n", result.TotalScore) } func JSON(w io.Writer, result *runner.SuiteResult) error { enc := json.NewEncoder(w) enc.SetIndent("", " ") return enc.Encode(jsonResult(result)) } type jsonSuiteResult struct { TotalScore float64 `json:"total_score"` BuildLog string `json:"build_log,omitempty"` Groups []jsonGroupResult `json:"groups"` } type jsonGroupResult struct { Name string `json:"name"` Weight float64 `json:"weight"` Score float64 `json:"score"` Passed int `json:"passed"` Total int `json:"total"` Tests []jsonTestResult `json:"tests"` } type jsonTestResult struct { Name string `json:"name"` Status string `json:"status"` ElapsedMs int64 `json:"elapsed_ms"` Failures []string `json:"failures,omitempty"` } func jsonResult(r *runner.SuiteResult) jsonSuiteResult { res := jsonSuiteResult{ TotalScore: r.TotalScore, BuildLog: r.BuildLog, } for _, gr := range r.Groups { jgr := jsonGroupResult{ Name: gr.Name, Weight: gr.Weight, Score: gr.Score, Passed: gr.Passed, Total: gr.Total, } for _, tr := range gr.Tests { jgr.Tests = append(jgr.Tests, jsonTestResult{ Name: tr.Name, Status: tr.Status.String(), ElapsedMs: tr.Elapsed.Milliseconds(), Failures: tr.Failures, }) } res.Groups = append(res.Groups, jgr) } return res }