From 5d5537a5d3bac6c4a2a23e55cb6a29691e5c5b52 Mon Sep 17 00:00:00 2001 From: Camillie Ashmore <cashmore@myune.edu.au> Date: Tue, 13 Jul 2021 21:14:07 +1000 Subject: [PATCH] Created unit tests for boxComplete, drawHorizontal and drawVertical methods --- .../dotsandboxes/DotsAndBoxesGridTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..921e644 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,36 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void testBoxComplete() { + logger.info("Creating a new game"); + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 5, 1); + + logger.info("Drawing three of four box sides"); + grid.drawHorizontal(0,0,1); + grid.drawHorizontal(1, 0, 1); + grid.drawVertical(0, 0, 1); + + assertFalse(grid.boxComplete(0,0)); + + logger.info("Completing the box"); + grid.drawVertical(0, 1, 1); + + assertTrue(grid.boxComplete(0,0)); + } + + @Test + public void testLineDoubleUp() { + logger.info("Creating a new game"); + DotsAndBoxesGrid gridTwo = new DotsAndBoxesGrid(3, 5, 1); + + logger.info("Drawing a horizontal line"); + gridTwo.drawHorizontal(1, 1, 1); + assertThrows(IllegalStateException.class, () -> gridTwo.drawHorizontal(1, 1, 1), "This horizontal line is already taken"); + + logger.info("Drawing a vertical line"); + gridTwo.drawVertical(2, 2, 1); + assertThrows(IllegalStateException.class, () -> gridTwo.drawVertical(2, 2, 1), "This vertical line is already taken"); + } + } -- GitLab