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

Replacing blanks with guesses
This commit is contained in:
2026-10-04 12:37:41 +08:00
parent f07c34a5fa
commit 15d5f7134d
6 changed files with 108 additions and 38 deletions
+17 -1
View File
@@ -1,5 +1,5 @@
from hangman.constants import WORD_LIST
from hangman.game import choose_word, is_in_word
from hangman.game import Game, choose_word, is_in_word
def test_choose_word_from_list():
@@ -14,3 +14,19 @@ def test_letter_in_word():
def test_letter_not_in_word():
assert not is_in_word("camel", "z")
def test_display_starts_blank():
assert Game("cat").display() == "_ _ _"
def test_correct_guess_reveals_letters():
g = Game("banana")
assert g.guess("a") is True
assert g.display() == "_ a _ a _ a"
def test_wrong_guess_keeps_blanks():
g = Game("cat")
assert g.guess("z") is False
assert g.display() == "_ _ _"
+11 -4
View File
@@ -8,9 +8,16 @@ def run(monkeypatch, capsys, word, letter):
return capsys.readouterr().out
def test_right_guess(monkeypatch, capsys):
assert "Right" in run(monkeypatch, capsys, "camel", "a")
def test_right_guess_fills_blanks(monkeypatch, capsys):
out = run(monkeypatch, capsys, "camel", "a")
assert out.splitlines() == [
"_ _ _ _ _",
"Right, 'a' is in the word.",
"_ a _ _ _",
]
def test_wrong_guess(monkeypatch, capsys):
assert "Wrong" in run(monkeypatch, capsys, "camel", "z")
def test_wrong_guess_keeps_blanks(monkeypatch, capsys):
out = run(monkeypatch, capsys, "camel", "z")
assert "Wrong" in out
assert out.splitlines()[-1] == "_ _ _ _ _"