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 MoveTest {
    private static final Location start = new Location(Coordinate.A, 1);
    private static final Location end = new Location(Coordinate.D, 2);
    private static final Move move = new Move(start, end);

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testToString() {
        String moveStr = move.toString();
        assertEquals(moveStr, "[(A,1)-->(D,2)]");
    }

    @Test
    public void testGetEnd() {
        assertEquals(end, move.getEnd());
    }

    @Test
    public void testGetStart() {
        assertEquals(start, move.getStart());
    }

    @Test
    public void testGetAbsoluteDistanceX() {
        assertEquals(3, move.getAbsoluteDistanceX().intValue());
    }

    @Test
    public void testGetAbsoluteDistanceY() {
        assertEquals(1, move.getAbsoluteDistanceY().intValue());
    }

    @Test
    public void testGetDistanceX() {
        assertEquals(3, move.getDistanceX().intValue());
    }

    @Test
    public void testGetDistanceY() {
        assertEquals(1, move.getDistanceY().intValue());
    }

    @Test
    public void testIsNotFileOrRankMove() {
        assertFalse(Move.isFileOrRankMove(move));
    }

    @Test
    public void testIsFileMove() {
        assertTrue(Move.isFileOrRankMove(new Move(start, new Location(Coordinate.H, 1))));
    }

    @Test
    public void testIsRankMove() {
        assertTrue(Move.isFileOrRankMove(new Move(start, new Location(Coordinate.A, 8))));
    }

    @Test
    public void testNoMoveIsNotFileOrRankMove() {
        assertFalse(Move.isFileOrRankMove(new Move(start, new Location(Coordinate.A, 1))));
    }

    @Test
    public void testIsNotDiagonalMove() {
        assertFalse(Move.isDiagonalMove(move));
    }

    @Test
    public void testIsDiagonalMove() {
        assertTrue(Move.isDiagonalMove(new Move(start, new Location(Coordinate.C, 3))));
    }

    
    @Test
    public void testMoveString() {
        Move move = new Move("A1-B2");
        assertTrue(move.getStart().getLetter().equals(Coordinate.A));
        assertEquals(move.getStart().getNumber(), 1);
        assertTrue(move.getEnd().getLetter().equals(Coordinate.B));
        assertEquals(move.getEnd().getNumber(), 2);
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testMoveStringMissingDash() {
        new Move("A1B2");
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testInvalidMoveString() {
        new Move("A1K2");
    }
    
    @Test(expected = IllegalArgumentException.class)
    public void testInvalidMoveString2() {
        new Move("\"\"-a2");
    }
    
    @Test
    public void testAsString() {
        final String moveStr = "A1-B2";
        Move move = new Move(moveStr);
        String storedMoveStr = move.asString();
        assertEquals(moveStr, storedMoveStr);
    }
}

@@ -110,57 +110,8 @@
 te;%0A
-import org.junit.After;%0Aimport org.junit.Before;%0A
 impo
@@ -209,31 +209,20 @@
 ocation(
-Coordinate.A, 1
+%22A1%22
 );%0A    p
@@ -273,23 +273,12 @@
 ion(
-Coordinate.D, 2
+%22D2%22
 );%0A 
@@ -340,134 +340,8 @@
 );%0A%0A
-    @Before%0A    public void setUp() throws Exception %7B%0A    %7D%0A%0A    @After%0A    public void tearDown() throws Exception %7B%0A    %7D%0A%0A
     
@@ -1370,23 +1370,12 @@
 ion(
-Coordinate.H, 1
+%22H1%22
 ))))
@@ -1502,23 +1502,12 @@
 ion(
-Coordinate.A, 8
+%22A8%22
 ))))
@@ -1650,23 +1650,12 @@
 ion(
-Coordinate.A, 1
+%22A1%22
 ))))
@@ -1891,23 +1891,12 @@
 ion(
-Coordinate.C, 3
+%22C3%22
 ))))

remove magic numbers and refactor