<commit_before>package org.amc.game.chess;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

public class KingPieceTest {
    private ChessBoard board;

    @Before
    public void setUp() throws Exception {
        board = new ChessBoard();
    }

    @Test
    public void testIsValidMoveOnEmptyBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        addChessPieceToBoard(king, "F7");
        assertTrue(king.isValidMove(board, createMove("F7", "F8")));
        assertTrue(king.isValidMove(board, createMove("F7", "F6")));
        assertTrue(king.isValidMove(board, createMove("F7", "G7")));
        assertTrue(king.isValidMove(board, createMove("F7", "E7")));

        assertTrue(king.isValidMove(board, createMove("F7", "E8")));
        assertTrue(king.isValidMove(board, createMove("F7", "G8")));
        assertTrue(king.isValidMove(board, createMove("F7", "G6")));
        assertTrue(king.isValidMove(board, createMove("F7", "E8")));
    }
    
    private Move createMove(String start, String end) {
        return new Move(start + Move.MOVE_SEPARATOR + end);
    }
    
    private void addChessPieceToBoard(ChessPiece piece, String location) {
        board.putPieceOnBoardAt(piece, new Location(location));
    }

    @Test
    public void testIsNotValidMoveOnEmptyBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        addChessPieceToBoard(king, "F7");
        assertFalse(king.isValidMove(board, createMove("F7", "A8")));
        assertFalse(king.isValidMove(board, createMove("F7", "B6")));
        assertFalse(king.isValidMove(board, createMove("F7", "G3")));
        assertFalse(king.isValidMove(board,
                        createMove("F7", StartingSquare.WHITE_KING.getLocation().asString())));

        assertFalse(king.isValidMove(board, createMove("F7", "D2")));
        assertFalse(king.isValidMove(board, createMove("F7", "C3")));
        assertFalse(king.isValidMove(board, createMove("F7", "G3")));
        assertFalse(king.isValidMove(board, createMove("F7", "D8")));

        assertFalse(king.isValidMove(board, createMove("F7", "F7")));

    }

    @Test
    public void testIsValidMoveOnBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        KingPiece kingWhite = KingPiece.getKingPiece(Colour.WHITE);
        KingPiece anotherBlackKing = KingPiece.getKingPiece(Colour.BLACK);
        addChessPieceToBoard(king, "F7");
        addChessPieceToBoard(kingWhite, "E7");
        addChessPieceToBoard(anotherBlackKing, "G7");

        // Move to square occupied by the white king should be valid
        boolean isValid = king.isValidMove(board, createMove("F7", "E7"));
        // Move to square occupied by the another king should not be valid
        boolean notValid = king
                        .isValidMove(board, createMove("F7", "G7"));

        assertTrue(isValid);
        assertFalse(notValid);
    }

    @Test
    public void testGetPossibleMoveLocations() {
        KingPiece whiteKing = KingPiece.getKingPiece(Colour.WHITE);
        addChessPieceToBoard(whiteKing, StartingSquare.WHITE_KING.getLocation().asString());
        Set<Location> expectedMoveLocations = new HashSet<>();
        expectedMoveLocations.add(new Location("D1"));<commit_msg>use ChessBoardUtilities in KingPieceTest<commit_after>package org.amc.game.chess;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.*;

import java.util.HashSet;
import java.util.Set;

public class KingPieceTest {
    private ChessBoard board;
    private ChessBoardUtilities cbUtils;

    @Before
    public void setUp() throws Exception {
        board = new ChessBoard();
        cbUtils = new ChessBoardUtilities(board);
    }

    @Test
    public void testIsValidMoveOnEmptyBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        cbUtils.addChessPieceToBoard(king, "F7");
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "F8")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "F6")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "G7")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "E7")));

        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "E8")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "G8")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "G6")));
        assertTrue(king.isValidMove(board, cbUtils.createMove("F7", "E8")));
    }

    @Test
    public void testIsNotValidMoveOnEmptyBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        cbUtils.addChessPieceToBoard(king, "F7");
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "A8")));
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "B6")));
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "G3")));
        assertFalse(king.isValidMove(board,
        		cbUtils.createMove("F7", StartingSquare.WHITE_KING.getLocation().asString())));

        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "D2")));
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "C3")));
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "G3")));
        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "D8")));

        assertFalse(king.isValidMove(board, cbUtils.createMove("F7", "F7")));

    }

    @Test
    public void testIsValidMoveOnBoard() {
        KingPiece king = KingPiece.getKingPiece(Colour.BLACK);
        KingPiece kingWhite = KingPiece.getKingPiece(Colour.WHITE);
        KingPiece anotherBlackKing = KingPiece.getKingPiece(Colour.BLACK);
        cbUtils.addChessPieceToBoard(king, "F7");
        cbUtils.addChessPieceToBoard(kingWhite, "E7");
        cbUtils.addChessPieceToBoard(anotherBlackKing, "G7");

        // Move to square occupied by the white king should be valid
        boolean isValid = king.isValidMove(board, cbUtils.createMove("F7", "E7"));
        // Move to square occupied by the another king should not be valid
        boolean notValid = king
                        .isValidMove(board, cbUtils.createMove("F7", "G7"));

        assertTrue(isValid);
        assertFalse(notValid);
    }

    @Test
    public void testGetPossibleMoveLocations() {
        KingPiece whiteKing = KingPiece.getKingPiece(Colour.WHITE);
        cbUtils.addChessPieceToBoard(whiteKing, StartingSquare.WHITE_KING.getLocation().asString());
        Set<Location> expectedMoveLocations = new HashSet<>();
        expectedMoveLocations.add(new Location("D1"));
{'fraction_non_alphanumeric': 0.13358722718617255, 'fraction_numerical': 0.012597041160099605, 'mean_word_length': 3.683127572016461, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3949760', 'n_tokens_mistral': 2115, 'n_tokens_neox': 2177, 'n_words': 368}