Skip to content
Snippets Groups Projects
Commit 0477818a authored by jphiri's avatar jphiri
Browse files

Run unit tests for bug fix 1

parent e9418ab9
No related branches found
No related tags found
No related merge requests found
......@@ -28,4 +28,61 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
void testBoxCompleteOnEdge() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players
assertFalse(grid.boxComplete(3, 2)); // The bottom-right corner, there's no box here
}
@Test
void testBoxCompleteOnEmptyBox() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players
assertFalse(grid.boxComplete(1, 1));
}
@Test
void testBoxCompleteOnCompletedBox() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2); // 4x3 grid with 2 players
// Draw all lines to complete a box at coordinates (1, 1)
grid.drawHorizontal(0, 1, 1);
grid.drawHorizontal(0, 2, 1);
grid.drawVertical(0, 1, 1);
grid.drawVertical(1, 1, 1);
// Test when the given coordinates represent a completed box
assertTrue(grid.boxComplete(1, 1));
}
//end here fix me
//fix 2
@Test
public void testDrawHorizontalOutOfBounds() {
int width = 4;
int height = 3;
int players = 2;
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(width, height, players);
// Test the out of bounds scenarios
assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(-1, 0, 1));
assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(width - 1, 0, 1));
assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(0, -1, 1));
assertThrows(IndexOutOfBoundsException.class, () -> grid.drawHorizontal(0, height, 1));
}
//end here
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment