From 13feb62471b93af34c9fe913dba11f11dfed8e18 Mon Sep 17 00:00:00 2001 From: Matthew Trippe <Mtrippe@myune.edu.au> Date: Wed, 21 Jul 2021 22:12:37 +1000 Subject: [PATCH] Created unit tests for CompleteBox and Exception throws on existing line --- .../dotsandboxes/DotsAndBoxesGridTest.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1aac7cc..f5d0431 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -28,4 +28,43 @@ public class DotsAndBoxesGridTest { } // FIXME: You need to write tests for the two known bugs in the code. -} + + @Test + public void testBoxComplete() { + + logger.info("This test sets up a test square 10,10,2 and draws a box for player1"); + + // set up the test box + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(10,10,2); + + // draw a test square, player 1 + grid.drawHorizontal(0,0,1); + grid.drawHorizontal(0,1,1); + grid.drawVertical(0,0,1); + grid.drawVertical(1,0,1); + + assertAll( + // complete box + () -> assertTrue(grid.boxComplete(0,0)), + // incomplete box + () -> assertFalse(grid.boxComplete(1,1)) + ); + } + + @Test + public void testDrawLine() { + + logger.info("Dummy test to show the Exception test runs"); + + // set up the test box + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(10,10,2); + + // draw a test line, player 1 + grid.drawHorizontal(0,0,1); + grid.drawVertical(0,0,1); + + // redraw lines to throw the exceptions + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0,0,1)); + assertThrows(IllegalStateException.class, () -> grid.drawVertical(0,0,1)); + } +} \ No newline at end of file -- GitLab