import unittest from board import Board class TestIsMoveValid(unittest.TestCase): def test_simple_movement(self): board = Board.initial_state self.assertEqual(Board.is_move_valid(board, 1, 2, (1, 3)), True) # White self.assertEqual(Board.is_move_valid(board, -1, 3, (24, 21)), True) # Black def test_backwards_movement_invalid(self): board = Board.initial_state self.assertEqual(Board.is_move_valid(board, 1, 2, (12, 10)), False) self.assertEqual(Board.is_move_valid(board, -1, 3, (8, 11)), False) def test_face_value_match_move_length(self): board = Board.initial_state self.assertEqual(Board.is_move_valid(board, 1, 2, (1, 3)), True) self.assertEqual(Board.is_move_valid(board, 1, 2, (1, 4)), False) def test_bear_in(self): board = [ 1, 1, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -2, 0 ] self.assertEqual(Board.is_move_valid(board, 1, 2, (0, 2)), True) board = [ 0, 2, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -1, -1 ] self.assertEqual(Board.is_move_valid(board, -1, 2, (25, 23)), True) def test_force_bear_in(self): board = [ 1, 1, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -2, 0 ] self.assertEqual(Board.is_move_valid(board, 1, 2, (1, 3)), False) self.assertEqual(Board.is_move_valid(board, -1, 3, (24, 21)), True) board = [ 0, 2, 0, 0, 0, 0, -5, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 5, 0, 0, 0, 0, -1, -1 ] self.assertEqual(Board.is_move_valid(board, -1, 2, (24, 22)), False) self.assertEqual(Board.is_move_valid(board, 1, 2, (1, 3)), True) def test_owned_checker_at_from(self): board = Board.initial_state self.assertEqual(Board.is_move_valid(board, 1, 2, (3, 5)), False) # No checkers self.assertEqual(Board.is_move_valid(board, -1, 2, (23, 21)), False) # No checkers self.assertEqual(Board.is_move_valid(board, 1, 2, (8, 10)), False) # Opponent checkers self.assertEqual(Board.is_move_valid(board, -1, 2, (1, 3)), False) # Opponent checkers def test_no_block_at_to(self): board = Board.initial_state self.assertEqual(Board.is_move_valid(board, 1, 5, (1, 6)), False) self.assertEqual(Board.is_move_valid(board, -1, 5, (24, 19)), False) def test_able_to_hit_opponent_checkers(self): board = [ 0, 2, 0, 0, -1, 0, -4, 0, -3, 0, 0, 0, 5, -5, 0, 0, 0, 3, 0, 4, 0, 1, 0, 0, -2, 0 ] self.assertEqual(Board.is_move_valid(board, 1, 3, (1, 4)), True) self.assertEqual(Board.is_move_valid(board, -1, 3, (24, 21)), True) def test_bear_off_simple(self): board = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ] self.assertEqual(Board.is_move_valid(board, 1, 2, (24, 26)), True) self.assertEqual(Board.is_move_valid(board, 1, 1, (24, 25)), True) # TODO: More tests for bearing off are needed if __name__ == '__main__': unittest.main()