Exemplo n.º 1
0
 def test_get_win_diagonal_win(self):
     board = Board()
     player = "X"
     moves = ["A3", "B2", "C1"]
     for move in moves:
         board.make_move(move, player)
     self.assertEqual(player, board.get_win(), "Game should be won by X.")
Exemplo n.º 2
0
 def test_get_win_no_win(self):
     board = Board()
     player = "X"
     moves = ["A1", "B1", "C3"]
     for move in moves:
         board.make_move(move, player)
     self.assertFalse(board.get_win(), "Game should not be won yet.")
Exemplo n.º 3
0
 def test_get_win_horizontal_win(self):
     board = Board()
     player = "X"
     moves = ["A1", "A2", "A3"]
     for move in moves:
         board.make_move(move, player)
     self.assertEqual(player, board.get_win(), "Game should be won by X.")
Exemplo n.º 4
0
 def test_get_opposite_side(self):
     board = Board()
     tile = "C2"
     expected_opposite = "A2"
     opposite = board.get_opposite(tile)
     self.assertEqual(expected_opposite, opposite,
                      "Opposite of A1 should be C3")
Exemplo n.º 5
0
 def test_get_opposite_middle(self):
     board = Board()
     tile = "B2"
     expected_opposite = "B2"
     opposite = board.get_opposite(tile)
     self.assertEqual(expected_opposite, opposite,
                      "B2 has no opposite. (Should return itself)")
Exemplo n.º 6
0
 def test_make_all_valid_moves(self):
     board = Board()
     player = "X"
     valid_moves = ["A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "C3"]
     for move in valid_moves:
         return_boolean = board.make_move(move, player)
         self.assertTrue(return_boolean,
                         "All moves should have been valid.")
Exemplo n.º 7
0
 def test_get_set(self):
     board = Board()
     player = "X"
     moves = ["B2", "A2", "B1", "A3", "C3"]
     for move in moves:
         board.make_move(move, player)
     set_of_moves = board.get_set(player)
     self.assertCountEqual(moves, set_of_moves, "Should have same contents")
Exemplo n.º 8
0
 def test_make_move_valid(self):
     board = Board()
     move = "B3"
     player = "X"
     expected_board = [[
         ttt_config['empty'], ttt_config['empty'], ttt_config['empty']
     ], [ttt_config['empty'], ttt_config['empty'], ttt_config['empty']],
                       [ttt_config['empty'], "X", ttt_config['empty']]]
     return_boolean = board.make_move(move, player)
     self.assertTrue(return_boolean, "True means move was valid.")
     self.assertEqual(expected_board, board.board,
                      "Board should have new value.")
Exemplo n.º 9
0
 def test_make_move_invalid(self):
     board = Board()
     old_board = copy.copy(board.board)
     player = "X"
     invalid_moves = [
         "A0", "Z3", "AA", "22", 34, ("AB", "23"), ["A1", "B2"]
     ]
     for move in invalid_moves:
         return_boolean = board.make_move(move, player)
         self.assertFalse(return_boolean,
                          "Invalid moves should result in False.")
     self.assertEqual(old_board, board.board,
                      "Board should be same as before.")
Exemplo n.º 10
0
 def test_copy(self):
     board_one = Board()
     board_copy = copy.copy(board_one)
     self.assertIsNot(board_one, board_copy,
                      "Copy should be deepcopy, not the same instance.")
     self.assertIsNot(board_one.board, board_copy.board,
                      "Copy should be deepcopy, not the same instance.")
     self.assertEqual(board_one.board, board_copy.board,
                      "Copies of the board should contain same values.")
Exemplo n.º 11
0
 def test_initialization(self):
     board = Board()
     expected_board = [
         [ttt_config['empty'], ttt_config['empty'], ttt_config['empty']],
         [ttt_config['empty'], ttt_config['empty'], ttt_config['empty']],
         [ttt_config['empty'], ttt_config['empty'], ttt_config['empty']]
     ]
     self.assertEqual(expected_board, board.board,
                      "Board should contain only empty spaces.")
Exemplo n.º 12
0
 def test_get_win_tie(self):
     board = Board()
     player_one = "X"
     player_two = "O"
     moves_one = ["B2", "A2", "B1", "A3", "C3"]
     moves_two = ["A1", "C2", "B3", "C1"]
     for move in moves_one:
         board.make_move(move, player_one)
     for move in moves_two:
         board.make_move(move, player_two)
     self.assertEqual(board.TIE_TOKEN, board.get_win(),
                      "Game should be a tie.")
Exemplo n.º 13
0
 def test_get_adjacent_corner(self):
     board = Board()
     player_one = "X"
     player_two = "O"
     moves_one = ["B1", "B2", "B3"]
     moves_two = ["A1", "A2", "A3"]
     for move in moves_one:
         board.make_move(move, player_one)
     for move in moves_two:
         board.make_move(move, player_two)
     adjacent = board.get_adjacent("A1")
     expected_adjacent = [player_one, player_two]
     self.assertCountEqual(expected_adjacent, adjacent,
                           "Should contain one X token, one O token.")
Exemplo n.º 14
0
 def test_get_adjacent_middle(self):
     board = Board()
     player_one = "X"
     player_two = "O"
     moves_one = ["B1", "B2", "B3"]
     moves_two = ["A1", "A2", "A3"]
     for move in moves_one:
         board.make_move(move, player_one)
     for move in moves_two:
         board.make_move(move, player_two)
     adjacent = board.get_adjacent("B2")
     expected_adjacent = [
         player_one, player_two, player_one, ttt_config['empty']
     ]
     self.assertCountEqual(
         expected_adjacent, adjacent,
         "Should contain two X tokens, one O, one Free Space")
Exemplo n.º 15
0
 def test_get_set_empty(self):
     board = Board()
     player = "X"
     moves = []
     self.assertEqual(moves, board.get_set(player),
                      "No moves made means no moves found")