package testing;
import algorithms.impls.wave.WaveAlgorithm;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import painting.ColorSquare;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.fail;
public class TestCase {
private List<List<ColorSquare>> colorSquareArr;
final int SQUARE_WIDTH = 10;
final int SQUARE_HEIGHT = 10;
final int SQUARES_NUMBER_Y = 5;
final int SQUARES_NUMBER_X = 5;
@Before
public void buildColorSquareArr() {
colorSquareArr = new ArrayList<List<ColorSquare>>();
for (int i = 0; i < SQUARES_NUMBER_Y; i++) {
List<ColorSquare> colorSquareArrX = new ArrayList<ColorSquare>();
for (int j = 0; j < SQUARES_NUMBER_X; j++) {
ColorSquare colorSquare = new ColorSquare();
colorSquare.setXPos(j * SQUARE_WIDTH);
colorSquare.setYPos(i * SQUARE_HEIGHT);
colorSquare.setXCoord(j);
colorSquare.setYCoord(i);
colorSquareArrX.add(colorSquare);
}
colorSquareArr.add(colorSquareArrX);
}
}
@Test
public void testPathNotLayThroughBlockSquares() {
final int POINT_SQUARE = 2;
final int BLOCK_SQUARE = 1;
final int OTHER_SQUARE = 0;
int [][] blockSquaresArr = new int [][] {
{POINT_SQUARE, BLOCK_SQUARE, BLOCK_SQUARE, BLOCK_SQUARE, OTHER_SQUARE},
{OTHER_SQUARE, BLOCK_SQUARE, OTHER_SQUARE, BLOCK_SQUARE, OTHER_SQUARE},
{OTHER_SQUARE, BLOCK_SQUARE, OTHER_SQUARE, BLOCK_SQUARE, POINT_SQUARE},
{OTHER_SQUARE, BLOCK_SQUARE, BLOCK_SQUARE, BLOCK_SQUARE, OTHER_SQUARE},
{OTHER_SQUARE, OTHER_SQUARE, OTHER_SQUARE, OTHER_SQUARE, OTHER_SQUARE},
};
for (int i = 0; i < SQUARES_NUMBER_Y; i++) {
for (int j = 0; j < SQUARES_NUMBER_X; j++) {
if (blockSquaresArr[i][j] == BLOCK_SQUARE) {
colorSquareArr.get(i).get(j).setColor(Color.RED);
}
if (blockSquaresArr[i][j] == POINT_SQUARE) {
colorSquareArr.get(i).get(j).setColor(Color.GREEN);
}
}
}
WaveAlgorithm waveAlgorithm = new WaveAlgorithm(colorSquareArr);
waveAlgorithm.calculate();
List<Point> pathCoordArr = waveAlgorithm.getPath();
for(Point point : pathCoordArr)
{
if (blockSquaresArr[point.y][point.x] == BLOCK_SQUARE) {
fail("Path between two points lays through block square y = " + point.y +
" x = " + point.x);
}
}
}
@After
public void closeColorSquareArr() {
//foo.close();
colorSquareArr.clear();
}
}