step 5
TirSystem/github-action: Sync GitHub mirror metadata / sync-metadata (push) Successful in 5s

Improving the user experience
This commit is contained in:
2026-10-04 12:46:03 +08:00
parent a76df46b79
commit 16cd9d42b9
6 changed files with 222 additions and 30 deletions
+22 -1
View File
@@ -1,4 +1,6 @@
from hangman.constants import MAX_LIVES, WORD_LIST
import pytest
from hangman.constants import MAX_LIVES, STAGES, WORD_LIST
from hangman.game import Game, choose_word, is_in_word
@@ -66,3 +68,22 @@ def test_lost_when_out_of_lives():
assert not g.lost
g.guess("y")
assert g.lost and g.over and not g.won
def test_stages_cover_all_lives():
assert len(STAGES) == MAX_LIVES + 1
def test_repeated_guess_is_free():
g = Game("cat")
g.guess("z")
assert g.guess("Z") is None
assert g.lives == MAX_LIVES - 1
def test_invalid_guess():
g = Game("cat")
for bad in ("", "ab", "1", " "):
with pytest.raises(ValueError):
g.guess(bad)
assert g.lives == MAX_LIVES