tests: Test handling of bad moves in connect four.
This commit tests that we throw a BadMoveException if you try to move into a "full" column in connect four. This gets the controller up to 100% coverage.
This commit is contained in:
parent
6df10749fb
commit
9175c451f6
|
@ -25,6 +25,13 @@ class ConnectFourModel(object):
|
||||||
def update_board(self, board):
|
def update_board(self, board):
|
||||||
self.current_board = deepcopy(board)
|
self.current_board = deepcopy(board)
|
||||||
|
|
||||||
|
def get_column(self, col):
|
||||||
|
# We use this in tests.
|
||||||
|
return [
|
||||||
|
self.current_board[i][col]
|
||||||
|
for i in range(6)
|
||||||
|
]
|
||||||
|
|
||||||
def validate_move(self, column_number):
|
def validate_move(self, column_number):
|
||||||
if column_number < 0 or column_number > 6:
|
if column_number < 0 or column_number > 6:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -3,6 +3,7 @@ from zulip_bots.test_lib import BotTestCase
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
from zulip_bots.bots.connect_four.connect_four import *
|
from zulip_bots.bots.connect_four.connect_four import *
|
||||||
|
from zulip_bots.game_handler import BadMoveException
|
||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
|
|
||||||
|
|
||||||
|
@ -479,3 +480,24 @@ The first player to get 4 in a row wins!\n Good Luck!')
|
||||||
confirmWinStates(vertical_win_boards)
|
confirmWinStates(vertical_win_boards)
|
||||||
confirmWinStates(major_diagonal_win_boards)
|
confirmWinStates(major_diagonal_win_boards)
|
||||||
confirmWinStates(minor_diagonal_win_boards)
|
confirmWinStates(minor_diagonal_win_boards)
|
||||||
|
|
||||||
|
def test_more_logic(self) -> None:
|
||||||
|
model = ConnectFourModel()
|
||||||
|
move = 'move 4'
|
||||||
|
col = 3 # zero-indexed
|
||||||
|
|
||||||
|
self.assertEqual(model.get_column(col), [0, 0, 0, 0, 0, 0])
|
||||||
|
model.make_move(move, player_number=0)
|
||||||
|
self.assertEqual(model.get_column(col), [0, 0, 0, 0, 0, 1])
|
||||||
|
model.make_move(move, player_number=0)
|
||||||
|
self.assertEqual(model.get_column(col), [0, 0, 0, 0, 1, 1])
|
||||||
|
model.make_move(move, player_number=1)
|
||||||
|
self.assertEqual(model.get_column(col), [0, 0, 0, -1, 1, 1])
|
||||||
|
model.make_move(move, player_number=1)
|
||||||
|
self.assertEqual(model.get_column(col), [0, 0, -1, -1, 1, 1])
|
||||||
|
model.make_move(move, player_number=1)
|
||||||
|
self.assertEqual(model.get_column(col), [0, -1, -1, -1, 1, 1])
|
||||||
|
model.make_move(move, player_number=0)
|
||||||
|
self.assertEqual(model.get_column(col), [1, -1, -1, -1, 1, 1])
|
||||||
|
with self.assertRaises(BadMoveException):
|
||||||
|
model.make_move(move, player_number=0)
|
||||||
|
|
Loading…
Reference in a new issue