Skip to content
Snippets Groups Projects
Commit 69cd737b authored by Will Billingsley's avatar Will Billingsley
Browse files

Added Unit Tests

parent 122b79c0
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ package dotsandboxes; ...@@ -2,7 +2,6 @@ package dotsandboxes;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -28,4 +27,71 @@ public class DotsAndBoxesGridTest { ...@@ -28,4 +27,71 @@ public class DotsAndBoxesGridTest {
} }
// FIXME: You need to write tests for the two known bugs in the code. // FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testDrawHorizontalLineTwiceThrowsException() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
grid.drawHorizontal(0, 0, 1);
Exception exception = assertThrows(IllegalStateException.class, () -> {
grid.drawHorizontal(0, 0, 1);
});
String expectedMessage = "Line has already been drawn";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage), "Expected an IllegalStateException for drawing a line that was already drawn");
}
@Test
public void testDrawVerticalLineTwiceThrowsException() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
grid.drawVertical(0, 0, 1);
Exception exception = assertThrows(IllegalStateException.class, () -> {
grid.drawVertical(0, 0, 1);
});
String expectedMessage = "Line has already been drawn";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage), "Expected an IllegalStateException for drawing a line that was already drawn");
}
@Test
public void testBoxIncompleteAtLeftEdge() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Draw three lines around the box at (0,1)
grid.drawHorizontal(0, 1, 1);
grid.drawHorizontal(0, 2, 1);
grid.drawVertical(0, 1, 1);
assertFalse(grid.boxComplete(0, 1), "The box at (0,1) should not be complete with only three lines drawn");
}
@Test
public void testBoxIncomplete() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Draw only one horizontal line
grid.drawHorizontal(0, 0, 1);
assertFalse(grid.boxComplete(0, 0), "The box at (0,0) should not be complete with only one line drawn");
// Draw two lines (horizontal and vertical)
grid.drawVertical(0, 0, 1);
assertFalse(grid.boxComplete(0, 0), "The box at (0,0) should not be complete with only two lines drawn");
// Draw three lines
grid.drawHorizontal(0, 1, 1);
assertFalse(grid.boxComplete(0, 0), "The box at (0,0) should not be complete with only three lines drawn");
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment