Skip to content
Snippets Groups Projects
Commit 1a50fa77 authored by gbrown31's avatar gbrown31
Browse files

Added tests

 - Added test that detects complete boxes
 - Added test that detects incomplete boxes
 - Added test that ensures box check occurs within game bounds
 - Added test that checks that horizontal and vertical lines are not duplicated
 - Added test that ensures lines are drawn within game bounds
parent a5c78581
No related branches found
No related tags found
No related merge requests found
package dotsandboxes;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;
import dotsandboxes.DotsAndBoxesGrid;
import dotsandboxes.DotsAndBoxesUI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.*;
public class DotsAndBoxesGridTest {
/*
* Because Test classes are classes, they can have fields, and can have static fields.
* This field is a logger. Loggers are like a more advanced println, for writing messages out to the console or a log file.
*/
private static final Logger logger = LogManager.getLogger(DotsAndBoxesGridTest.class);
private static final Logger logger = LogManager.getLogger(
DotsAndBoxesGridTest.class
);
/*
* Tests are functions that have an @Test annotation before them.
......@@ -27,5 +31,103 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
final int width = 5;
final int height = 5;
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void boxCompleteDetectsCompletedBoxes() {
/*
* Box is complete
*/
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(width, height, 2);
case1.drawHorizontal(0, 0, 0);
case1.drawVertical(0, 0, 1);
case1.drawHorizontal(0, 1, 0);
case1.drawVertical(1, 0, 1);
assertTrue(case1.boxComplete(0, 0));
}
@Test
public void boxCompleteDetectsIncompleteBoxes() {
/*
* Box is incomplete
*/
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(width, height, 2);
case1.drawHorizontal(0, 0, 0);
case1.drawVertical(0, 0, 1);
case1.drawHorizontal(0, 1, 0);
assertFalse(case1.boxComplete(0, 0));
}
@Test
public void boxCompleteStaysWithinBounds() {
/*
* Box is within game board bounds
*/
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(width, height, 2);
assertFalse(case1.boxComplete(-1, 0));
assertFalse(case1.boxComplete(width, 0));
assertFalse(case1.boxComplete(0, height));
assertFalse(case1.boxComplete(0, -1));
}
@Test
public void drawMethodsDetectRedrawnLines() {
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(width, height, 2);
/*
* Drawn lines are not duplicated
*/
case1.drawHorizontal(0, 0, 0);
assertThrows(
RuntimeException.class,
() -> {
case1.drawHorizontal(0, 0, 0);
}
);
case1.drawVertical(0, 0, 0);
assertThrows(
RuntimeException.class,
() -> {
case1.drawVertical(0, 0, 0);
}
);
/*
* Drawn lines are within game board bounds
*/
assertThrows(
RuntimeException.class,
() -> {
case1.drawHorizontal(-1, 0, 0);
}
);
assertThrows(
RuntimeException.class,
() -> {
case1.drawHorizontal(width, 0, 0);
}
);
assertThrows(
IndexOutOfBoundsException.class,
() -> {
case1.drawVertical(0, -1, 0);
}
);
assertThrows(
IndexOutOfBoundsException.class,
() -> {
case1.drawVertical(0, height, 0);
}
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment