Skip to content
Snippets Groups Projects
Commit aee39a57 authored by mhay23's avatar mhay23
Browse files

Wrote unit tests for known bugs

parent 07df38de
No related branches found
No related tags found
No related merge requests found
Pipeline #1412 failed
......@@ -13,6 +13,18 @@ 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);
public static DotsAndBoxesGrid grid;
@BeforeAll
public static void beforeAll(){
logger.info("Running 'before all' setup");
}
@BeforeEach
public void beforeEach(){
logger.info("Running 'before each' setup");
grid = new DotsAndBoxesGrid(3,3,2);
}
/*
* Tests are functions that have an @Test annotation before them.
......@@ -28,4 +40,35 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testBoxIsComplete() {
logger.info("Checking completed box is correctly detected");
//empty grid, test top left box
assertFalse(grid.boxComplete(0,0));
//draw top horizontal and test
grid.drawHorizontal(0,0,1);
assertFalse(grid.boxComplete(0,0));
//draw left vertical and test
grid.drawVertical(0,0,1);
assertFalse(grid.boxComplete(0,0));
//draw bottom horizontal and test
grid.drawHorizontal(0,1,1);
assertFalse(grid.boxComplete(0,0));
//draw right vertical and test, box now complete
grid.drawVertical(1,0,1);
assertTrue(grid.boxComplete(0,0));
}
@Test
public void testCantRedrawLine(){
//draw line first time
grid.drawHorizontal(0,0,1);
assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0,0,2));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment