Skip to content

Commit

Permalink
fix #144 : Make Maze2D.pointInBounds() check lower bounds too.
Browse files Browse the repository at this point in the history
  • Loading branch information
gahrae committed Aug 27, 2015
1 parent aae581e commit 3d80af8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public boolean validLocation(Point loc) {
* @return true if the point is in the maze.
*/
public boolean pointInBounds(Point loc) {
return loc.x < this.columns && loc.y < this.rows;
return loc.x >= 0 && loc.x < this.columns && loc.y >= 0 && loc.y < this.rows;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

public class Maze2DTest {

Expand Down Expand Up @@ -133,4 +134,21 @@ public void testObstacles() {
assertTrue(maze.diff(new Maze2D(refMaze)).isEmpty());
assertTrue(!maze.diff(goal).isEmpty());
}

@Test
public void testPointInBounds() {
Maze2D maze = new Maze2D(testMaze);
assertFalse(maze.pointInBounds(new Point(-1,0)));
assertFalse(maze.pointInBounds(new Point(0,-1)));

int colLength = maze.getMaze()[0].length;
int rowLength = maze.getMaze().length;
assertFalse(maze.pointInBounds(new Point(colLength,0)));
assertFalse(maze.pointInBounds(new Point(0,rowLength)));

assertTrue(maze.pointInBounds(new Point(0,0)));
assertTrue(maze.pointInBounds(new Point(0,0)));
assertTrue(maze.pointInBounds(new Point(colLength-1,0)));
assertTrue(maze.pointInBounds(new Point(0,rowLength-1)));
}
}

0 comments on commit 3d80af8

Please sign in to comment.