diff --git a/src/main/java/dotsandboxes/Main.java b/src/main/java/dotsandboxes/Main.java index 0e7a44b686d86fbcd5d4f4cebaf4c086746912b9..21d2eafa2b209c10be7ff185936e79e34ca58a11 100644 --- a/src/main/java/dotsandboxes/Main.java +++ b/src/main/java/dotsandboxes/Main.java @@ -11,7 +11,6 @@ public class Main { JFrame mainWindow = new JFrame("Dots and Boxes"); DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); - // FIXME: Update this label to show your name and student number JLabel label = new JLabel("Name: Alex Milliken | Student Number: 220275842"); JPanel borderPane = new JPanel(new BorderLayout()); diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..27f6f4693465c3773c0dad1b3f653890b115265a 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -27,5 +27,45 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + /* + * This test draws a box and checks that the box is drawn. + * Given that the boxComplete method always returns true, this test should always pass. + */ + @Test + public void boxCompleteDetectsCompletedBoxes() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawHorizontal(0, 1, 1); + grid.drawVertical(0, 0, 1); + grid.drawVertical(1, 0, 1); + assertTrue(grid.boxComplete(0, 0)); + } + + /* + * This test draws an incomplete box and checks that the box is not drawn. + * Given that the boxComplete method always returns true, this test should always fail. + */ + @Test + public void boxCompleteDetectsIncompleteBoxes() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawHorizontal(0, 1, 1); + grid.drawVertical(0, 0, 1); + assertFalse(grid.boxComplete(0, 0)); + } + + + /* + * This test detects whether the drawHorizontal and drawVertical methods throw an exception if the line already has been drawn. + * Given that the drawHorizontal and drawVertical methods do not currently throw an exception, this test should always fail. + */ + @Test + public void drawMethodsDetectRedrawnLines() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2); + grid.drawHorizontal(0, 0, 1); + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1)); + grid.drawVertical(0, 0, 1); + assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1)); + } + }