diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..e3fed039d2e6f122ecf044db369adc29f770bc97 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -27,5 +27,40 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + // A test to check that the boxComplete function performs correctly + @Test + public void testBoxComplete() { + + // Creates a grid with a box starting at (0,0) + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawHorizontal(0, 1, 1); + grid.drawVertical(0, 0, 1); + grid.drawVertical(1, 0, 1); + + logger.info("This test checks that the boxComplete function works correctly"); + + assertAll( + "A complete box must return true, an incomplete must return false.", + () -> assertTrue(grid.boxComplete(0,0)), + // Returns false as the x,y co-ordinates passed are not the left and top co-ordinates of the box + () -> assertFalse(grid.boxComplete(1,1)) + ); + } + + // A test to check that the program throws an exception when a player attempts to draw a line in a position that + // has already been played + @Test + public void testDrawLine() { + + // Creates a grid and draws a horizontal and vertical line at (0,0) + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawVertical(0, 0, 1); + + logger.info("This test checks that an exception is thrown when a player tries to draw a line that is already drawn"); + + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1), "The horizontal line was drawn more than once"); + assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1), "The vertical line was drawn more than once"); + } }