@Test public void shouldPaintSelectedZoneUsingIndicatedColor() { int[][] picture = { { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }, { 1, 1, 1, 1 } }; int colorToReplace = 0; int colorToPaint = 1; int x = 1; int y = 1; floodFill.apply(picture, colorToReplace, colorToPaint, x, y); int[][] expectedResult = { { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 } }; assertArrayEquals(expectedResult, picture); }
public void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y) { validatePicture(picture); int currentColor = getValueAt(picture, x, y); if (currentColor == colorToReplace) { picture[x][y] = colorToPaint; apply(picture, colorToReplace, colorToPaint, x + 1, y); apply(picture, colorToReplace, colorToPaint, x - 1, y); apply(picture, colorToReplace, colorToPaint, x, y + 1); apply(picture, colorToReplace, colorToPaint, x, y - 1); } }
FloodFill { public void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y) { validatePicture(picture); int currentColor = getValueAt(picture, x, y); if (currentColor == colorToReplace) { picture[x][y] = colorToPaint; apply(picture, colorToReplace, colorToPaint, x + 1, y); apply(picture, colorToReplace, colorToPaint, x - 1, y); apply(picture, colorToReplace, colorToPaint, x, y + 1); apply(picture, colorToReplace, colorToPaint, x, y - 1); } } }
FloodFill { public void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y) { validatePicture(picture); int currentColor = getValueAt(picture, x, y); if (currentColor == colorToReplace) { picture[x][y] = colorToPaint; apply(picture, colorToReplace, colorToPaint, x + 1, y); apply(picture, colorToReplace, colorToPaint, x - 1, y); apply(picture, colorToReplace, colorToPaint, x, y + 1); apply(picture, colorToReplace, colorToPaint, x, y - 1); } }  }
FloodFill { public void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y) { validatePicture(picture); int currentColor = getValueAt(picture, x, y); if (currentColor == colorToReplace) { picture[x][y] = colorToPaint; apply(picture, colorToReplace, colorToPaint, x + 1, y); apply(picture, colorToReplace, colorToPaint, x - 1, y); apply(picture, colorToReplace, colorToPaint, x, y + 1); apply(picture, colorToReplace, colorToPaint, x, y - 1); } }  void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y); }
FloodFill { public void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y) { validatePicture(picture); int currentColor = getValueAt(picture, x, y); if (currentColor == colorToReplace) { picture[x][y] = colorToPaint; apply(picture, colorToReplace, colorToPaint, x + 1, y); apply(picture, colorToReplace, colorToPaint, x - 1, y); apply(picture, colorToReplace, colorToPaint, x, y + 1); apply(picture, colorToReplace, colorToPaint, x, y - 1); } }  void apply(int[][] picture, int colorToReplace, int colorToPaint, int x, int y);  }