From c9a031fc104d0d8f1f46ac01247687dee957f0e5 Mon Sep 17 00:00:00 2001 From: vle2 <vle9@myune.edu.au> Date: Mon, 29 Jul 2024 21:19:23 +1000 Subject: [PATCH] Unit tests added --- .../dotsandboxes/DotsAndBoxesGridTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..f893fb7 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,32 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void boxCompleteDetectsCompletedBoxes() { + // code to test that boxComplete returns true for boxes that *are complete* goes here + 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 drawMethodsDetectRedrawnLines() { + DotsAndBoxesGrid case2 = new DotsAndBoxesGrid(5, 5, 2); + case2.drawHorizontal(0, 0, 0); + case2.drawVertical(0, 0, 1); + + // code to test that drawHorizontal throws an exception if the line was already drawn goes here + assertThrows(IllegalStateException.class, () -> { + case2.drawHorizontal(0, 0, 1); // divide by zero throws an exception for int/int + }); + + // code to test that drawVertical throws an exception if the line was already drawn goes here + assertThrows(IllegalStateException.class, () -> { + case2.drawVertical(0, 0, 0); // divide by zero throws an exception for int/int + }); + + } } -- GitLab