From 9231f72fa394bdb7ec09d51b3c745a955e0ea323 Mon Sep 17 00:00:00 2001 From: Hayden McCristal <hmccrist@myune.edu.au> Date: Thu, 3 Aug 2023 19:51:38 +1000 Subject: [PATCH] Added unit tests --- .../dotsandboxes/DotsAndBoxesGridTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..7435a83 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,31 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. + + @Test + public void boxCompleteDetectsCompletedBoxes() { + DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(5, 5, 2); + case1.drawHorizontal(0, 0, 0); + case1.drawVertical(0, 0, 1); + case1.drawHorizontal(0, 1, 0); + case1.drawVertical(1, 0, 1); + assertTrue(case1.boxComplete(0, 0)); + } + + @Test + public void boxCompleteDetectsIncompleteBoxes() { + DotsAndBoxesGrid case2 = new DotsAndBoxesGrid(5, 5, 2); + case2.drawHorizontal(0, 0, 0); + case2.drawVertical(0, 0, 1); + assertFalse(case2.boxComplete(0, 0)); + } + + @Test + public void checkDrawLineException() { + DotsAndBoxesGrid case3 = new DotsAndBoxesGrid(5, 5, 2); + case3.drawHorizontal(0, 0, 0); + case3.drawVertical(0, 0, 1); + assertThrows(IllegalArgumentException.class, () -> case3.drawHorizontal(0, 0, 0)); + assertThrows(IllegalArgumentException.class, () -> case3.drawVertical(0, 0, 1)); + } } -- GitLab