From 4450a8e9f32e956f565f7068e8d70cfc9a985a1f Mon Sep 17 00:00:00 2001 From: Steve Mckinnon <smckin27@myune.edu.au> Date: Tue, 20 Jul 2021 12:30:12 +1000 Subject: [PATCH] created tests to check complete box and redraw line --- .../dotsandboxes/DotsAndBoxesGridTest.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1aac7cc..6030871 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -14,18 +14,39 @@ public class DotsAndBoxesGridTest { */ private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class); + /* - * Tests are functions that have an @Test annotation before them. - * The typical format of a test is that it contains some code that does something, and then one - * or more assertions to check that a condition holds. - * - * This is a dummy test just to show that the test suite itself runs - */ + * A test to check if a box is correctly marked as complete. + * Asserting False after drawing a complete box + */ + + @Test - public void testTestSuiteRuns() { - logger.info("Dummy test to show the test suite runs"); - assertTrue(true); + public void testForCompleteBox() { + logger.info("Testing the complete box"); + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(10,10,2); + + grid.drawHorizontal(1,1,1); + grid.drawHorizontal(1,2,1); + grid.drawVertical(1,1,1); + grid.drawVertical(2,1,1); + + assertFalse(grid.boxComplete(1, 1)); } - // FIXME: You need to write tests for the two known bugs in the code. + + /* + * A test to see if a line can be redrawn after it has already been drawn, + * test should throw an exception + */ + @Test + public void testRedrawLineFails() { + logger.info("Testing redrawing a line"); + + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(10,10,2); + + grid.drawVertical(5,5,1); + + assertThrows(IllegalStateException.class, () -> grid.drawVertical(5, 5, 1)); + } } -- GitLab