From 304f9f629e62a54f7b858dbf28e8f260a0f3ea2c Mon Sep 17 00:00:00 2001 From: jphiri <jphiri@myune.edu.au> Date: Wed, 2 Aug 2023 20:33:05 +1000 Subject: [PATCH] test for fixing the bug boxcomplete and drawHorizontal class --- .../dotsandboxes/DotsAndBoxesGridTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..a4fc127 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,58 @@ 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); + + + assertFalse(grid.boxComplete(3, 2)); + } + + @Test + void testBoxCompleteOnEmptyBox() { + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); + + + assertFalse(grid.boxComplete(1, 1)); + } + + @Test + void testBoxCompleteOnCompletedBox() { + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); + + + grid.drawHorizontal(0, 1, 1); + grid.drawHorizontal(0, 2, 1); + grid.drawVertical(0, 1, 1); + grid.drawVertical(1, 1, 1); + + + 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); + + //out of bounce + 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)); + } + } -- GitLab