From 8490b8df25cc04d066d4be4b5afe5ee08d6443ba Mon Sep 17 00:00:00 2001 From: Anudip Chauhan <achauha3@myune.edu.au> Date: Wed, 31 Jul 2024 14:02:12 +0545 Subject: [PATCH] Add unit tests --- .../dotsandboxes/DotsAndBoxesGridTest.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 75fa3c2..ad34020 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -32,7 +32,7 @@ public class DotsAndBoxesGridTest { public void testBoxCompletionDetection() { DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); - / Draw only three sides of a box (not completing it) + // 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 @@ -41,26 +41,23 @@ public class DotsAndBoxesGridTest { 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) + @Test public void testDrawHorizontalLineAlreadyDrawn() { - game.drawHorizontal(0, 0, 1); - game.drawHorizontal(0, 0, 1); // Drawing the same line should throw an exception + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4,4,2); + grid.drawHorizontal(0, 0, 1); + assertThrows(IllegalStateException.class, () -> { + grid.drawHorizontal(0, 0, 1); // Drawing the same line should throw an exception + }); } - @Test(expected = IllegalStateException.class) + @Test public void testDrawVerticalLineAlreadyDrawn() { - game.drawVertical(0, 0, 1); - game.drawVertical(0, 0, 1); // Drawing the same line should throw an exception + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4,4,2); + grid.drawVertical(0, 0, 1); + assertThrows(IllegalStateException.class, () -> { + grid.drawVertical(0, 0, 1); // Drawing the same line should throw an exception + }); } } -- GitLab