diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..c9a990e07211f725ae51a3312810b8fb266ed911 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -19,13 +19,51 @@ public class DotsAndBoxesGridTest { * 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 */ + + // Unit test to determine if the boxComplete algorithm correctly discerns a box is complete + // This test is currently vacuously true - it's not failing but that isn't indicative of + // the algorithm working - the function simply always returns true for values of x and y where + // 0 < x < width-1 OR 0 < y < height-1 @Test - public void testTestSuiteRuns() { - logger.info("Dummy test to show the test suite runs"); - assertTrue(true); - } + public void testBoxIsComplete() { + // test against box that is known to be complete + DotsAndBoxesGrid test1 = new DotsAndBoxesGrid(4, 4, 2); + test1.drawHorizontal(0, 0, 0); + test1.drawVertical(0, 0, 1); + test1.drawHorizontal(0, 1, 0); + test1.drawVertical(1, 0, 1); + assertTrue(test1.boxComplete(0, 0)); + } + + // Unit test to determine if the boxComplete correctly discerns a box is not complete + @Test + public void testBoxIsNotComplete() { + // test against 'box' that is known to not be complete + DotsAndBoxesGrid test2 = new DotsAndBoxesGrid(6, 6, 2); + test2.drawHorizontal(0, 0, 0); + test2.drawVertical(0, 0, 1); + test2.drawHorizontal(2, 0, 0); + test2.drawVertical(2, 0, 1); + assertFalse(test2.boxComplete(0, 0)); + } - // FIXME: You need to write tests for the two known bugs in the code. + // Unit test to determine if the horizontal draw function permits you to draw over a line that has already been drawn + @Test + public void testHorizontalLineAlreadyDrawn() { + DotsAndBoxesGrid test = new DotsAndBoxesGrid(5, 5, 2); + test.drawHorizontal(1, 0, 0); + assertThrows(IllegalStateException.class, () -> { + test.drawHorizontal(1, 0, 0); + }); + } + // Unit test to determine if the vertical draw function permits you to draw over a line that has already been drawn + @Test + public void testVerticalLineAlreadyDrawn() { + DotsAndBoxesGrid test = new DotsAndBoxesGrid(5, 5, 2); + test.drawVertical(1, 0, 0); + assertThrows(IllegalStateException.class, () -> { + test.drawVertical(1, 0, 0); + }); + } }