Print a table summarizing all problem results.
(summaries: list[dict])
| 307 | |
| 308 | |
| 309 | def print_summary(summaries: list[dict]): |
| 310 | """Print a table summarizing all problem results.""" |
| 311 | name_width = max((len(s["problem"]) for s in summaries), default=20) |
| 312 | name_width = max(name_width, 20) |
| 313 | row_width = name_width + 2 + 5 + 1 + 5 + 1 + 8 |
| 314 | |
| 315 | print("\n" + "=" * row_width) |
| 316 | print(f"{'Problem':<{name_width}} {'Pass':>5} {'Fail':>5} {'Status':>8}") |
| 317 | print("-" * row_width) |
| 318 | |
| 319 | total_problems = len(summaries) |
| 320 | all_passed = 0 |
| 321 | any_failed = 0 |
| 322 | |
| 323 | for s in summaries: |
| 324 | name = s["problem"] |
| 325 | pass_count = s["passed"] |
| 326 | fail_count = s["failed"] |
| 327 | |
| 328 | if fail_count == 0: |
| 329 | status = "OK" |
| 330 | all_passed += 1 |
| 331 | else: |
| 332 | status = "FAIL" |
| 333 | any_failed += 1 |
| 334 | |
| 335 | print(f"{name:<{name_width}} {pass_count:>5} {fail_count:>5} {status:>8}") |
| 336 | |
| 337 | print("=" * row_width) |
| 338 | print(f"Total: {total_problems} problems | OK: {all_passed} | FAIL: {any_failed}") |
| 339 | |
| 340 | |
| 341 | # --------------------------------------------------------------------------- |