<commit_before>from chess.core.moving import move
from chess.core.models import Coordinate, Piece
from chess.core.game import Game
from chess.core.possible_destinations import destinations
from chess.core.utils import _, K, k, Q, q, R, r, N, n, B, b, P, p, piece_at


def test_castling_left_white_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest in destinations(game, white_king_src))

    move(game, white_king_src, white_king_dest)

    assert(piece_at(game.board, white_rook_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_dest) == Piece.WHITE_KING)
    assert(piece_at(game.board, white_king_dest.right()) == Piece.WHITE_ROOK)


def test_castling_right_white_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, R]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.right().right()
    white_rook_src = Coordinate(7, 7)

    assert(white_king_dest in destinations(game, white_king_src))

    move(game, white_king_src, white_king_dest)

    assert(piece_at(game.board, white_rook_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_dest) == Piece.WHITE_KING)
    assert(piece_at(game.board, white_king_dest.left()) == Piece.WHITE_ROOK)


def test_castling_left_black_rook():
    game = Game()
    game.board = [[r, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, _]]
    black_king_src = Coordinate(0, 4)
    black_king_dest = black_king_src.left().left()
    black_rook_src = Coordinate(0, 0)

    assert(black_king_dest in destinations(game, black_king_src))

    move(game, black_king_src, black_king_dest)

    assert(piece_at(game.board, black_rook_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_dest) == Piece.BLACK_KING)
    assert(piece_at(game.board, black_king_dest.right()) == Piece.BLACK_ROOK)


def test_castling_right_black_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, r],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, _]]
    black_king_src = Coordinate(0, 4)
    black_king_dest = black_king_src.right().right()
    black_rook_src = Coordinate(0, 7)

    assert(black_king_dest in destinations(game, black_king_src))

    move(game, black_king_src, black_king_dest)

    assert(piece_at(game.board, black_rook_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_dest) == Piece.BLACK_KING)
    assert(piece_at(game.board, black_king_dest.left()) == Piece.BLACK_ROOK)


def test_no_castling_allowed_when_path_is_blocked():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, B, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest not in destinations(game, white_king_src))


def test_no_castling_allowed_when_in_check():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, p, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest not in destinations(game, white_king_src))


def test_no_castling_allowed_when_king_has_moved():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    move(game, white_king_src, white_king_src.up())
    move(game, white_king_src.up(), white_king_src)

    assert(white_king_dest not in destinations(game, white_king_src))

def test_no_castling_allowed_when_rook_has_moved():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    move(game, white_rook_src, white_rook_src.up())
    move(game, white_rook_src.up(), white_rook_src)

    assert(white_king_dest not in destinations(game, white_king_src))<commit_msg>:art: #81 Conserta code style<commit_after>from chess.core.moving import move
from chess.core.models import Coordinate, Piece
from chess.core.game import Game
from chess.core.possible_destinations import destinations
from chess.core.utils import _, K, k, Q, q, R, r, N, n, B, b, P, p, piece_at


def test_castling_left_white_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest in destinations(game, white_king_src))

    move(game, white_king_src, white_king_dest)

    assert(piece_at(game.board, white_rook_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_dest) == Piece.WHITE_KING)
    assert(piece_at(game.board, white_king_dest.right()) == Piece.WHITE_ROOK)


def test_castling_right_white_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, R]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.right().right()
    white_rook_src = Coordinate(7, 7)

    assert(white_king_dest in destinations(game, white_king_src))

    move(game, white_king_src, white_king_dest)

    assert(piece_at(game.board, white_rook_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_src) == Piece.NONE)
    assert(piece_at(game.board, white_king_dest) == Piece.WHITE_KING)
    assert(piece_at(game.board, white_king_dest.left()) == Piece.WHITE_ROOK)


def test_castling_left_black_rook():
    game = Game()
    game.board = [[r, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, _]]
    black_king_src = Coordinate(0, 4)
    black_king_dest = black_king_src.left().left()
    black_rook_src = Coordinate(0, 0)

    assert(black_king_dest in destinations(game, black_king_src))

    move(game, black_king_src, black_king_dest)

    assert(piece_at(game.board, black_rook_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_dest) == Piece.BLACK_KING)
    assert(piece_at(game.board, black_king_dest.right()) == Piece.BLACK_ROOK)


def test_castling_right_black_rook():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, r],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, K, _, _, _]]
    black_king_src = Coordinate(0, 4)
    black_king_dest = black_king_src.right().right()
    black_rook_src = Coordinate(0, 7)

    assert(black_king_dest in destinations(game, black_king_src))

    move(game, black_king_src, black_king_dest)

    assert(piece_at(game.board, black_rook_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_src) == Piece.NONE)
    assert(piece_at(game.board, black_king_dest) == Piece.BLACK_KING)
    assert(piece_at(game.board, black_king_dest.left()) == Piece.BLACK_ROOK)


def test_no_castling_allowed_when_path_is_blocked():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, B, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest not in destinations(game, white_king_src))


def test_no_castling_allowed_when_in_check():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, p, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    assert(white_king_dest not in destinations(game, white_king_src))


def test_no_castling_allowed_when_king_has_moved():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    move(game, white_king_src, white_king_src.up())
    move(game, white_king_src.up(), white_king_src)

    assert(white_king_dest not in destinations(game, white_king_src))


def test_no_castling_allowed_when_rook_has_moved():
    game = Game()
    game.board = [[_, _, _, _, k, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [_, _, _, _, _, _, _, _],
                  [R, _, _, _, K, _, _, _]]
    white_king_src = Coordinate(7, 4)
    white_king_dest = white_king_src.left().left()
    white_rook_src = Coordinate(7, 0)

    move(game, white_rook_src, white_rook_src.up())
    move(game, white_rook_src.up(), white_rook_src)

    assert(white_king_dest not in destinations(game, white_king_src))
{'fraction_non_alphanumeric': 0.16451154794827716, 'fraction_numerical': 0.004933104118394499, 'mean_word_length': 2.014871563767463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2121423', 'n_tokens_mistral': 4715, 'n_tokens_neox': 4479, 'n_words': 545}