Пример #1
0
class BoardRowRetrievalTests(unittest.TestCase):

    def setUp(self):
        self.board = Board()

    def test_getting_all_horizontal_rows(self):
        expected_rows = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

        self.assertEqual(expected_rows, self.board.horizontal_rows())

    def test_getting_all_vertical_rows(self):
        expected_rows = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

        self.assertEqual(expected_rows, self.board.vertical_rows())

    def test_getting_all_diagonal_rows(self):
        expected_rows = [[1, 5, 9], [3, 5, 7]]

        self.assertEqual(expected_rows, self.board.diagonal_rows())

    def test_getting_all_rows_columns_and_diagonals(self):
        expected_rows = [
                          [1, 2, 3], [4, 5, 6], [7, 8, 9],
                          [1, 4, 7], [2, 5, 8], [3, 6, 9],
                          [1, 5, 9], [3, 5, 7]
                        ]

        self.assertEqual(expected_rows, self.board.get_all_rows())
Пример #2
0
class ComputerMoveChoiceTests(unittest.TestCase):

    def setUp(self):
        self.computer = Computer("O")
        self.board = Board()
        self.mock_presenter = MagicMock()
        self.mock_presenter.computer_move_message = MagicMock()

    def test_computer_chooses_moves_from_available_spots(self):
        self.board.spots =[1, "X", "X", "O", "X", "O", "O", "O", "X"]
        available_spots = self.board.available_spots()
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertTrue(chosen_move in self.board.spots)

    def test_computer_choses_first_move_optimally(self):
        optimal_moves = [1, 3, 5, 7, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertTrue(chosen_move in optimal_moves)

    def test_computer_chooses_obvious_win(self):
        self.board.spots =[1, "X", "X", "O", "X", "O", "O", "O", "X"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(1, chosen_move)

    def test_computer_chooses_winning_row_move(self):
        self.board.spots = ["X", "X", 3, 4, "X", 6, 7, "O", "O"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(7, chosen_move)

    def test_computer_chooses_winning_column_move(self):
        self.board.spots = ["X", 2, "O", "X", "O", 6, 7, 8, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(7, chosen_move)

    def test_computer_chooses_winning_diagonal_move(self):
        self.board.spots = [1, 2, "X", 4, "X", "O", "O", "O", "X"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(1, chosen_move)

    def test_computer_takes_win_over_block(self):
        self.board.spots = ["X", "X", 3, 4, "X", 6, "O", "O", 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(9, chosen_move)

    def test_computer_takes_win_over_fork(self):
        self.board.spots = ["X", 2, "X", "O", "O", 6, "X", 8, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(6, chosen_move)
Пример #3
0
class ComputerMoveChoiceTests(unittest.TestCase):
    def setUp(self):
        self.computer = Computer("O")
        self.board = Board()
        self.mock_presenter = MagicMock()
        self.mock_presenter.computer_move_message = MagicMock()

    def test_computer_chooses_moves_from_available_spots(self):
        self.board.spots = [1, "X", "X", "O", "X", "O", "O", "O", "X"]
        available_spots = self.board.available_spots()
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertTrue(chosen_move in self.board.spots)

    def test_computer_choses_first_move_optimally(self):
        optimal_moves = [1, 3, 5, 7, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertTrue(chosen_move in optimal_moves)

    def test_computer_chooses_obvious_win(self):
        self.board.spots = [1, "X", "X", "O", "X", "O", "O", "O", "X"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(1, chosen_move)

    def test_computer_chooses_winning_row_move(self):
        self.board.spots = ["X", "X", 3, 4, "X", 6, 7, "O", "O"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(7, chosen_move)

    def test_computer_chooses_winning_column_move(self):
        self.board.spots = ["X", 2, "O", "X", "O", 6, 7, 8, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(7, chosen_move)

    def test_computer_chooses_winning_diagonal_move(self):
        self.board.spots = [1, 2, "X", 4, "X", "O", "O", "O", "X"]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(1, chosen_move)

    def test_computer_takes_win_over_block(self):
        self.board.spots = ["X", "X", 3, 4, "X", 6, "O", "O", 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(9, chosen_move)

    def test_computer_takes_win_over_fork(self):
        self.board.spots = ["X", 2, "X", "O", "O", 6, "X", 8, 9]
        chosen_move = self.computer.get_move(self.mock_presenter, self.board)

        self.assertEqual(6, chosen_move)
Пример #4
0
class BoardTests(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        self.default_spots = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    def test_board_initializes_with_spots(self):
        self.assertEqual(self.default_spots, self.board.spots)

    def test_board_can_have_spots_injected(self):
        spots_to_inject = ["X", 2, "O", 4, 5, 6, 7, 8, 9]
        board = Board(spots_to_inject)

        self.assertEqual(spots_to_inject, board.spots)

    def test_available_spots_list(self):
        self.assertEqual(self.default_spots, self.board.available_spots())

        self.board.place_move("X", 5)
        available_spots = [1, 2, 3, 4, 6, 7, 8, 9]

        self.assertEqual(available_spots, self.board.available_spots())
Пример #5
0
class BoardTests(unittest.TestCase):

    def setUp(self):
        self.board = Board()
        self.default_spots = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    def test_board_initializes_with_spots(self):
        self.assertEqual(self.default_spots, self.board.spots)

    def test_board_can_have_spots_injected(self):
        spots_to_inject = ["X", 2, "O", 4, 5, 6, 7, 8, 9]
        board = Board(spots_to_inject)

        self.assertEqual(spots_to_inject, board.spots)

    def test_available_spots_list(self):
        self.assertEqual(self.default_spots, self.board.available_spots())

        self.board.place_move("X", 5)
        available_spots = [1, 2, 3, 4, 6, 7, 8, 9]

        self.assertEqual(available_spots, self.board.available_spots())
Пример #6
0
class BoardRowRetrievalTests(unittest.TestCase):
    def setUp(self):
        self.board = Board()

    def test_getting_all_horizontal_rows(self):
        expected_rows = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

        self.assertEqual(expected_rows, self.board.horizontal_rows())

    def test_getting_all_vertical_rows(self):
        expected_rows = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

        self.assertEqual(expected_rows, self.board.vertical_rows())

    def test_getting_all_diagonal_rows(self):
        expected_rows = [[1, 5, 9], [3, 5, 7]]

        self.assertEqual(expected_rows, self.board.diagonal_rows())

    def test_getting_all_rows_columns_and_diagonals(self):
        expected_rows = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8],
                         [3, 6, 9], [1, 5, 9], [3, 5, 7]]

        self.assertEqual(expected_rows, self.board.get_all_rows())
Пример #7
0
class BoardMovementTests(unittest.TestCase):
    def setUp(self):
        self.board = Board()

    def test_placing_moves_on_board(self):
        self.board.place_move("X", 1)

        self.assertEqual("X", self.board.spots[0])

    def test_check_if_spot_is_available(self):
        self.board.place_move("O", 5)

        self.assertTrue(self.board.is_spot_available(1))
        self.assertFalse(self.board.is_spot_available(5))
Пример #8
0
class BoardMovementTests(unittest.TestCase):

    def setUp(self):
        self.board = Board()

    def test_placing_moves_on_board(self):
        self.board.place_move("X",1)

        self.assertEqual("X", self.board.spots[0])

    def test_check_if_spot_is_available(self):
        self.board.place_move("O", 5)

        self.assertTrue(self.board.is_spot_available(1))
        self.assertFalse(self.board.is_spot_available(5))
Пример #9
0
 def setUp(self):
     self.board = Board()
Пример #10
0
 def setUp(self):
     self.board = Board()
     self.default_spots = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Пример #11
0
 def setUp(self):
     self.board = Board()
Пример #12
0
 def setUp(self):
     self.computer = Computer("O")
     self.board = Board()
Пример #13
0
 def setUp(self):
     self.computer = Computer("O")
     self.board = Board()
     self.mock_presenter = MagicMock()
     self.mock_presenter.computer_move_message = MagicMock()
Пример #14
0
 def setUp(self):
     self.board = Board()
     self.default_spots = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Пример #15
0
 def setUp(self):
     self.computer = Computer("X")
     self.board = Board()
     self.winning_spots = ["X", "X", 3, 4, "X", 6, "O", "O", "O"]
Пример #16
0
 def setUp(self):
     self.computer = Computer("O")
     self.board = Board()
     self.mock_presenter = MagicMock()
     self.mock_presenter.computer_move_message = MagicMock()
Пример #17
0
    def test_board_can_have_spots_injected(self):
        spots_to_inject = ["X", 2, "O", 4, 5, 6, 7, 8, 9]
        board = Board(spots_to_inject)

        self.assertEqual(spots_to_inject, board.spots)