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
  • 1-two-known-bugs
  • main
  • testsfail
3 results

Target

Select target project
  • mralston/a2
1 result
Select Git revision
  • 1-two-known-bugs
  • main
  • testsfail
3 results
Show changes

Commits on Source 2

......@@ -111,8 +111,7 @@ 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).
return true;
return horizontals[x][y] && horizontals[x][y+1] && verticals[x][y] && verticals[x+1][y];
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
......@@ -139,7 +138,9 @@ public class DotsAndBoxesGrid {
throw new IndexOutOfBoundsException(String.format("y was %d, which is out of range. Range is 0 to %d", y, height));
}
// FIXME: You need to throw an exception if the line was already drawn.
if (this.horizontals[x][y]) {
throw new IllegalStateException(String.format("line at %d, %d was already drawn and cannot be redrawn.", x, y));
}
this.horizontals[x][y] = true;
......
......@@ -27,5 +27,34 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void boxCompleteDetectsCompletedBoxes() {
logger.info("Test to show that boxComplete returns true if all sides have been drawn");
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(4,4,1);
case1.drawHorizontal(0,0,0);
case1.drawVertical(0,0,1);
case1.drawHorizontal(0,1,0);
case1.drawVertical(1,0,1);
assertTrue(case1.boxComplete(0,0));
}
@Test
public void boxCompleteDetectsIncompleteBoxes() {
logger.info("Test to show that boxComplete returns false if not all sides have been drawn");
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(4,4,1);
case1.drawHorizontal(0,0,0);
case1.drawVertical(0,0,1);
case1.drawHorizontal(0,1,0);
assertFalse(case1.boxComplete(0,0));
}
@Test
public void drawMethodsDetectRedrawnLines() {
logger.info("Test to show that drawHorizontal throws an exception if the line was already drawn");
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(4,4,1);
case1.drawHorizontal(0,0,0);
assertThrows(IllegalStateException.class, () -> {
case1.drawHorizontal(0,0,0);
});
}
}