Skip to content
Snippets Groups Projects
Commit 9114ee1c authored by Ben OToole's avatar Ben OToole
Browse files

Added unit tests for boxComplete() algorithm and to check that a horizontal...

Added unit tests for boxComplete() algorithm and to check that a horizontal line is not drawn over a another horizontal line
parent 5fb20126
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,15 @@ public class DotsAndBoxesGridTest { ...@@ -14,6 +14,15 @@ public class DotsAndBoxesGridTest {
*/ */
private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class); private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class);
/*
* Added an annotated @BeforeAll function
*/
@BeforeAll
public static void beforeAll() {
logger.info("This message was printed out before any of the tests were run");
}
/* /*
* Tests are functions that have an @Test annotation before them. * Tests are functions that have an @Test annotation before them.
* The typical format of a test is that it contains some code that does something, and then one * The typical format of a test is that it contains some code that does something, and then one
...@@ -27,5 +36,39 @@ public class DotsAndBoxesGridTest { ...@@ -27,5 +36,39 @@ public class DotsAndBoxesGridTest {
assertTrue(true); assertTrue(true);
} }
// FIXME: You need to write tests for the two known bugs in the code.
/*
* textBoxComplete():
* Purpose: Test used for testing whether the algorithm used for boxComplete() is wrong.
*/
@Test
public void testBoxComplete() {
logger.info("Testing whether a box is complete");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(2, 2, 1);
if (grid.drawHorizontal(0, 0, 0) &&
grid.drawHorizontal(1, 0, 0) &&
grid.drawVertical(0, 0, 0) &&
grid.drawVertical(0, 1, 0)) {
assertTrue(grid.boxComplete(0, 0));
} else {
assertFalse(grid.boxComplete(0, 0));
}
}
/*
* testIsSameHorizontalLine()
* Purpose: Test used to throw an IllegalStateException if a line is drawn on an existing line.
*/
@Test
public void testIsSameHorizontalLine(){
logger.info("Testing if a line has already been drawn");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(2,2, 1);
grid.drawHorizontal(0,0,1);
assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0,0,1),
"Line already drawn");
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment