File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,10 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
67
67
let mut table = "| Test suite | Passed ✅ | Ignored 🚫 | Failed ❌ |\n " . to_string ( ) ;
68
68
writeln ! ( table, "|:------|------:|------:|------:|" ) . unwrap ( ) ;
69
69
70
+ fn compute_pct ( value : f64 , total : f64 ) -> f64 {
71
+ if total == 0.0 { 0.0 } else { value / total }
72
+ }
73
+
70
74
fn write_row (
71
75
buffer : & mut String ,
72
76
name : & str ,
@@ -75,9 +79,9 @@ fn render_table(suites: BTreeMap<String, TestSuiteRecord>) -> String {
75
79
) -> std:: fmt:: Result {
76
80
let TestSuiteRecord { passed, ignored, failed } = record;
77
81
let total = ( record. passed + record. ignored + record. failed ) as f64 ;
78
- let passed_pct = ( ( * passed as f64 ) / total) * 100.0 ;
79
- let ignored_pct = ( ( * ignored as f64 ) / total) * 100.0 ;
80
- let failed_pct = ( ( * failed as f64 ) / total) * 100.0 ;
82
+ let passed_pct = compute_pct ( * passed as f64 , total) * 100.0 ;
83
+ let ignored_pct = compute_pct ( * ignored as f64 , total) * 100.0 ;
84
+ let failed_pct = compute_pct ( * failed as f64 , total) * 100.0 ;
81
85
82
86
write ! ( buffer, "| {surround}{name}{surround} |" ) ?;
83
87
write ! ( buffer, " {surround}{passed} ({passed_pct:.0}%){surround} |" ) ?;
You can’t perform that action at this time.
0 commit comments