diff --git a/src/main/java/dotsandboxes/LineAlreadyDrawnException.java b/src/main/java/dotsandboxes/LineAlreadyDrawnException.java new file mode 100644 index 0000000000000000000000000000000000000000..6d5541de2f9fef31fce16fc5d23cf83ad10ebdda --- /dev/null +++ b/src/main/java/dotsandboxes/LineAlreadyDrawnException.java @@ -0,0 +1,4 @@ +package dotsandboxes; +import java.lang.Exception; + +public class LineAlreadyDrawnException extends Exception{} \ No newline at end of file diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..3f6a3bbeaa96760992d75c6f863cd7d150dd9beb 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -21,11 +21,48 @@ public class DotsAndBoxesGridTest { * * This is a dummy test just to show that the test suite itself runs */ + + + // FIXME: You need to write tests for the two known bugs in the code. @Test - public void testTestSuiteRuns() { - logger.info("Dummy test to show the test suite runs"); - assertTrue(true); + public void testExisitingHorizontalLineThrowsException() { + DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2); + dbg.drawHorizontal(0, 0, 0); + assertThrows(LineAlreadyDrawnException.class, () -> {dbg.drawHorizontal(0, 0, 0);}); } - // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void testExisitingVerticalLineThrowsException() { + DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2); + dbg.drawVertical(0, 0, 0); + assertThrows(LineAlreadyDrawnException.class, () -> {dbg.drawVertical(0, 0, 0);}); + } + + @Test + public void testOutOfBoundsHorizontalLineThrowsException() { + DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2); + + assertThrows(IndexOutOfBoundsException.class, () -> {dbg.drawHorizontal(4, 0, 0);}); + } + + + + @Test + public void testBoxComplete() { + DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2); + assertEquals(dbg.boxComplete(0,0),false); + dbg.drawHorizontal(0,0,0); + assertEquals(dbg.boxComplete(0,0),false); + dbg.drawVertical(0,0,0); + assertEquals(dbg.boxComplete(0,0),false); + dbg.drawVertical(1,0,0); + assertEquals(dbg.boxComplete(0,0),false); + dbg.drawHorizontal(0,1,0); + assertEquals(dbg.boxComplete(0,0),true); + + } + + + + }