package org.amc.game.chess;

import static org.junit.Assert.*;

import org.amc.game.chess.ChessBoard.Coordinate;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ChessBoardTest {

    private ChessBoard board;
    private Location endLocation;
    private Location startLocation;

    @Before
    public void setUp() throws Exception {
        board = new ChessBoard();
        startLocation = new Location(ChessBoard.Coordinate.A, 8);
        endLocation = new Location(ChessBoard.Coordinate.B, 7);
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testMovesAreSaved() throws InvalidMoveException {
        BishopPiece bishop = new BishopPiece(Colour.BLACK);
        board.putPieceOnBoardAt(bishop, startLocation);
        Move move = new Move(startLocation, endLocation);
        board.move(move);
        Move lastMove = board.getTheLastMove();
        assertEquals(lastMove.getStart(), startLocation);
        assertEquals(lastMove.getEnd(), endLocation);
    }
    
    @Test
    public void getEmptyMove(){
        Move move=board.getTheLastMove();
        assertTrue(move instanceof EmptyMove);
    }
    
    @Test
    public void testInitialse(){
        board.initialise();
        for(int i=7;i<=8;i++){
            for(Coordinate coord:Coordinate.values()){
                ChessPiece piece=board.getPieceFromBoardAt(coord.getIndex(), i);
                assertTrue(piece instanceof ChessPiece);
                assertEquals(piece.getColour(),Colour.BLACK);
            }
        }
        for(int i=3;i<=6;i++){
            for(Coordinate coord:Coordinate.values()){
                assertNull(board.getPieceFromBoardAt(coord.getIndex(), i));
            }
        }
        for(int i=1;i<=2;i++){
            for(Coordinate coord:Coordinate.values()){
                ChessPiece piece=board.getPieceFromBoardAt(coord.getIndex(), i);
                assertTrue(piece instanceof ChessPiece);
                assertEquals(piece.getColour(),Colour.WHITE);
            }
        }
        
    }
    
    /**
     * Tests the copying constructor of ChessBoard and copy method of ChessPiece
     */
    @Test
    public void CloneConstructorTest(){
        board.initialise();
        ChessBoard clone=new ChessBoard(board);       
        for(Coordinate coord:ChessBoard.Coordinate.values()){
            for(int i=1;i<=ChessBoard.BOARD_WIDTH;i++){
                Location location=new Location(coord,i);
                ChessPiece piece=board.getPieceFromBoardAt(location);
                ChessPiece clonedPiece=clone.getPieceFromBoardAt(location);
                if(piece instanceof ChessPiece){
                    assertFalse(piece==clonedPiece);
                    assertTrue(piece.equals(clonedPiece));
                }else{
                    assertNull(piece);
                    assertNull(clonedPiece);
                }
            }
        }
    }
}

@@ -183,38 +183,159 @@
 t;%0A%0A
-public class ChessBoardTest %7B%0A
+import java.text.ParseException;%0Aimport java.util.List;%0A%0Apublic class ChessBoardTest %7B%0A%0A    private Player whitePlayer;%0A    private Player blackPlayer;
 %0A   
@@ -479,32 +479,165 @@
 ows Exception %7B%0A
+        whitePlayer=new HumanPlayer(%22White Player%22,Colour.WHITE);%0A        blackPlayer=new HumanPlayer(%22Black Player%22, Colour.BLACK);%0A
         board = 
@@ -2507,32 +2507,34 @@
 rd.initialise();
+  
 %0A        ChessBo
@@ -2627,32 +2627,70 @@
 nate.values())%7B%0A
+            boolean moveToggle=false;%0A
             for(
@@ -3238,20 +3238,1531 @@
 %7D%0A        %7D%0A
+        %0A        %0A    %7D%0A    %0A    @Test%0A    public void CloneConstuctorMoveListCopyTest()%7B%0A        board.initialise();  %0A        ChessBoard clone=new ChessBoard(board);%0A        assertTrue(board.getTheLastMove().equals(clone.getTheLastMove()));%0A    %7D%0A    %0A    @Test%0A    public void CloneConstuctorPieceMovedCopyTest()%7B%0A        board.initialise();%0A        board.getPieceFromBoardAt(StartingSquare.BLACK_KING.getLocation()).moved();%0A        board.getPieceFromBoardAt(StartingSquare.WHITE_KING.getLocation()).moved();%0A        ChessBoard clone=new ChessBoard(board);%0A        assertTrue(clone.getPieceFromBoardAt(StartingSquare.BLACK_KING.getLocation()).hasMoved());%0A        assertTrue(clone.getPieceFromBoardAt(StartingSquare.WHITE_KING.getLocation()).hasMoved());%0A        assertFalse(clone.getPieceFromBoardAt(StartingSquare.BLACK_KNIGHT_LEFT.getLocation()).hasMoved());%0A        assertFalse(clone.getPieceFromBoardAt(StartingSquare.WHITE_ROOK_LEFT.getLocation()).hasMoved());%0A        %0A    %7D%0A    %0A    @Test%0A    public void getListOfPlayersPiecesOnTheBoardTest()throws ParseException%7B%0A        ChessBoardFactory factory=new ChessBoardFactoryImpl(new SimpleChessBoardSetupNotation());%0A        ChessBoard board=factory.getChessBoard(%22Ke1:ke2:Bf1:nf3:na1:ra2%22);%0A        List%3C?%3E blackPieceList=board.getListOfPlayersPiecesOnTheBoard(blackPlayer);%0A        List%3C?%3E whitePieceList=board.getListOfPlayersPiecesOnTheBoard(whitePlayer);%0A        assertTrue(blackPieceList.size()==2);%0A        assertTrue(whitePieceList.size()==4);%0A
     %7D%0A%7D%0A

add test cases for ChessBoard