コード例 #1
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_new_game(self):
     game = HangmanGame(word='moo')
     for event in ('m', 'o', '-'):
         game.event(event)
     self.assertEqual(
         game.state(), mkstate('moo', 'mo', 'Flawless victory!'))
     self.assertEqual(game.exit_code, game.DONE_WANTS_NEW)
コード例 #2
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_")
コード例 #3
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_incorrect_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('g')
     self.assertFalse(game.won())
     self.assertEqual(
         game.state(), mkstate('moo', 'fg', "Word contains no 'g'. :("))
コード例 #4
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_repeated_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('f')
     self.assertFalse(game.won())
     self.assertEqual(
         game.state(), mkstate('moo', 'f', "You've already guessed 'f'."))
コード例 #5
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 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_")
コード例 #6
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_easy_game(self):
     game = HangmanGame(word='moo')
     game.event('m')
     game.event('o')
     self.assertTrue(game.won())
     self.assertEqual(
         game.state(), mkstate('moo', 'mo', 'Flawless victory!'))
コード例 #7
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 def test_new_game(self):
     game = HangmanGame(word='moo')
     for event in ('m', 'o', '-'):
         game.event(event)
     self.assertEqual(game.state(), mkstate('moo', 'mo',
                                            'Flawless victory!'))
     self.assertEqual(game.exit_code, game.DONE_WANTS_NEW)
コード例 #8
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 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):")
コード例 #9
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):")
コード例 #10
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 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):")
コード例 #11
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):")
コード例 #12
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)
コード例 #13
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_from_state_non_ascii(self):
     game = HangmanGame.from_state(
         mkstate("b\xc3\xa4r".decode("utf-8"), "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)
コード例 #14
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
    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'. :(")
コード例 #15
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 def test_from_state_non_ascii(self):
     game = HangmanGame.from_state(
         mkstate("b\xc3\xa4r".decode("utf-8"), "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)
コード例 #16
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 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(), mkstate('moo', string.lowercase, "Button mashing!"))
コード例 #17
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 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())
コード例 #18
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 def test_easy_game(self):
     game = HangmanGame(word='moo')
     game.event('m')
     game.event('o')
     self.assertTrue(game.won())
     self.assertEqual(game.state(), mkstate('moo', 'mo',
                                            'Flawless victory!'))
コード例 #19
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 def test_incorrect_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('g')
     self.assertFalse(game.won())
     self.assertEqual(game.state(),
                      mkstate('moo', 'fg', "Word contains no 'g'. :("))
コード例 #20
0
ファイル: test_hangman.py プロジェクト: musabaloyi/vumi
 def test_repeated_guesses(self):
     game = HangmanGame(word='moo')
     game.event('f')
     game.event('f')
     self.assertFalse(game.won())
     self.assertEqual(game.state(),
                      mkstate('moo', 'f', "You've already guessed 'f'."))
コード例 #21
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 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())
コード例 #22
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)
コード例 #23
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"))
コード例 #24
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"))
コード例 #25
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"))
コード例 #26
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'. :(")
コード例 #27
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_exit(self):
     game = HangmanGame('elephant')
     game.event('0')
     self.assertEqual(game.exit_code, game.DONE)
     self.assertEqual(game.draw_board(), "Adieu!")
コード例 #28
0
 def test_exit(self):
     game = HangmanGame('elephant')
     game.event('0')
     self.assertEqual(game.exit_code, game.DONE)
     self.assertEqual(game.draw_board(), "Adieu!")
コード例 #29
0
ファイル: test_hangman.py プロジェクト: BantouTelecom/vumi
 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"))
コード例 #30
0
ファイル: test_hangman.py プロジェクト: AndrewCvekl/vumi
 def test_from_state(self):
     game = HangmanGame.from_state(mkstate("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)
コード例 #31
0
ファイル: test_hangman.py プロジェクト: BantouTelecom/vumi
 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"))
コード例 #32
0
ファイル: test_hangman.py プロジェクト: BantouTelecom/vumi
 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"))