Select Git revision
-
Will Billingsley authoredWill Billingsley authored
DotsAndBoxesGridTest.java 5.81 KiB
package dotsandboxes;
import org.junit.jupiter.api.*;
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.Logger;
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);
/*
* Tests are functions that have an @Test annotation before them.
* 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
*/
@Test
public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs");
assertTrue(true);
}
/**
* Tests correct detection of completed boxes
*/
@Test
public void boxCompleteDetectsCompletedBoxes() {
// test top left corner box of grid
DotsAndBoxesGrid case1 = new DotsAndBoxesGrid(5, 5, 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 bottom right corner box of grid
DotsAndBoxesGrid case2 = new DotsAndBoxesGrid(5, 5, 2);
case2.drawHorizontal(3, 3, 0);
case2.drawVertical(3, 3, 1);
case2.drawHorizontal(3, 4, 0);
case2.drawVertical(4, 3, 1);
assertTrue(case2.boxComplete(3,3));
// test grid with 1 box
DotsAndBoxesGrid case3 = new DotsAndBoxesGrid(2, 2, 2);
case3.drawHorizontal(0, 0, 0);
case3.drawVertical(0, 0, 1);
case3.drawHorizontal(0, 1, 0);
case3.drawVertical(1, 0, 1);
assertTrue(case3.boxComplete(0,0));
// test a box around the center of grid
DotsAndBoxesGrid case4 = new DotsAndBoxesGrid(5, 5, 2);
case4.drawHorizontal(2, 2, 0);
case4.drawVertical(2, 2, 1);
case4.drawHorizontal(2, 3, 0);
case4.drawVertical(3, 2, 1);
assertTrue(case4.boxComplete(2,2));
}