diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..72ff77f9aa08f53841ab8d7d09f03ec66694916c 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -2,8 +2,6 @@ package dotsandboxes; import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assumptions.*; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -27,5 +25,41 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + // Test cases for known bugs + + @Test + public void testSquareCompletionBug() { + logger.info("Testing square completion logic"); + + // Create a new game grid + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(); + + // Draw lines to form a square + grid.drawLine(0, 0, 0, 1); // Top horizontal line + grid.drawLine(0, 0, 1, 0); // Left vertical line + grid.drawLine(0, 1, 1, 1); // Bottom horizontal line + grid.drawLine(1, 0, 1, 1); // Right vertical line + + // Test if the square at (0, 0) is complete + boolean isComplete = grid.isSquareComplete(0, 0); + + // The bug is that isSquareComplete always returns true + assertFalse(isComplete, "The square completion check should fail because the method is broken."); + } + + @Test + public void testDrawLineTwiceThrowsException() { + logger.info("Testing drawing the same line twice throws exception"); + + // Create a new game grid + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(); + + // Draw a line once + grid.drawLine(0, 0, 0, 1); + + // Attempt to draw the same line again + assertThrows(IllegalStateException.class, () -> { + grid.drawLine(0, 0, 0, 1); + }, "Drawing the same line twice should throw IllegalStateException."); + } }