package game.patterns;

import game.pieces.Square;
import game.pieces.SquaresMatrix;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author givanse
 */
public class TSquareTest extends TSquare {
    
    @Test
    public void findPatternMatchTest() {
        /**
         *  0123
         * 0    0
         * 1 bb 1
         * 2 bb 2
         * 3    3
         */
        SquaresMatrix squares = new SquaresMatrix(4, 4)
                .insertSquare(1, 1, Square.SquareColour.BLUE)
                .insertSquare(2, 1, Square.SquareColour.BLUE)
                .insertSquare(1, 2, Square.SquareColour.BLUE)
                .insertSquare(2, 2, Square.SquareColour.BLUE);
        /* pattern match a square shape */
        int x, y;
        int expecteds[][] = new int[0][0];
        int actuals[][];
        for(x = 0; x < squares.getWidth(); x++) {
            y = 0;
            actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
            assertArrayEquals(expecteds, actuals);
            y = squares.getHeight() - 1;
            actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
            assertArrayEquals(expecteds, actuals);
        }
        
        x = 0; y = 1;
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        x = 0; y = 2;
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        x = 3; y = 1;
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        x = 3; y = 2;
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        /* The next four tests will find a match. */
        
        /**
         *  0123
         * 0    0
         * 1 bb 1
         * 2 bb 2
         * 3    3
         */
        x = 1; y = 1;
        expecteds = new int[][]{{1, 1}, {2, 1}, {1, 2}, {2, 2}};
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        x = 2; y = 1;
        expecteds = new int[][]{{2, 1}, {1, 1}, {2, 2}, {1, 2}};
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        x = 1; y = 2;
        expecteds = new int[][]{{1, 2}, {2, 2}, {1, 1}, {2, 1}};
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        x = 2; y = 2;
        expecteds = new int[][]{{2, 2}, {1, 2}, {2, 1}, {1, 1}};
        actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
        assertArrayEquals(expecteds, actuals);
        
        /* The next tests fail because there is a color/SquareType mismatch */
        
        /**
         *  0123
         * 0    0
         * 1 bb 1
         * 2 br 2
         * 3    3
         */
        expecteds = new int[0][0];
        squares.insertSquare(2, 2, Square.SquareColour.RED);
        for(x = 1; x <= 2; x++)
            for(y = 1; y <= 2; y++) {
                actuals = TetrominoType.SQUARE.isPatternFound(x, y, squares);
                assertArrayEquals(expecteds, actuals);
            }
    }
   
}
@@ -3302,23 +3302,706 @@
           %7D%0A
+        %0A        /**%0A         *  0123456789%0A         * 0          0%0A         * 1          1%0A         * 2          2%0A         * 3        pp3%0A         * 4        pp4%0A         * 5          5%0A         */%0A        squares = new SquaresMatrix(10, 6)%0A                .insertSquare(8, 3, Square.SquareColour.PINK)%0A                .insertSquare(9, 3, Square.SquareColour.PINK)%0A                .insertSquare(8, 4, Square.SquareColour.PINK)%0A                .insertSquare(9, 4, Square.SquareColour.PINK);%0A        %0A        expecteds = new int%5B%5D%5B%5D%7B%7B8, 3%7D, %7B9, 3%7D, %7B8, 4%7D, %7B9, 4%7D%7D;%0A        actuals = TetrominoType.SQUARE.isPatternFound(8, 3, squares);%0A        assertArrayEquals(expecteds, actuals);%0A
     %7D%0A   %0A%7D

add one test case for pattern matching