From f63649f762bfe032f414028c5159ec827675e27b Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 26 Jul 2026 18:34:02 -0600 Subject: [PATCH] Fix tavern money prompts truncating cents player.money can carry cents after a fractional bank withdrawal (bank.py already parses withdraw/deposit amounts as float), but the tavern's "Change Bet" prompts formatted it with %d, silently dropping the fractional part. Switch those three prompts to %.2f, matching the convention already used for player.money in bank.py. Co-Authored-By: Claude Sonnet 5 --- src/location/tavern.py | 7 +++--- tests/location/test_tavern.py | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/location/tavern.py b/src/location/tavern.py index 649f532..b66de7d 100644 --- a/src/location/tavern.py +++ b/src/location/tavern.py @@ -228,7 +228,7 @@ def gamble(self): continue elif input == 7: self.changeBet( - "How much money would you like to bet? Money: $%d" + "How much money would you like to bet? Money: $%.2f" % self.player.money ) continue @@ -242,7 +242,7 @@ def gamble(self): def changeBet(self, prompt): amount = self.userInterface.promptForNumber(prompt) if amount is None: - self.currentPrompt.text = "Try again. Money: $%d" % self.player.money + self.currentPrompt.text = "Try again. Money: $%.2f" % self.player.money return self.amount = int(amount) @@ -255,7 +255,8 @@ def changeBet(self, prompt): # Don't call self.gamble() recursively - let the main loop continue else: self.currentPrompt.text = ( - "You don't have that much money on you! Money: $%d" % self.player.money + "You don't have that much money on you! Money: $%.2f" + % self.player.money ) def talkToNPC(self): diff --git a/tests/location/test_tavern.py b/tests/location/test_tavern.py index b0d5103..457d733 100644 --- a/tests/location/test_tavern.py +++ b/tests/location/test_tavern.py @@ -361,6 +361,51 @@ def test_changeBet_invalid_input(): builtins.input = original_input +def test_changeBet_invalid_input_shows_cents(): + # prepare - money picks up cents via bank withdrawals (see bank.py), so + # the retry prompt must not silently truncate them + tavernInstance = createTavern() + tavernInstance.player.money = 42.7 + tavernInstance.userInterface.promptForNumber = MagicMock(return_value=None) + + # call + tavernInstance.changeBet("How much money would you like to bet?") + + # check + assert "$42.70" in tavernInstance.currentPrompt.text + + +def test_changeBet_insufficient_money_shows_cents(): + # prepare + tavernInstance = createTavern() + tavernInstance.player.money = 12.3 + tavernInstance.userInterface.promptForNumber = MagicMock(return_value=100) + + # call + tavernInstance.changeBet("How much money would you like to bet?") + + # check + assert tavernInstance.currentBet == 0 + assert "$12.30" in tavernInstance.currentPrompt.text + + +def test_gamble_change_bet_prompt_shows_cents(): + # prepare - the "Change Bet" option (7) rebuilds its prompt from + # player.money each time; a fractional balance must not lose its cents + tavernInstance = createTavern() + tavernInstance.player.money = 100.5 + tavernInstance.changeBet = MagicMock() + tavernInstance.userInterface.showOptions = MagicMock(side_effect=["7", "8"]) + + # call + tavernInstance.gamble() + + # check + tavernInstance.changeBet.assert_called_once() + promptArg = tavernInstance.changeBet.call_args[0][0] + assert "$100.50" in promptArg + + def test_getDrunk_updates_stats(): # prepare tavernInstance = createTavern()