diff --git a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py index 6099224..4b864b9 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py @@ -10,6 +10,91 @@ class TestTicTacToeBot(BotTestCase, DefaultTests): # FIXME: Add tests for computer moves # FIXME: Add test lib for game_handler + # Tests for TicTacToeModel functions + # Things that might need to be checked: how model is being used in these functions, + # When running the tests, many of the failures involved current_board. This + # may need to be initialized prior to the constructor initialization in order to + # avoid these errors. + + def test_get_value(self) -> None: + board = [[0, 1, 0], + [0, 0, 0], + [0, 0, 2]] + position = (0, 1) + response = 1 + self._test_get_value(board, position, response) + + def _test_get_value(self, board: List[List[int]], position: Tuple[int, int], expected_response: int) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.get_value(board, position) + self.assertEqual(response, expected_response) + + def test_determine_game_over_with_win(self) -> None: + board = [[1, 1, 1], + [0, 2, 0], + [2, 0, 2]] + players = ['Human', 'Computer'] + response = 'current turn' + self._test_determine_game_over_with_win(board, players, response) + + def _test_determine_game_over_with_win(self, board: List[List[int]], players: List[str], expected_response: str) -> None: + model, message_handler = self._get_game_handlers() + tictactoegame = model(board) + response = tictactoegame.determine_game_over(players) + self.assertEqual(response, expected_response) + + def test_determine_game_over_with_draw(self) -> None: + board = [[1, 2, 1], + [1, 2, 1], + [2, 1, 2]] + players = ['Human', 'Computer'] + response = 'draw' + self._test_determine_game_over_with_draw(board, players, response) + + def _test_determine_game_over_with_draw(self, board: List[List[int]], players: List[str], expected_response: str) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.determine_game_over(players) + self.assertEqual(response, expected_response) + + def test_board_is_full(self) -> None: + board = [[1, 0, 1], + [1, 2, 1], + [2, 1, 2]] + response = False + self._test_board_is_full(board, response) + + def _test_board_is_full(self, board: List[List[int]], expected_response: bool) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.board_is_full(board) + self.assertEqual(response, expected_response) + + def test_contains_winning_move(self) -> None: + board = [[1, 1, 1], + [0, 2, 0], + [2, 0, 2]] + response = True + self._test_contains_winning_move(board, response) + + def _test_contains_winning_move(self, board: List[List[int]], expected_response: bool) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.contains_winning_move(board) + self.assertEqual(response, expected_response) + + def test_player_color(self) -> None: + turn = 0 + response = ':cross_mark_button:' + self._test_player_color(turn, response) + + def _test_player_color(self, turn: int, expected_response: str) -> None: + model, message_handler = self._get_game_handlers() + response = message_handler.get_player_color(0) + + self.assertEqual(response, expected_response) + def test_static_responses(self) -> None: model, message_handler = self._get_game_handlers() self.assertNotEqual(message_handler.get_player_color(0), None) @@ -39,11 +124,6 @@ class TestTicTacToeBot(BotTestCase, DefaultTests): response = message_handler.parse_board(board) self.assertEqual(response, expected_response) - def _test_determine_game_over(self, board: List[List[int]], players: List[str], expected_response: str) -> None: - model, message_handler = self._get_game_handlers() - response = model.determine_game_over(players) - self.assertEqual(response, expected_response) - def add_user_to_cache(self, name: str, bot: Any=None) -> Any: if bot is None: bot, bot_handler = self._get_handlers()