Пример #1
0
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
Пример #2
0
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
Пример #3
0
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)
Пример #4
0
 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)),
     )
Пример #5
0
def test_hangman_guess_letter_case_insensitive(letter):
    hangman = Hangman("Order")
    assert hangman.guess(letter) == "O _ _ _ _"
Пример #6
0
def test_hangman_guess_word():
    hangman = Hangman("order")
    assert hangman.guess("order") == "o r d e r"
Пример #7
0
def test_hangman_guess_existing_letter():
    hangman = Hangman("order")
    assert hangman.guess("r") == "_ r _ _ r"
Пример #8
0
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
Пример #9
0
def test_score(word, known_letters, score):
    hangman = Hangman(word, known_letters=known_letters)
    assert hangman.score == score
Пример #10
0
def test_hangman_string_representation():
    hangman = Hangman("order")
    assert str(hangman) == "_ _ _ _ _"
Пример #11
0
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
Пример #12
0
def test_hangman_lives(attempt_count, lives):
    hangman = Hangman("order", attempt_count=attempt_count)
    assert hangman.lives == lives
Пример #13
0
def test_hangman_completed(word, known_letters, completed):
    hangman = Hangman(word, known_letters=known_letters)
    assert hangman.completed is completed
Пример #14
0
def test_hangman_guess_word_case_insensitive():
    hangman = Hangman("OrDeR")
    assert hangman.guess("order") == "O r D e R"
Пример #15
0
def test_hangman_string_representation_with_known_letters():
    hangman = Hangman("order", known_letters={"r"})
    assert str(hangman) == "_ r _ _ r"