From 2a54e73e1e88346bbffa697df15e2ed067c7f88b Mon Sep 17 00:00:00 2001 From: Carol-Ann Donaldson <cdonald7@myune.edu.au> Date: Tue, 16 Jul 2024 22:26:18 +1000 Subject: [PATCH] Added unit tests to detect assignment errors - square completion and drawing lines twice --- .../dotsandboxes/DotsAndBoxesGridTest.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..5244dbb 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -26,6 +26,30 @@ public class DotsAndBoxesGridTest { logger.info("Dummy test to show the test suite runs"); assertTrue(true); } + @Test + public void testSquareCompletion() { + logger.info("Testing if square completion detection is working"); + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3); + + // Simulate drawing lines to complete a square at (0,0) + grid.drawHorizontal(0, 0, 1); + grid.drawVertical(0, 0, 1); + grid.drawHorizontal(0, 1, 1); + grid.drawVertical(1, 0, 1); + + // The square at (0,0) should be complete + assertTrue(grid.isSquareComplete(0, 0), "Square at (0,0) should be complete"); + } - // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void testDrawingLineTwiceThrowsException() { + logger.info("Testing if drawing a line twice throws an IllegalStateException"); + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3); + + // Simulate drawing a horizontal line + grid.drawHorizontal(0, 0, 1); + + // Try drawing the same horizontal line again, which should throw an IllegalStateException + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1)); + } } -- GitLab