Skip to content
Snippets Groups Projects
Commit a9b9997d authored by sclark94's avatar sclark94
Browse files

Add unit tests for bugs

parent 5b89ba58
No related branches found
No related tags found
No related merge requests found
......@@ -28,4 +28,60 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testBoxCompleteAlgorithm() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
assertFalse(grid.boxComplete(0, 0));
grid.drawVertical(0, 0, 1);
assertFalse(grid.boxComplete(0, 0));
assertFalse(grid.boxComplete(1, 0));
grid.drawVertical(1, 0, 1);
assertFalse(grid.boxComplete(1, 0));
assertFalse(grid.boxComplete(0, 0));
grid.drawHorizontal(0, 0, 1);
assertFalse(grid.boxComplete(0, 0));
assertFalse(grid.boxComplete(0, 1));
grid.drawHorizontal(0, 1, 1);
assertTrue(grid.boxComplete(0, 0));
assertFalse(grid.boxComplete(5, 5));
grid.drawHorizontal(5, 5, 1);
assertFalse(grid.boxComplete(5, 5));
assertFalse(grid.boxComplete(5, 6));
grid.drawHorizontal(5, 6, 1);
assertFalse(grid.boxComplete(5, 6));
assertFalse(grid.boxComplete(5, 5));
grid.drawVertical(5, 5, 1);
assertFalse(grid.boxComplete(5, 5));
assertFalse(grid.boxComplete(4, 5));
grid.drawVertical(6, 5, 1);
assertFalse(grid.boxComplete(6, 5));
assertTrue(grid.boxComplete(5, 5));
}
@Test
public void testDrawAlreadyDrawnLine() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(2, 2, 2);
// Draw a line at (0, 0) and claim a box
grid.drawHorizontal(0, 0, 1);
// Try to draw the same line again, it should throw an IllegalStateException
assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1));
// Draw a vertical line at (0, 0) and claim a box
grid.drawVertical(0, 0, 1);
// Try to draw the same vertical line again, it should throw an IllegalStateException
assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment