Skip to content
Snippets Groups Projects
Commit 5c0457ce authored by Chelsea Allen's avatar Chelsea Allen
Browse files

Add unit tests for bugs

1. Test boxComplete detects completed boxes and returns false for incomplete boxes.

2. Test horizontal and vertical draw methods throw exceptions for already-drawn lines.
parent d4c69bbe
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment