Skip to content
Snippets Groups Projects
Commit 7a7a842e authored by Camillie Ashmore's avatar Camillie Ashmore
Browse files

Updated code so that boxComplete, drawHorizontal and drawVertical methods pass unit tests

parent 5d5537a5
No related tags found
No related merge requests found
......@@ -109,8 +109,9 @@ public class DotsAndBoxesGrid {
public boolean boxComplete(int x, int y) {
if (x >= width - 1 || x < 0 || y >= height - 1 || y < 0) {
return false;
} else if ((!this.getHorizontal(x,y)) || (!this.getVertical(x,y)) || (!this.getHorizontal(x+1,y)) || (!this.getVertical(x,y+1))) {
return false;
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first).
return true;
......@@ -139,7 +140,9 @@ public class DotsAndBoxesGrid {
if (y >= height || y < 0) {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height));
}
if (this.getHorizontal(x,y)) {
throw new IllegalStateException("That line has already been taken");
}
// FIXME: You need to throw an exception if the line was already drawn.
this.horizontals[x][y] = true;
......@@ -170,7 +173,9 @@ public class DotsAndBoxesGrid {
if (y >= height - 1 || y < 0) {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height - 1));
}
if (this.getVertical(x,y)) {
throw new IllegalStateException("That line has already been taken");
}
// You need to throw an exception if the line was already drawn.
this.verticals[x][y] = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment