Skip to content
Snippets Groups Projects
Commit e0fe5c10 authored by Alex Milliken's avatar Alex Milliken
Browse files

Added unit tests

1. Added tests to confirm whether the boxComplete method was functioning correctly. Specifically whether it returns true for a complete box AND false for an incomplete box.

2. Added a test to confirm whether the drawVertical and drawHorizontal methods were detecting and throwing an exception for attempting to draw lines that already existed.

3. Removed FIXME line from previously updated name label
parent 0b09ce33
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,6 @@ public class Main { ...@@ -11,7 +11,6 @@ public class Main {
JFrame mainWindow = new JFrame("Dots and Boxes"); JFrame mainWindow = new JFrame("Dots and Boxes");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2); 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"); JLabel label = new JLabel("Name: Alex Milliken | Student Number: 220275842");
JPanel borderPane = new JPanel(new BorderLayout()); JPanel borderPane = new JPanel(new BorderLayout());
......
...@@ -27,5 +27,45 @@ public class DotsAndBoxesGridTest { ...@@ -27,5 +27,45 @@ public class DotsAndBoxesGridTest {
assertTrue(true); 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));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment