Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/location/tavern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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):
Expand Down
45 changes: 45 additions & 0 deletions tests/location/test_tavern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading