Exemple #1
0
 def test_displaying_word(self):
     game = HangmanGame('word')
     game.event('w')
     game.event('r')
     board = game.draw_board()
     _msg, word, _guesses, _prompt, _end = board.split("\n")
     self.assertEqual(word, "Word: w_r_")
Exemple #2
0
 def test_draw_board(self):
     game = HangmanGame('word')
     board = game.draw_board()
     msg, word, guesses, prompt, end = board.split("\n")
     self.assertEqual(msg, "New game!")
     self.assertEqual(word, "Word: ____")
     self.assertEqual(guesses, "Letters guessed so far: ")
     self.assertEqual(prompt, "Enter next guess (0 to quit):")
Exemple #3
0
 def test_draw_board_at_end_of_game(self):
     game = HangmanGame('m')
     game.event('m')
     board = game.draw_board()
     msg, word, guesses, prompt, end = board.split("\n")
     self.assertEqual(msg, "Flawless victory!")
     self.assertEqual(word, "Word: m")
     self.assertEqual(guesses, "Letters guessed so far: m")
     self.assertEqual(prompt, "Enter anything to start a new game"
                              " (0 to quit):")
Exemple #4
0
    def test_displaying_guesses(self):
        game = HangmanGame('word')
        game.event('w')
        board = game.draw_board()
        msg, _word, _guesses, _prompt, _end = board.split("\n")
        self.assertEqual(msg, "Word contains at least one 'w'! :D")

        game.event('w')
        board = game.draw_board()
        msg, _word, _guesses, _prompt, _end = board.split("\n")
        self.assertEqual(msg, "You've already guessed 'w'.")

        game.event('x')
        board = game.draw_board()
        msg, _word, _guesses, _prompt, _end = board.split("\n")
        self.assertEqual(msg, "Word contains no 'x'. :(")
Exemple #5
0
 def test_button_mashing(self):
     game = HangmanGame(word='moo')
     for event in string.lowercase.replace('o', ''):
         game.event(event)
     game.event('o')
     self.assertTrue(game.won())
     self.assertEqual(game.state(),
                      "moo:%s:Button mashing!" % string.lowercase)
Exemple #6
0
 def test_garbage_input(self):
     game = HangmanGame(word="zoo")
     for garbage in [
         ":", "!", "\x00", "+", "abc", "",
         ]:
         game.event(garbage)
     self.assertEqual(game.guesses, set())
     game.event('z')
     game.event('o')
     self.assertTrue(game.won())
Exemple #7
0
 def test_exit(self):
     game = HangmanGame('elephant')
     game.event('0')
     self.assertEqual(game.exit_code, game.DONE)
     self.assertEqual(game.draw_board(), "Adieu!")
Exemple #8
0
 def test_from_state_non_ascii(self):
     game = HangmanGame.from_state("b\xc3\xa4r:xyz:Eep?")
     self.assertEqual(game.word, u"b\u00e4r")
     self.assertEqual(game.guesses, set("xyz"))
     self.assertEqual(game.msg, "Eep?")
     self.assertEqual(game.exit_code, game.NOT_DONE)
Exemple #9
0
 def test_from_state(self):
     game = HangmanGame.from_state("bar:xyz:Eep?")
     self.assertEqual(game.word, "bar")
     self.assertEqual(game.guesses, set("xyz"))
     self.assertEqual(game.msg, "Eep?")
     self.assertEqual(game.exit_code, game.NOT_DONE)
Exemple #10
0
 def test_new_game(self):
     game = HangmanGame(word='moo')
     for event in ('m', 'o', '-'):
         game.event(event)
     self.assertEqual(game.state(), 'moo:mo:Flawless victory!')
     self.assertEqual(game.exit_code, game.DONE_WANTS_NEW)
Exemple #11
0
 def test_repeated_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('f')
     self.assertFalse(game.won())
     self.assertTrue(game.state().startswith("moo:f:You've already"))
Exemple #12
0
 def test_incorrect_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('g')
     self.assertFalse(game.won())
     self.assertTrue(game.state().startswith("moo:fg:Word contains no"))
Exemple #13
0
 def test_easy_game(self):
     game = HangmanGame(word='moo')
     game.event('m')
     game.event('o')
     self.assertTrue(game.won())
     self.assertTrue(game.state().startswith("moo:mo:Flawless"))