diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..623a308bc6a57189af730efded58d174ec06a3e3 Binary files /dev/null and b/.DS_Store differ diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..cb847ec45cac29cd123711ad6222d944413569c4 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -26,6 +26,68 @@ public class DotsAndBoxesGridTest { logger.info("Dummy test to show the test suite runs"); assertTrue(true); } + + @Test + public void testBoxCompleteFalse() { + //Creating a box that should be incorrect and checking if it returns false + DotsAndBoxesGrid boxCompleteFalse = new DotsAndBoxesGrid(5, 5, 2); + boxCompleteFalse.drawHorizontal(0, 0, 0); + boxCompleteFalse.drawVertical(0, 0, 1); + boxCompleteFalse.drawHorizontal(0, 1, 0); + boxCompleteFalse.drawVertical(1, 1, 1); + + assertFalse(boxCompleteFalse.boxComplete(0, 0)); + } + + @Test + public void testBoxCompleteTrue() { + //Creating a box that should be correct and checking if it returns true + DotsAndBoxesGrid boxCompleteTrue = new DotsAndBoxesGrid(5, 5, 2); + boxCompleteTrue.drawHorizontal(0, 0, 0); + boxCompleteTrue.drawVertical(0, 0, 1); + boxCompleteTrue.drawHorizontal(0, 1, 0); + boxCompleteTrue.drawVertical(1, 0, 1); + + assertTrue(boxCompleteTrue.boxComplete(0, 0)); + } + + @Test + public void testDrawHorizontalDrawn() { + //Draws a horizontal line, then draws another horizontal line in the same + //place to check if an exception is appropriately thrown + DotsAndBoxesGrid horizontalDrawn = new DotsAndBoxesGrid(5, 5, 1); + horizontalDrawn.drawHorizontal(0, 0, 1); + assertThrows(RuntimeException.class, () -> { + horizontalDrawn.drawHorizontal(0, 0, 1); + }); + } - // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void testDrawHorizontalNotDrawn() { + //Draws a horizontal line to check if no exception is thrown + DotsAndBoxesGrid horizontalNotDrawn = new DotsAndBoxesGrid(5, 5, 1); + assertDoesNotThrow(() -> { + horizontalNotDrawn.drawHorizontal(0, 0, 1); + }); + } + + @Test + public void testDrawVerticalDrawn() { + //Draws a vertical line, then draws another vertical line in the same + //place to check if an exception is appropriately thrown + DotsAndBoxesGrid verticalDrawn = new DotsAndBoxesGrid(5, 5, 1); + verticalDrawn.drawVertical(0, 0, 1); + assertThrows(RuntimeException.class, () -> { + verticalDrawn.drawVertical(0, 0, 1); + }); + } + + @Test + public void testDrawVerticalNotDrawn() { + //Draws a vertical line to check if no exception is thrown + DotsAndBoxesGrid verticalNotDrawn = new DotsAndBoxesGrid(5, 5, 1); + assertDoesNotThrow(() -> { + verticalNotDrawn.drawVertical(0, 0, 1); + }); + } }