def test_guessed_word_state_is_unchanged_if_guess_not_in_word(self): initialGuessedWordState = ['', '', 'S', '', 'W', 'O', 'R', ''] game = Game(word='TESTWORD', guessed_word_state=initialGuessedWordState, letters_guessed=['S', 'A', 'W', 'O', 'R', 'C'], guesses_allowed=5, guesses_taken=2) game.handleGuess('X') self.assertEquals(initialGuessedWordState, game.guessed_word_state)
def test_guesses_taken_should_increment_if_letter_not_in_word(self): expectedGuessesTaken = 2 game = Game(word='TESTWORD', guessed_word_state=['', '', 'S', '', 'W', 'O', 'R', ''], letters_guessed=['S', 'A', 'W', 'O', 'R', 'C'], guesses_allowed=5, guesses_taken=expectedGuessesTaken) game.handleGuess('X') self.assertEquals(expectedGuessesTaken + 1, game.guesses_taken)
def test_guessed_word_state_is_updated_with_guessed_letter_in_word(self): initialGuessedWordState = ['', '', 'S', '', 'W', 'O', 'R', ''] expectedGuessedWordState = ['T', '', 'S', 'T', 'W', 'O', 'R', ''] game = Game(word='TESTWORD', guessed_word_state=initialGuessedWordState, letters_guessed=['S', 'A', 'W', 'O', 'R', 'C'], guesses_allowed=5, guesses_taken=2) game.handleGuess('T') self.assertEquals(expectedGuessedWordState, game.guessed_word_state)
def test_is_game_over_is_true_if_all_letters_guessed(self): initialLettersGuessed = ['H', 'E', 'L'] game = Game(word='HELLO', guessed_word_state=['H', 'E', 'L', 'L', ''], letters_guessed=initialLettersGuessed.copy(), guesses_allowed=5, guesses_taken=2) guess = 'O' game.handleGuess(guess) self.assertEqual(game.is_game_over, True)
def test_letters_guessed_should_add_guessed_letter_when_letter_not_in_word( self): initialLettersGuessed = ['S', 'A', 'W', 'O', 'R', 'C'] game = Game(word='TESTWORD', guessed_word_state=['', '', 'S', '', 'W', 'O', 'R', ''], letters_guessed=initialLettersGuessed.copy(), guesses_allowed=5, guesses_taken=2) guess = 'Q' game.handleGuess(guess) expectedLettersGuessed = initialLettersGuessed + [guess] self.assertEquals(game.letters_guessed, expectedLettersGuessed)
def test_available_letters_should_remove_guessed_letters_when_letter_not_in_word( self ): initialLettersAvailable = ['B', 'D', 'E', 'T', 'Q'] game = Game( word= 'TESTWORD', guessed_word_state= ['','','S','','W','O','R',''], letters_guessed = ['S', 'A', 'W', 'O', 'R','C'], letters_available = initialLettersAvailable, guesses_allowed= 5, guesses_taken= 2 ) guess = 'Q' game.handleGuess(guess) expectedLettersAvailable = [letter for letter in initialLettersAvailable if not letter in [guess]] self.assertEquals( game.letters_available, expectedLettersAvailable )