Пример #1
0
 def test_that_board_is_printed_when_game_not_over(self):
     fake_printer = FakePrinter()
     fake_player_one = MockPlayer("x", self.user_input([1, 2, 3]))
     fake_player_two = MockPlayer("o", self.user_input([4, 5]))
     game = Game(fake_player_one, fake_player_two, prompter=fake_printer)
     game.run()
     self.assertTrue(len(fake_printer.history) >= 6)
Пример #2
0
 def test_that_game_prints_tie(self):
     fake_player_one = MockPlayer("x", self.user_input([1, 6, 8, 7, 5]))
     fake_player_two = MockPlayer("o", self.user_input([2, 3, 4, 9]))
     fake_printer = FakePrinter()
     game = Game(fake_player_one, fake_player_two, prompter=fake_printer)
     game.run()
     self.assertEqual(None, game.board.winner())
     self.assertTrue("It's a tie." in fake_printer.history)
Пример #3
0
 def test_that_game_displays_winner(self):
     self.player_one.next_move.side_effect = [1, 2, 3]
     self.player_two.next_move.side_effect = [4, 5]
     fake_printer = FakePrinter()
     game = Game(self.player_one, self.player_two, prompter=fake_printer)
     game.run()
     self.assertEqual("x", game.board.winner())
     self.assertTrue("x wins" in fake_printer.history)
Пример #4
0
 def test_that_game_prints_board_after_each_set_of_rounds(self):
     self.player_one.next_move.side_effect = [1, 2, 3]
     self.player_two.next_move.side_effect = [4, 5]
     fake_printer = FakePrinter()
     game = Game(self.player_one, self.player_two, prompter=fake_printer)
     game.run()
     # Two sets of rounds plus final print
     self.assertTrue(len(fake_printer.history) >= 6)
Пример #5
0
 def test_that_board_isnt_printed_when_game_over(self):
     fake_printer = FakePrinter()
     fake_player_one = MockPlayer("x", self.user_input([1]))
     fake_player_two = MockPlayer("o", self.user_input([2]))
     game = Game(fake_player_one, fake_player_two, prompter=fake_printer)
     game.__print_board_if_game_not_over__()
     #Game gets printed once when game over
     self.assertEqual(1, len(fake_printer.history))
Пример #6
0
 def test_that_board_is_printed_when_game_is_over(self):
     self.player_one.next_move = mock.MagicMock(return_value=1)
     self.player_two.next_move = mock.MagicMock(return_value=3)
     board = BaseBoard(3)
     board.set_state({1: "x", 2: "x", 3: "x"})
     fake_printer = FakePrinter()
     game = Game(self.player_one,
                 self.player_two,
                 board,
                 prompter=fake_printer)
     game.run()
     self.assertEqual(True, game.__over__())
     expected_string = game.board.__str__()
     self.assertTrue(expected_string in fake_printer.history)
Пример #7
0
 def test_prompter_receives_output_object(self):
     printer = FakePrinter()
     prompter = Prompter(display_object=printer)
     prompter.display("What's up")
     self.assertEqual("What's up",printer.last_print())
Пример #8
0
 def setUp(self):
     self.fake_printer = FakePrinter()
     mock = MockUserInput([" "] * 20)
     self.prompter = Prompter(self.fake_printer, mock)
Пример #9
0
 def test_prompter_receives_output_object(self):
     printer = FakePrinter()
     prompter = Prompter(display_object=printer)
     prompter.display("What's up")
     self.assertEqual("What's up", printer.last_print())