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

Merge branch '1-fix-assignment-errors' into 'main'

Resolve "Fix assignment errors"

Closes #1

See merge request !1
parents 3f9f831d 60f6a15f
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);
} }
// FIXME: You need to write tests for the two known bugs in the code. @Test
public void testSquareCompletion() {
logger.info("Testing if square completion detection is working");
// 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)
grid.drawHorizontal(0, 0, 1);
grid.drawVertical(0, 0, 1);
grid.drawHorizontal(0, 1, 1);
grid.drawVertical(1, 0, 1);
// Check if the square at (0,0) is complete
assertTrue(grid.boxComplete(0, 0), "Square at (0,0) should be complete");
} }
@Test
public void testDrawingLineTwiceThrowsException() {
logger.info("Testing if drawing a line twice throws an IllegalStateException");
// Initialize the grid with dimensions and number of players
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(3, 3, 2);
// Simulate drawing a horizontal line
grid.drawHorizontal(0, 0, 1);
// Try drawing the same horizontal line again, which should throw an IllegalStateException
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