Skip to content
Snippets Groups Projects
Commit 49ee7591 authored by sbuchan9's avatar sbuchan9
Browse files

Added new unit tests to test the boxComplete method is working, and also that...

Added new unit tests to test the boxComplete method is working, and also that drawing the same line twice throws an exception
parent bb7b1126
No related branches found
No related merge requests found
......@@ -26,6 +26,49 @@ public class DotsAndBoxesGridTest {
logger.info("Dummy test to show the test suite runs");
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testBoxCompleteWorking() {
logger.info("Test that box completion is true for a valid box coordinate");
// First draw a valid box
DotsAndBoxesGrid dotsAndBoxesGrid = new DotsAndBoxesGrid(8, 8, 2);
dotsAndBoxesGrid.drawHorizontal(1, 1, 1);
dotsAndBoxesGrid.drawHorizontal(1, 2, 1);
dotsAndBoxesGrid.drawVertical(1, 1, 1);
dotsAndBoxesGrid.drawVertical(2, 1, 1);
// Assert our box is valid
boolean isBox = dotsAndBoxesGrid.boxComplete(1, 1);
assertTrue(isBox);
// Now we will test with an invalid box, which should fail
logger.info("Test that box completion is false for an invalid box coordinate");
// First draw only a partial box
dotsAndBoxesGrid = new DotsAndBoxesGrid(8, 8, 2);
dotsAndBoxesGrid.drawHorizontal(1, 1, 1);
dotsAndBoxesGrid.drawHorizontal(1, 2, 1);
dotsAndBoxesGrid.drawVertical(1, 1, 1);
// Now assert an unfinished box isn't valid
isBox = dotsAndBoxesGrid.boxComplete(1, 1);
assertFalse(isBox);
}
@Test
public void testDoubleDrawForbidden() {
logger.info("Test that drawing the same line twice is forbidden (horizontal)");
// Instantiate the grid and draw a horizontal line twice, assert an exception
DotsAndBoxesGrid dotsAndBoxesGrid = new DotsAndBoxesGrid(8, 8, 2);
dotsAndBoxesGrid.drawHorizontal(1, 1, 1);
assertThrows(Exception.class, () -> dotsAndBoxesGrid.drawHorizontal(1, 1, 1));
logger.info("Test that drawing the same line twice is forbidden (vertical)");
// Instantiate the grid and draw a vertical line twice, assert an exception
DotsAndBoxesGrid dotsAndBoxesGrid2 = new DotsAndBoxesGrid(8, 8, 2);
dotsAndBoxesGrid2.drawVertical(1, 1, 1);
assertThrows(Exception.class, () -> dotsAndBoxesGrid2.drawVertical(1, 1, 1));
}
}
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