Skip to content
Snippets Groups Projects
Commit be1aea3d authored by ssmit235's avatar ssmit235
Browse files

Add tests to check exception is thrown when line already drawn.

Add test to check box is complete.
parent 7076d001
No related branches found
No related merge requests found
package dotsandboxes;
import java.lang.Exception;
public class LineAlreadyDrawnException extends Exception{}
\ No newline at end of file
......@@ -21,11 +21,48 @@ public class DotsAndBoxesGridTest {
*
* This is a dummy test just to show that the test suite itself runs
*/
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs");
assertTrue(true);
public void testExisitingHorizontalLineThrowsException() {
DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2);
dbg.drawHorizontal(0, 0, 0);
assertThrows(LineAlreadyDrawnException.class, () -> {dbg.drawHorizontal(0, 0, 0);});
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testExisitingVerticalLineThrowsException() {
DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2);
dbg.drawVertical(0, 0, 0);
assertThrows(LineAlreadyDrawnException.class, () -> {dbg.drawVertical(0, 0, 0);});
}
@Test
public void testOutOfBoundsHorizontalLineThrowsException() {
DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2);
assertThrows(IndexOutOfBoundsException.class, () -> {dbg.drawHorizontal(4, 0, 0);});
}
@Test
public void testBoxComplete() {
DotsAndBoxesGrid dbg = new DotsAndBoxesGrid(4, 3, 2);
assertEquals(dbg.boxComplete(0,0),false);
dbg.drawHorizontal(0,0,0);
assertEquals(dbg.boxComplete(0,0),false);
dbg.drawVertical(0,0,0);
assertEquals(dbg.boxComplete(0,0),false);
dbg.drawVertical(1,0,0);
assertEquals(dbg.boxComplete(0,0),false);
dbg.drawHorizontal(0,1,0);
assertEquals(dbg.boxComplete(0,0),true);
}
}
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