Ejemplo n.º 1
0
    def test_that_players_dont_move_when_game_over(self):
        board = BaseBoard(3)
        board.set_state({1:"x",2:"o",3:"x",
			                   4:"o",5:"x",6:"o",
				                 7:"x",8:"o",9:"x"})
        game = Game(self.player_one,self.player_two,board)
        game.run()
        self.assertFalse(self.player_one.next_move.called)
        self.assertFalse(self.player_two.next_move.called)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_that_players_dont_move_when_game_over(self):
     board = BaseBoard(3)
     board.set_state({
         1: "x",
         2: "o",
         3: "x",
         4: "o",
         5: "x",
         6: "o",
         7: "x",
         8: "o",
         9: "x"
     })
     game = Game(self.player_one, self.player_two, board)
     game.run()
     self.assertFalse(self.player_one.next_move.called)
     self.assertFalse(self.player_two.next_move.called)
Ejemplo n.º 5
0
 def test_set_state_doesnt_alter_original_object(self):
     board = BaseBoard(3)
     original_state = {"state":"stuff"}
     board.set_state(original_state)
     board.make_move(2,"x")
     self.assertEqual({"state":"stuff"}, original_state)
Ejemplo n.º 6
0
 def test_set_state(self):
     board = BaseBoard(3)
     self.assertEqual({},board.state())
     board.set_state({1:"x"})
     self.assertEqual({1:"x"},board.state())