package org.amc.game.chess;

import static org.amc.game.chess.ChessBoard.Coordinate.*;
import static org.junit.Assert.*;
import static org.amc.game.chess.SimpleChessBoardSetupNotation.MOVE_TOKEN;

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

import java.text.ParseException;

public class SimpleChessBoardSetupNotationTest {

    private static final String setupNotation = "Kd6:Qe6:Bb8:Be8:Ng8:Na6:Ra4:Ph5:"
                    + "ka3:qe1:bh3:nc3:pf4:rb5";
    private ChessBoardFactory chessBoardFactory;

    // private static final String setupNotation="Kd6Qe6";
    @Before
    public void setUp() throws Exception {
        chessBoardFactory = new ChessBoardFactoryImpl(new SimpleChessBoardSetupNotation());
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void validInputTest() {
        SimpleChessBoardSetupNotation notation = new SimpleChessBoardSetupNotation();
        assertTrue(notation.isInputValid(setupNotation));
    }

    @Test
    public void test() throws Exception {
        ChessBoard board = chessBoardFactory.getChessBoard(setupNotation);
        assertTrue(board.getPieceFromBoardAt(new Location(D, 6)) instanceof KingPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(E, 6)) instanceof QueenPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(B, 8)) instanceof BishopPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(E, 8)) instanceof BishopPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(G, 8)) instanceof KnightPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(A, 6)) instanceof KnightPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(A, 4)) instanceof RookPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(H, 5)) instanceof PawnPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(A, 3)) instanceof KingPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(E, 1)) instanceof QueenPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(H, 3)) instanceof BishopPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(C, 3)) instanceof KnightPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(B, 5)) instanceof RookPiece);
        assertTrue(board.getPieceFromBoardAt(new Location(F, 4)) instanceof PawnPiece);
    }

    @Test(expected = ParseException.class)
    public void testInvalidPattern() throws ParseException {
        chessBoardFactory.getChessBoard("Be3:Me3");
    }
    
    @Test
    public void testMovedNotationValid() {
    	final String boardStr = setupNotation + ":pa4" + MOVE_TOKEN;
    	try {
    		chessBoardFactory.getChessBoard(boardStr);
    	} catch (ParseException pe) {
    		fail("Should be valid setUp Notation:" + boardStr);
    	}
    	
    }
    
    @Test
    public void testMovedNotation() throws Exception {
    	final String boardStr = setupNotation + ":pa4" + MOVE_TOKEN;
        ChessBoard board = chessBoardFactory.getChessBoard(boardStr);
        assertTrue("Pawn should have field moved set to true", board.getPieceFromBoardAt(new Location("a4")).hasMoved());
        assertFalse("Pawn should have field moved set to false", board.getPieceFromBoardAt(new Location("f4")).hasMoved());
    }

}

@@ -1191,12 +1191,12 @@
 ion(
-D, 6
+%22D6%22
 )) i
@@ -1279,12 +1279,12 @@
 ion(
-E, 6
+%22E6%22
 )) i
@@ -1368,12 +1368,12 @@
 ion(
-B, 8
+%22B8%22
 )) i
@@ -1458,12 +1458,12 @@
 ion(
-E, 8
+%22E8%22
 )) i
@@ -1548,12 +1548,12 @@
 ion(
-G, 8
+%22G8%22
 )) i
@@ -1638,12 +1638,12 @@
 ion(
-A, 6
+%22A6%22
 )) i
@@ -1728,12 +1728,12 @@
 ion(
-A, 4
+%22A4%22
 )) i
@@ -1816,12 +1816,12 @@
 ion(
-H, 5
+%22H5%22
 )) i
@@ -1904,12 +1904,12 @@
 ion(
-A, 3
+%22A3%22
 )) i
@@ -1992,12 +1992,12 @@
 ion(
-E, 1
+%22E1%22
 )) i
@@ -2081,12 +2081,12 @@
 ion(
-H, 3
+%22H3%22
 )) i
@@ -2171,12 +2171,12 @@
 ion(
-C, 3
+%22C3%22
 )) i
@@ -2261,12 +2261,12 @@
 ion(
-B, 5
+%22B5%22
 )) i
@@ -2349,12 +2349,12 @@
 ion(
-F, 4
+%22F4%22
 )) i

replace magic numbers with strings