| 1 | """Tests for the unified number formatters in :mod:`dlm_sway.suite.report` (D10).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import math |
| 6 | |
| 7 | from dlm_sway.suite import report |
| 8 | |
| 9 | |
| 10 | class TestFormatScore: |
| 11 | def test_two_decimals(self) -> None: |
| 12 | assert report.format_score(0.8765) == "0.88" |
| 13 | |
| 14 | def test_none_is_em_dash(self) -> None: |
| 15 | assert report.format_score(None) == "—" |
| 16 | |
| 17 | def test_nan_is_em_dash(self) -> None: |
| 18 | assert report.format_score(math.nan) == "—" |
| 19 | |
| 20 | def test_inf_is_em_dash(self) -> None: |
| 21 | assert report.format_score(math.inf) == "—" |
| 22 | |
| 23 | def test_int_accepted(self) -> None: |
| 24 | assert report.format_score(1) == "1.00" |
| 25 | |
| 26 | |
| 27 | class TestFormatRaw: |
| 28 | def test_three_decimals(self) -> None: |
| 29 | assert report.format_raw(0.123456) == "0.123" |
| 30 | |
| 31 | def test_thousands_separator(self) -> None: |
| 32 | assert report.format_raw(1234.5678) == "1,234.568" |
| 33 | |
| 34 | def test_none_is_em_dash(self) -> None: |
| 35 | assert report.format_raw(None) == "—" |
| 36 | |
| 37 | |
| 38 | class TestFormatZ: |
| 39 | def test_signed_with_sigma(self) -> None: |
| 40 | assert report.format_z(3.14) == "+3.14σ" |
| 41 | |
| 42 | def test_negative(self) -> None: |
| 43 | assert report.format_z(-1.5) == "-1.50σ" |
| 44 | |
| 45 | def test_large_thousands_separator(self) -> None: |
| 46 | assert report.format_z(1234.56) == "+1,234.56σ" |
| 47 | |
| 48 | def test_none_is_em_dash(self) -> None: |
| 49 | assert report.format_z(None) == "—" |
| 50 | |
| 51 | |
| 52 | class TestFormatDuration: |
| 53 | def test_sub_ten_seconds(self) -> None: |
| 54 | assert report.format_duration_s(1.234) == "1.23s" |
| 55 | |
| 56 | def test_between_ten_and_hundred(self) -> None: |
| 57 | assert report.format_duration_s(42.678) == "42.7s" |
| 58 | |
| 59 | def test_large_seconds_with_thousands(self) -> None: |
| 60 | assert report.format_duration_s(12345.6) == "12,346s" |
| 61 | |
| 62 | def test_none_is_em_dash(self) -> None: |
| 63 | assert report.format_duration_s(None) == "—" |