def test_shoot_valid(): board = Board(BOARD_SIZE) board.shoot(Point(7, 4)) board.shoot(Point(0, BOARD_SIZE - 1)) assert board.shot_locations == {Point(7, 4), Point(0, BOARD_SIZE - 1)}
def test_shoot_invalid_already_shot(): board = Board(BOARD_SIZE) board.shoot(Point(1, 1)) board.shoot(Point(5, 2)) with pytest.raises(InvalidShotException): board.shoot(Point(1, 1))
def test_game_is_won(): board = Board(BOARD_SIZE) assert board.is_board_lost() is False board.place_ship(Destroyer(), Point(5, 1), Orientation.Horizontal) assert board.is_board_lost() is False board.shoot(Point(5, 1)) assert board.is_board_lost() is False board.shoot(Point(5, 2)) assert board.is_board_lost() is True board.shoot(Point(BOARD_SIZE - 1, BOARD_SIZE - 1)) assert board.is_board_lost() is True
def test_shoot_invalid_off_board(): board = Board(BOARD_SIZE) with pytest.raises(InvalidShotException): board.shoot(Point(BOARD_SIZE, BOARD_SIZE))