def test_hangman_guess_wrong_letter_and_game_over(): hangman = Hangman("order", attempt_count=4) assert hangman.attempt_count == 4 with pytest.raises(NoLives): hangman.guess("a") assert hangman.attempt_count == 5
def test_hangman_guess_wrong_letter(): hangman = Hangman("order") assert hangman.attempt_count == 0 with pytest.raises(WrongGuess): hangman.guess("a") assert hangman.attempt_count == 1
def start_game(game_config: GameConfig = Body( ..., example={"lives": config.HANGMAN_LIVES})): """Start a new game of Hangman""" hangman = Hangman(word=game_config.word, max_attempts=game_config.lives) with db.SessionManager() as db_session: crud.games.create(db_session, hangman) return Game.from_hangman(hangman)
def load(self) -> Hangman: return Hangman( uid=uuid.UUID(self.game_uid), word=self.word, max_attempts=self.max_attempts, attempt_count=self.attempt_count, known_letters=set(iter(self.known_letters)), )
def test_hangman_guess_letter_case_insensitive(letter): hangman = Hangman("Order") assert hangman.guess(letter) == "O _ _ _ _"
def test_hangman_guess_word(): hangman = Hangman("order") assert hangman.guess("order") == "o r d e r"
def test_hangman_guess_existing_letter(): hangman = Hangman("order") assert hangman.guess("r") == "_ r _ _ r"
def test_score_depends_on_attempt(word, attempt_count, score): hangman = Hangman(word, known_letters=set(word), attempt_count=attempt_count) assert hangman.score == score
def test_score(word, known_letters, score): hangman = Hangman(word, known_letters=known_letters) assert hangman.score == score
def test_hangman_string_representation(): hangman = Hangman("order") assert str(hangman) == "_ _ _ _ _"
def test_hangman_is_game_over(attempt_count, game_over): hangman = Hangman("order", attempt_count=attempt_count) assert hangman.is_game_over() is game_over
def test_hangman_lives(attempt_count, lives): hangman = Hangman("order", attempt_count=attempt_count) assert hangman.lives == lives
def test_hangman_completed(word, known_letters, completed): hangman = Hangman(word, known_letters=known_letters) assert hangman.completed is completed
def test_hangman_guess_word_case_insensitive(): hangman = Hangman("OrDeR") assert hangman.guess("order") == "O r D e R"
def test_hangman_string_representation_with_known_letters(): hangman = Hangman("order", known_letters={"r"}) assert str(hangman) == "_ r _ _ r"