Skip to content
Snippets Groups Projects
Commit 3fc75196 authored by Jason Aboh's avatar Jason Aboh :speech_balloon:
Browse files

Added unit tests to test for the two known bug issues

parent 21343e09
No related branches found
No related tags found
No related merge requests found
......@@ -28,4 +28,58 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
// Test to check for box completion , if it has 4 lines drawn then it is complete, else it is incomplete.
@Test
public void testForBoxCompletion(){
logger.info("Testing to check that a box is fully drawn, only when it is complete");
// Create new grid
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(2,2,1);
// Check for empty box
assertFalse(grid.boxComplete(0,0), "Empty box is incomplete and should not be claimable");
// Draw vertical line
grid.drawVertical(0,0,1);
// Box is incomplete
assertFalse(grid.boxComplete(0,0),"Box is incomplete and should not be claimable");
// Draw a horizontal line
grid.drawHorizontal(0,0,1);
// Box is incomplete
assertFalse(grid.boxComplete(0,0),"Box is incomplete and should not be claimable");
// Draw another vertical line and another horizontal line to complete the box
grid.drawVertical(1,0,1);
grid.drawHorizontal(0,1,1);
// Check for complete box
assertTrue(grid.boxComplete(0,0), "Box is complete and should be fully drawn and claimable");
}
// Test to check if a line can be drawn, and to throw an illegalStateException if the line has already been
// drawn at the same coordinates (duplicate).
@Test
public void TestForDuplicateLinesDrawn(){
logger.info("Testing to check that it is disallowed to draw over a line that has already been drawn");
// Create new grid
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(2,2,1);
// Test to check if a vertical and horizontal line can be drawn to the grid
assertFalse(grid.drawVertical(0,0,1));
assertFalse(grid.drawHorizontal(0,0,1));
// Test to catch IllegalStateException, when a duplicate vertical line draw attempt is made
// at the same coordinates.
assertThrows(
IllegalStateException.class,()-> grid.drawVertical(0,0,1)
,"This line has already been drawn");
// Test to catch IllegalStateException, when a duplicate horizontal line draw attempt is made
// at the same coordinates.
assertThrows(
IllegalStateException.class, () -> grid.drawHorizontal(0,0,1),
"This line has already been drawn");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment