Skip to content
Snippets Groups Projects
Commit 6c251d5f authored by Jack Scarfe's avatar Jack Scarfe
Browse files

Added Unit Tests that detect the errors in the code

parent 3ead5ba0
No related branches found
No related merge requests found
......@@ -19,13 +19,51 @@ public class DotsAndBoxesGridTest {
* The typical format of a test is that it contains some code that does something, and then one
* or more assertions to check that a condition holds.
*
* This is a dummy test just to show that the test suite itself runs
*/
// Unit test to determine if the boxComplete algorithm correctly discerns a box is complete
// This test is currently vacuously true - it's not failing but that isn't indicative of
// the algorithm working - the function simply always returns true for values of x and y where
// 0 < x < width-1 OR 0 < y < height-1
@Test
public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs");
assertTrue(true);
}
public void testBoxIsComplete() {
// test against box that is known to be complete
DotsAndBoxesGrid test1 = new DotsAndBoxesGrid(4, 4, 2);
test1.drawHorizontal(0, 0, 0);
test1.drawVertical(0, 0, 1);
test1.drawHorizontal(0, 1, 0);
test1.drawVertical(1, 0, 1);
assertTrue(test1.boxComplete(0, 0));
}
// Unit test to determine if the boxComplete correctly discerns a box is not complete
@Test
public void testBoxIsNotComplete() {
// test against 'box' that is known to not be complete
DotsAndBoxesGrid test2 = new DotsAndBoxesGrid(6, 6, 2);
test2.drawHorizontal(0, 0, 0);
test2.drawVertical(0, 0, 1);
test2.drawHorizontal(2, 0, 0);
test2.drawVertical(2, 0, 1);
assertFalse(test2.boxComplete(0, 0));
}
// FIXME: You need to write tests for the two known bugs in the code.
// Unit test to determine if the horizontal draw function permits you to draw over a line that has already been drawn
@Test
public void testHorizontalLineAlreadyDrawn() {
DotsAndBoxesGrid test = new DotsAndBoxesGrid(5, 5, 2);
test.drawHorizontal(1, 0, 0);
assertThrows(IllegalStateException.class, () -> {
test.drawHorizontal(1, 0, 0);
});
}
// Unit test to determine if the vertical draw function permits you to draw over a line that has already been drawn
@Test
public void testVerticalLineAlreadyDrawn() {
DotsAndBoxesGrid test = new DotsAndBoxesGrid(5, 5, 2);
test.drawVertical(1, 0, 0);
assertThrows(IllegalStateException.class, () -> {
test.drawVertical(1, 0, 0);
});
}
}
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