From 5c3f0b9b172660566d38e70b44aa2cae7dfe7e7c Mon Sep 17 00:00:00 2001 From: David Fischer Date: Mon, 21 Sep 2026 18:56:55 -0700 Subject: [PATCH] Fix place order suffix --- src/client.py | 9 +-------- src/normalizer.py | 18 ++++++++++-------- tests/test_normalizer.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/client.py b/src/client.py index c9a485b..f33b3cc 100644 --- a/src/client.py +++ b/src/client.py @@ -505,14 +505,7 @@ def _parse_decks( if winloss and player_id in winloss: result = winloss[player_id] else: - if rank == 1: - result = "1st Place" - elif rank == 2: - result = "2nd Place" - elif rank == 3: - result = "3rd Place" - else: - result = f"{rank}th Place" + result = OrderNormalizer.format_place(rank) rank += 1 deck = Deck( diff --git a/src/normalizer.py b/src/normalizer.py index 6b20f1e..3d55e84 100644 --- a/src/normalizer.py +++ b/src/normalizer.py @@ -32,6 +32,15 @@ def combine_duplicates(input_items: List[DeckItem]) -> List[DeckItem]: class OrderNormalizer: + @staticmethod + def format_place(position: int) -> str: + """Format an integer rank into an ordinal place string (e.g. 1st Place, 32nd Place).""" + if 11 <= (position % 100) <= 13: + suffix = "th" + else: + suffix = {1: "st", 2: "nd", 3: "rd"}.get(position % 10, "th") + return f"{position}{suffix} Place" + @staticmethod def reorder_decks( decks: List[Deck], @@ -51,14 +60,7 @@ def reorder_decks( position += 1 continue - rank = f"{position}th Place" - if position == 1: - rank = "1st Place" - elif position == 2: - rank = "2nd Place" - elif position == 3: - rank = "3rd Place" - + rank = OrderNormalizer.format_place(position) position += 1 if update_result: diff --git a/tests/test_normalizer.py b/tests/test_normalizer.py index a49d961..1c4b1c0 100644 --- a/tests/test_normalizer.py +++ b/tests/test_normalizer.py @@ -80,3 +80,31 @@ def test_order_normalizer_playoff_bracket(): assert reordered[1].player == "Bob" assert reordered[1].result == "2nd Place" + + +def test_order_normalizer_format_place(): + test_cases = { + 1: "1st Place", + 2: "2nd Place", + 3: "3rd Place", + 4: "4th Place", + 11: "11th Place", + 12: "12th Place", + 13: "13th Place", + 14: "14th Place", + 21: "21st Place", + 22: "22nd Place", + 23: "23rd Place", + 31: "31st Place", + 32: "32nd Place", + 33: "33rd Place", + 40: "40th Place", + 101: "101st Place", + 111: "111th Place", + 112: "112th Place", + 113: "113th Place", + 122: "122nd Place", + 133: "133rd Place", + } + for rank, expected in test_cases.items(): + assert OrderNormalizer.format_place(rank) == expected