From 164c674a6049fa7ec8a4e8e73bdf004ce48dd323 Mon Sep 17 00:00:00 2001 From: Juan Ludevid <jludevid@myune.edu.au> Date: Fri, 29 Jul 2022 16:30:28 +1000 Subject: [PATCH] first unit test creation --- .../dotsandboxes/DotsAndBoxesGridTest.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946bed..1c7f8b7 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -27,5 +27,39 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + // FIXME: You need to write tests for the two known bugs in the code. + @Test + public void boxCompleteDetectsCompletedBoxes() { + // code to test that boxComplete returns true for boxes that *are complete* goes here + DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(5, 5, 2); + case1.drawHorizontal(0, 0, 0); + case1.drawVertical(0, 0, 1); + case1.drawHorizontal(0, 1, 0); + case1.drawVertical(1, 0, 1); + assertTrue(case1.boxComplete(0, 0)); + } + @Test + public void boxCompleteDetectsIncompleteBoxes() { + // code to test that boxComplete returns false for boxes that *are not complete* goes here + DotsAndBoxesGrid case2 = new DotsAndBoxesGrid(5, 5, 2); + case2.drawHorizontal(0, 0, 0); + case2.drawVertical(0, 0, 1); + case2.drawHorizontal(0, 1, 0); + case2.drawVertical(0, 0, 1); + assertFalse(case2.boxComplete(0, 0)); + } + @Test + public void drawMethodsDetectRedrawnLines() { + // code to test that drawHorizontal throws an exception if the line was already drawn goes here + // code to test that drawVertical throws an exception if the line was already drawn goes here + DotsAndBoxesGrid case3 = new DotsAndBoxesGrid(5, 5, 2); + case3.drawHorizontal(0, 0, 1); + case3.drawVertical(0, 0, 1); + assertAll( + ()->assertThrows(IllegalStateException.class, ()-> case3.drawHorizontal(0, 0, 1), "No horizonal line has been drawn"), + ()->assertThrows(IllegalStateException.class, ()-> case3.drawVertical(0, 0, 1), "No vertical line has been drawn") + ); + + + } } -- GitLab