package li.seiji.minichess;

import org.junit.Test;

import java.util.HashSet;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;

public class SquareTest {

    @Test
    public void testAutoPositionStringParsing() {
        String[][] positions = new String[Board.ROWS][Board.COLUMNS];
        for(int y = 0; y < Board.ROWS; ++y) {
            for(int x = 0; x < Board.COLUMNS; ++x) {
                char[] posStr = {
                        (char)((int)'a' + x),
                        (char)((int)'1' + y)
                }; //construct position strings like: "c4"
                positions[y][x] = new String(posStr);
            }
        }

        for(int y = 0; y < Board.ROWS; ++y) {
            for(int x = 0; x < Board.COLUMNS; ++x) {
                Square square = new Square(positions[y][x]);
                assertSquareCorrect(square, x, y);
            }
        }
    }

    @Test
    public void testPositionStringParsing() {
        Square square;

        square = new Square("c4");
        assertSquareCorrect(square, 2, 3);
        square = new Square("a6");
        assertSquareCorrect(square, 0, 5);
        square = new Square("e1");
        assertSquareCorrect(square, 4, 0);
    }


    @Test
    public void testHashAndEquality() {
        HashSet<Square> squares = new HashSet<>();
        for(int y = 0; y < 250; ++y) {
            for(int x = 0; x < 250; ++x) {
                squares.add(new Square(x, y));
            }
        }

        //test that the HashSet can find them
        for(Square sqr : squares) {
            assertTrue(squares.contains(sqr));
        }
    }


    private static void assertSquareCorrect(Square square, int x, int y) {
        assertEquals(x, square.x);
        assertEquals(y, square.y);
    }

}

@@ -22,16 +22,53 @@
 chess;%0A%0A
+import li.seiji.minichess.move.Move;%0A
 import o
@@ -1044,109 +1044,104 @@
     
-Square square;%0A%0A        square = new Square(%22c4%22);%0A        assertSquareCorrect(square, 2, 3);%0A       
+for(int y = 0; y %3C 250; ++y) %7B%0A            for(int x = 0; x %3C 250; ++x) %7B%0A                Square
  squ
@@ -1161,12 +1161,12 @@
 are(
-%22a6%22
+x, y
 );%0A 
@@ -1176,52 +1176,30 @@
     
-assertSquareCorrect(square, 0, 5);%0A        s
+        Square parsedS
 quar
@@ -1217,12 +1217,25 @@
 are(
-%22e1%22
+square.toString()
 );%0A 
@@ -1245,42 +1245,97 @@
     
+        
 assert
-SquareCorrect(square, 4, 0);
+Equals(parsedSquare.toString(), square.toString());%0A            %7D%0A        %7D
 %0A   

Fix Square string parsing TestCase