diff --git a/src/main/java/dotsandboxes/Main.java b/src/main/java/dotsandboxes/Main.java index 048ad466502c8e235869585c0280f99a4602281a..be056baeed834e35776dd55728682fce1b2470b7 100644 --- a/src/main/java/dotsandboxes/Main.java +++ b/src/main/java/dotsandboxes/Main.java @@ -11,7 +11,7 @@ public class Main { JFrame mainWindow = new JFrame("Dots and Boxes"); DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); - // Updated with name and student numer + // Updated with name and student number JLabel label = new JLabel("Name: Chelsea Allen (220155519)"); JPanel borderPane = new JPanel(new BorderLayout()); diff --git a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java index 1946beda974d180686c65c0259a7b881e9a4eb5a..326e174d607be235df7c52bc53ddc9d3f7f6120f 100644 --- a/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java +++ b/src/test/java/dotsandboxes/DotsAndBoxesGridTest.java @@ -27,5 +27,70 @@ public class DotsAndBoxesGridTest { assertTrue(true); } - // FIXME: You need to write tests for the two known bugs in the code. + /* + * Test if boxComplete returns true for complete box + */ + @Test + public void testBoxCompleteDetectsCompletedBoxes() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 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)); + } + + /* + * 3 tests to determine if boxComplete returns false for incomplete box (no lines, 1 line, 2 lines) + */ + @Test + public void testBoxCompleteNoLinesDrawn() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(20, 10, 2); + assertFalse(grid.boxComplete(0, 0)); + } + + @Test + public void testBoxCompleteOneLineDrawn() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(20, 10, 2); + grid.drawHorizontal(0, 0, 1); + assertFalse(grid.boxComplete(0, 0)); + } + + @Test + public void testBoxCompleteTwoLinesDrawn() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(20, 10, 2); + grid.drawHorizontal(0, 0, 1); + grid.drawVertical(0, 0, 1); + assertFalse(grid.boxComplete(0, 0)); + } + + /* + * Test if horizontal draw method throws exception for already-drawn lines + */ + @Test + public void testDrawHorizontalDetectsRedrawnLines() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(20, 10, 2); + + // draw a horizontal line at (0, 0) and claim a box + grid.drawHorizontal(0, 0, 1); + + // attempt to draw the same line, should throw an IllegalStateException + assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1)); + + } + + /* + * Test if vertical draw method throws exception for already-drawn lines + */ + @Test + public void testDrawVerticalDetectsRedrawnLines() { + DotsAndBoxesGrid grid = new DotsAndBoxesGrid(20, 10, 2); + + // draw a vertical line at (0, 0) and claim a box + grid.drawVertical(0, 0, 1); + + // attempt to draw the same line, should throw an IllegalStateException + assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1)); + + } }