Skip to content
Snippets Groups Projects
Commit 649cf71c authored by Hayden James Swift's avatar Hayden James Swift
Browse files

Implemented testing functions to DotsAndBoxesGridTest.java

parent f4f0b8f1
No related branches found
No related merge requests found
......@@ -27,5 +27,69 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
/*
* This tests the boxComplete() function.
*/
@Test
public void testForBoxComplete() {
logger.info("Testing if box is complete.");
// Create new grid instance
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Draw half a box
grid.drawVertical(1, 1, 1);
grid.drawVertical(2, 1, 1);
// Test boxComplete() function
assertFalse(grid.boxComplete(1, 1));
// Draw remaining lines
grid.drawHorizontal(1, 1, 1);
grid.drawHorizontal(1, 2, 1);
// Test boxComplete() function
assertTrue(grid.boxComplete(1, 1));
}
/*
* Test for drawHorizontal() function.
*/
@Test
public void testDrawHorizontal() {
logger.info("Testing drawHorizontal()");
// Initialise new DotsAndBoxesGrid instance and new player
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
int player = 1;
// Draw new line at (1, 1). This should return false as the box is not complete.
assertFalse(grid.drawHorizontal(1, 1, player));
// Try redraw line at (1, 1). This should throw an IllegalStateException.
assertThrows(IllegalStateException.class, () -> {
grid.drawHorizontal(1, 1, player);
});
}
/*
* Test for drawVertical() function.
*/
@Test
public void testDrawVertical() {
logger.info("Testing drawVertical()");
// Initialise new DotsAndBoxesGrid instance and new player
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
int player = 1;
// Draw new line at (1, 1). This should return false as the box is not complete.
assertFalse(grid.drawVertical(1, 1, player));
// Try redraw line at (1, 1). This should throw an IllegalStateException.
assertThrows(IllegalStateException.class, () -> {
grid.drawVertical(1, 1, player);
});
}
}
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