From 0477818a210386a0abd853355dd05fb999b524a3 Mon Sep 17 00:00:00 2001 From: jphiri <jphiri@myune.edu.au> Date: Tue, 1 Aug 2023 21:12:46 +1000 Subject: [PATCH] Run unit tests for bug fix 1 --- .../dotsandboxes/DotsAndBoxesGridTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..f34910c 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,61 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. + + @Test + void testBoxCompleteOnEdge() { + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players + + + assertFalse(grid.boxComplete(3, 2)); // The bottom-right corner, there's no box here + } + + @Test + void testBoxCompleteOnEmptyBox() { + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players + + + assertFalse(grid.boxComplete(1, 1)); + } + + @Test + void testBoxCompleteOnCompletedBox() { + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players + + // Draw all lines to complete a box at coordinates (1, 1) + grid.drawHorizontal(0, 1, 1); + grid.drawHorizontal(0, 2, 1); + grid.drawVertical(0, 1, 1); + grid.drawVertical(1, 1, 1); + + // Test when the given coordinates represent a completed box + assertTrue(grid.boxComplete(1, 1)); + } + + + + //end here fix me + + //fix 2 + + + @Test + public void testDrawHorizontalOutOfBounds() { + int width = 4; + int height = 3; + int players = 2; + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(width, height, players); + + // Test the out of bounds scenarios + assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(-1, 0, 1)); + assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(width - 1, 0, 1)); + assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(0, -1, 1)); + assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(0, height, 1)); + } + + + //end here } -- GitLab