Skip to content
Snippets Groups Projects
Commit 3ae346ba authored by atravain's avatar atravain
Browse files

Added unit tests to perform checks on known bugs, These tests currently fail

parent 3473d067
No related branches found
No related tags found
No related merge requests found
......@@ -27,5 +27,40 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
// A test to check that the boxComplete function performs correctly
@Test
public void testBoxComplete() {
// Creates a grid with a box starting at (0,0)
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);
logger.info("This test checks that the boxComplete function works correctly");
assertAll(
"A complete box must return true, an incomplete must return false.",
() -> assertTrue(grid.boxComplete(0,0)),
// Returns false as the x,y co-ordinates passed are not the left and top co-ordinates of the box
() -> assertFalse(grid.boxComplete(1,1))
);
}
// A test to check that the program throws an exception when a player attempts to draw a line in a position that
// has already been played
@Test
public void testDrawLine() {
// Creates a grid and draws a horizontal and vertical line at (0,0)
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
grid.drawHorizontal(0, 0, 1);
grid.drawVertical(0, 0, 1);
logger.info("This test checks that an exception is thrown when a player tries to draw a line that is already drawn");
assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1), "The horizontal line was drawn more than once");
assertThrows(IllegalStateException.class, () -> grid.drawVertical(0, 0, 1), "The vertical line was drawn more than once");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment