Skip to content
Snippets Groups Projects
Commit 60f6a15f authored by Carol-Ann Donaldson's avatar Carol-Ann Donaldson
Browse files

Added unit tests for square completion and duplicate line drawing

parent 2a54e73e
No related branches found
No related tags found
1 merge request!1Resolve "Fix assignment errors"
package dotsandboxes; package dotsandboxes;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.Test;
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;
public class DotsAndBoxesGridTest { 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.
* 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 @Test
public void testTestSuiteRuns() { public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs"); logger.info("Dummy test to show the test suite runs");
assertTrue(true); assertTrue(true);
} }
@Test @Test
public void testSquareCompletion() { public void testSquareCompletion() {
logger.info("Testing if square completion detection is working"); logger.info("Testing if square completion detection is working");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3);
// Initialize the grid with dimensions and number of players
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Simulate drawing lines to complete a square at (0,0) // Simulate drawing lines to complete a square at (0,0)
grid.drawHorizontal(0, 0, 1); grid.drawHorizontal(0, 0, 1);
...@@ -37,14 +27,16 @@ public class DotsAndBoxesGridTest { ...@@ -37,14 +27,16 @@ public class DotsAndBoxesGridTest {
grid.drawHorizontal(0, 1, 1); grid.drawHorizontal(0, 1, 1);
grid.drawVertical(1, 0, 1); grid.drawVertical(1, 0, 1);
// The square at (0,0) should be complete // Check if the square at (0,0) is complete
assertTrue(grid.isSquareComplete(0, 0), "Square at (0,0) should be complete"); assertTrue(grid.boxComplete(0, 0), "Square at (0,0) should be complete");
} }
@Test @Test
public void testDrawingLineTwiceThrowsException() { public void testDrawingLineTwiceThrowsException() {
logger.info("Testing if drawing a line twice throws an IllegalStateException"); logger.info("Testing if drawing a line twice throws an IllegalStateException");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3);
// Initialize the grid with dimensions and number of players
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Simulate drawing a horizontal line // Simulate drawing a horizontal line
grid.drawHorizontal(0, 0, 1); grid.drawHorizontal(0, 0, 1);
...@@ -53,3 +45,4 @@ public class DotsAndBoxesGridTest { ...@@ -53,3 +45,4 @@ public class DotsAndBoxesGridTest {
assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1)); assertThrows(IllegalStateException.class, () -> grid.drawHorizontal(0, 0, 1));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment