From 3d80af82a57ba130b300871185839b44d6bff948 Mon Sep 17 00:00:00 2001 From: Gareth Stretton Date: Thu, 27 Aug 2015 09:06:36 -0400 Subject: [PATCH] fix #144 : Make Maze2D.pointInBounds() check lower bounds too. --- .../hipster/util/examples/maze/Maze2D.java | 2 +- .../citius/lab/hipster/maze/Maze2DTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hipster-core/src/main/java/es/usc/citius/hipster/util/examples/maze/Maze2D.java b/hipster-core/src/main/java/es/usc/citius/hipster/util/examples/maze/Maze2D.java index 4ea198a..68a8117 100644 --- a/hipster-core/src/main/java/es/usc/citius/hipster/util/examples/maze/Maze2D.java +++ b/hipster-core/src/main/java/es/usc/citius/hipster/util/examples/maze/Maze2D.java @@ -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; } /** diff --git a/hipster-core/src/test/java/es/usc/citius/lab/hipster/maze/Maze2DTest.java b/hipster-core/src/test/java/es/usc/citius/lab/hipster/maze/Maze2DTest.java index 022117f..1d1ba09 100644 --- a/hipster-core/src/test/java/es/usc/citius/lab/hipster/maze/Maze2DTest.java +++ b/hipster-core/src/test/java/es/usc/citius/lab/hipster/maze/Maze2DTest.java @@ -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 { @@ -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))); + } }