diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..75fa3c2acceea84772f7e83cc8b063b6ccbaa27f 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,39 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void testBoxCompletionDetection() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); + + / Draw only three sides of a box (not completing it) + grid.drawHorizontal(0, 0, 1); // Top + grid.drawVertical(0, 0, 1); // Left + grid.drawHorizontal(0, 1, 1); // Bottom + + // Check if the box at (0, 0) is incorrectly identified as completed + assertTrue(grid.boxComplete(0, 0), "The box should not be completed."); + } + + @Test + public void testBoxComplete() { + // Draw lines around a box and check if it's completed + game.drawHorizontal(0, 0, 1); // Top horizontal line + game.drawVertical(0, 0, 1); // Left vertical line + game.drawHorizontal(0, 1, 1); // Bottom horizontal line + game.drawVertical(1, 0, 1); // Right vertical line + + assertTrue("Box should be completed", game.boxComplete(0, 0)); + } + + @Test(expected = IllegalStateException.class) + public void testDrawHorizontalLineAlreadyDrawn() { + game.drawHorizontal(0, 0, 1); + game.drawHorizontal(0, 0, 1); // Drawing the same line should throw an exception + } + + @Test(expected = IllegalStateException.class) + public void testDrawVerticalLineAlreadyDrawn() { + game.drawVertical(0, 0, 1); + game.drawVertical(0, 0, 1); // Drawing the same line should throw an exception + } }