<commit_before># Copyright (C) 2016 <NAME>
# All rights reserved.
#
# This software may be modified and distributed under the
# terms of the three-clause BSD license. See LICENSE.txt

require './setup'

def test_castling_to_one_side original_board:,
                              works:,
                              row:,
                              king:,
                              rook:,
                              king_to_column:,
                              rook_to_column:

  null_pos  = PAIR[ZERO, ZERO]
  king_from = PAIR[FOUR, row]
  king_to   = PAIR[king_to_column, row]
  rook_from = PAIR[rook_to_column == THREE ? ZERO : SEVEN, row]
  rook_to   = PAIR[rook_to_column, row]
  result    = PERFORM_CASTLING[original_board, king_from, king_to, null_pos, null_pos]

  if works
    assert "king was moved" do
     piece_in_position = TO_MOVED_PIECE[king].to_i ==
                         GET_POSITION[result, king_to].to_i

     piece_in_position == works
    end

    assert "rook was moved" do
      piece_in_position = TO_MOVED_PIECE[rook].to_i ==
                          GET_POSITION[result, rook_to].to_i

      piece_in_position == works
    end

    assert "correct rook was moved" do
      piece_in_position = 0 == GET_POSITION[result, rook_from].to_i

      piece_in_position == works
    end
  else
    assert "board remains the same" do
     result == original_board
    end
  end
end

def test_castling board, works
  null_pos = PAIR[ZERO, ZERO]

  group 'with a white king' do
    group 'castling to the left' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                row:            WHITE_HOME_ROW,
                                king:           WHITE_KING,
                                rook:           WHITE_ROOK,
                                king_to_column: TWO,
                                rook_to_column: THREE
    end

    group 'castling to the right' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                row:            WHITE_HOME_ROW,
                                king:           WHITE_KING,
                                rook:           WHITE_ROOK,
                                king_to_column: SIX,
                                rook_to_column: FIVE
    end
  end

  group 'with a black king' do
    group 'can castle to the left' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                row:            BLACK_HOME_ROW,
                                king:           BLACK_KING,
                                rook:           BLACK_ROOK,
                                king_to_column: TWO,
                                rook_to_column: THREE
    end

    group 'can castle to the right' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                row:            BLACK_HOME_ROW,
                                king:           BLACK_KING,
                                rook:           BLACK_ROOK,
                                king_to_column: SIX,
                                rook_to_column: FIVE
    end
  end
end

group 'Play Functions' do
  group 'PERFORM_CASTLING' do
    group 'path is free' do
      board = [BR,0, 0, 0, BK,0, 0, BR,
               0, 0, 0, 0, 0, 0, 0, 0,<commit_msg>Clean castling tests a little<commit_after># Copyright (C) 2016 <NAME>
# All rights reserved.
#
# This software may be modified and distributed under the
# terms of the three-clause BSD license. See LICENSE.txt

require './setup'

def test_castling_to_one_side original_board:,
                              works:,
                              home_row:,
                              king:,
                              rook:,
                              king_to_column:,
                              rook_to_column:

  null_position = PAIR[ZERO, ZERO]
  king_from     = PAIR[FOUR, home_row]
  king_to       = PAIR[king_to_column, home_row]
  rook_from     = PAIR[
                    (rook_to_column == THREE) ? ZERO : SEVEN,
                    home_row
                  ]
  rook_to       = PAIR[rook_to_column, home_row]
  result        = PERFORM_CASTLING[
                    original_board,
                    king_from,
                    king_to,
                    null_position,
                    null_position
                  ]

  if works
    assert "king was moved" do
     piece_in_position = TO_MOVED_PIECE[king].to_i ==
                         GET_POSITION[result, king_to].to_i

     piece_in_position == works
    end

    assert "rook was moved" do
      piece_in_position = TO_MOVED_PIECE[rook].to_i ==
                          GET_POSITION[result, rook_to].to_i

      piece_in_position == works
    end

    assert "correct rook was moved" do
      piece_in_position = 0 == GET_POSITION[result, rook_from].to_i

      piece_in_position == works
    end
  else
    assert "board remains the same" do
     result == original_board
    end
  end
end

def test_castling board, works
  null_pos = PAIR[ZERO, ZERO]

  group 'with a white king' do
    group 'castling to the left' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                home_row:       WHITE_HOME_ROW,
                                king:           WHITE_KING,
                                rook:           WHITE_ROOK,
                                king_to_column: TWO,
                                rook_to_column: THREE
    end

    group 'castling to the right' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                home_row:       WHITE_HOME_ROW,
                                king:           WHITE_KING,
                                rook:           WHITE_ROOK,
                                king_to_column: SIX,
                                rook_to_column: FIVE
    end
  end

  group 'with a black king' do
    group 'can castle to the left' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                home_row:       BLACK_HOME_ROW,
                                king:           BLACK_KING,
                                rook:           BLACK_ROOK,
                                king_to_column: TWO,
                                rook_to_column: THREE
    end

    group 'can castle to the right' do
      test_castling_to_one_side original_board: board,
                                works:          works,
                                home_row:       BLACK_HOME_ROW,
                                king:           BLACK_KING,
                                rook:           BLACK_ROOK,
                                king_to_column: SIX,
                                rook_to_column: FIVE
    end
  end
end

group 'Play Functions' do
  group 'PERFORM_CASTLING' do
    group 'path is free' do
      board = [BR,0, 0, 0, BK,0, 0, BR,
               0, 0, 0, 0, 0, 0, 0, 0,
{'fraction_non_alphanumeric': 0.05510623714873201, 'fraction_numerical': 0.004934886908841672, 'mean_word_length': 1.0953475014359564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4073596', 'n_tokens_mistral': 2124, 'n_tokens_neox': 1986, 'n_words': 505}