Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • jali6/a2
1 result
Select Git revision
Loading items
Show changes

Commits on Source 2

......@@ -112,8 +112,13 @@ public class DotsAndBoxesGrid {
// 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).
if (getHorizontal(0, 0) && getHorizontal(0, 1) && getVertical(0, 0) && getVertical(1, 0)) {
return true;
}
else
return false;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
private boolean claimBox(int x, int y, int p) {
......@@ -140,6 +145,7 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if (getHorizontal(x, y)) throw new IllegalStateException();
this.horizontals[x][y] = true;
......
......@@ -28,4 +28,26 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
/* Test a grid with lines forming a complete box */
@Test
public void testIfBoxComplete() {
logger.info("test a grid with lines forming a complete box");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 1);
assertFalse(grid.boxComplete(0, 0));
}
/* Test if drawing a duplicate line throws IllegalStateException */
@Test
public void testDrawDuplicateLine() {
logger.info("Test if drawing a duplicate line throws IllegalStateException");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(5, 3, 2);
grid.drawHorizontal(1, 1, 1);
assertThrows(IllegalStateException.class, () -> {
grid.drawHorizontal(1, 1, 1);
});
}
}