From 0e8347d44096d8a93d67ceb632c465d1479328f3 Mon Sep 17 00:00:00 2001 From: Sheehan Khan Date: Sun, 7 Apr 2019 19:05:46 -0400 Subject: [PATCH] bot tests: Improve test coverage for TicTacToeModel. This commit improves test coverage of from 41.66% to 50%. This commit is related to #417 --- .../bots/tictactoe/test_tictactoe.py | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py index 4b864b9..94ebe3f 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py @@ -84,6 +84,37 @@ class TestTicTacToeBot(BotTestCase, DefaultTests): response = tictactoeboard.contains_winning_move(board) self.assertEqual(response, expected_response) + def test_get_locations_of_char(self) -> None: + board = [[0, 0, 0], + [0, 0, 0], + [0, 0, 1]] + response = [[2, 2]] + self._test_get_locations_of_char(board, response) + + def _test_get_locations_of_char(self, board: List[List[int]], expected_response: List[List[int]]) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.get_locations_of_char(board, 1) + self.assertEqual(response, expected_response) + + def test_is_valid_move(self) -> None: + board = [[0, 0, 0], + [0, 0, 0], + [1, 0, 2]] + move = "1,2" + response = True + self._test_is_valid_move(board, move, response) + + move = "4,4" + response = False + self._test_is_valid_move(board, move, response) + + def _test_is_valid_move(self, board: List[List[int]], move: str, expected_response: bool) -> None: + model, message_handler = self._get_game_handlers() + tictactoeboard = model(board) + response = tictactoeboard.is_valid_move(move) + self.assertEqual(response, expected_response) + def test_player_color(self) -> None: turn = 0 response = ':cross_mark_button:' @@ -124,7 +155,7 @@ class TestTicTacToeBot(BotTestCase, DefaultTests): response = message_handler.parse_board(board) self.assertEqual(response, expected_response) - def add_user_to_cache(self, name: str, bot: Any=None) -> Any: + def add_user_to_cache(self, name: str, bot: Any = None) -> Any: if bot is None: bot, bot_handler = self._get_handlers() message = {