Skip to content
Snippets Groups Projects
Commit 79cd9035 authored by Will Billingsley's avatar Will Billingsley
Browse files

Add failing unit tests to highlight known bugs in DotsAndBoxesGrid

parent 8e4e51b2
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ public class DotsAndBoxesGridTest {
* This field is a logger. Loggers are like a more advanced println, for writing messages out to the console or a log file.
*/
private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class);
private DotsAndBoxesGrid grid;
/*
* Tests are functions that have an @Test annotation before them.
......@@ -27,5 +28,38 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
@BeforeEach
public void setup() {
grid = new DotsAndBoxesGrid(3, 3, 2); // Assuming a 3x3 grid with 2 players
}
@Test
public void testBoxNotCompleteInitially() {
assertFalse(grid.boxComplete(0, 0), "Box should not be complete without any lines drawn.");
}
@Test
public void testCompleteBox() {
// Draw all four lines around a single box
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), "Box at (0, 0) should be complete.");
}
@Test
public void testRedrawingHorizontalLineThrowsException() {
grid.drawHorizontal(0, 0, 1);
Exception exception = assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1));
assertEquals("Line already drawn.", exception.getMessage(), "Should throw an exception when redrawing a horizontal line.");
}
@Test
public void testRedrawingVerticalLineThrowsException() {
grid.drawVertical(0, 0, 1);
Exception exception = assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1));
assertEquals("Line already drawn.", exception.getMessage(), "Should throw an exception when redrawing a vertical line.");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment