From be1aea3dddff2531fd1428cee53381b3f61f88f2 Mon Sep 17 00:00:00 2001 From: Steve Smith <ssmit235@myune.edu.au> Date: Fri, 30 Jul 2021 11:34:57 +0800 Subject: [PATCH] Add tests to check exception is thrown when line already drawn. Add test to check box is complete. --- .../LineAlreadyDrawnException.java | 4 ++ .../dotsandboxes/DotsAndBoxesGridTest.java | 45 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/main/java/dotsandboxes/LineAlreadyDrawnException.java diff --git a/src/main/java/dotsandboxes/LineAlreadyDrawnException.java b/src/main/java/dotsandboxes/LineAlreadyDrawnException.java new file mode 100644 index 0000000..6d5541d --- /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 1946bed..3f6a3bb 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); + + } + + + + } -- GitLab