Skip to content
Snippets Groups Projects
Commit 13c3b093 authored by kalpana acharya's avatar kalpana acharya
Browse files

Add unit tests to detect assignment errors

parent 535b1581
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@ 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;
......@@ -27,5 +25,41 @@ public class DotsAndBoxesGridTest {
assertTrue(true);
}
// FIXME: You need to write tests for the two known bugs in the code.
// Test cases for known bugs
@Test
public void testSquareCompletionBug() {
logger.info("Testing square completion logic");
// Create a new game grid
DotsAndBoxesGrid grid = new DotsAndBoxesGrid();
// Draw lines to form a square
grid.drawLine(0, 0, 0, 1); // Top horizontal line
grid.drawLine(0, 0, 1, 0); // Left vertical line
grid.drawLine(0, 1, 1, 1); // Bottom horizontal line
grid.drawLine(1, 0, 1, 1); // Right vertical line
// Test if the square at (0, 0) is complete
boolean isComplete = grid.isSquareComplete(0, 0);
// The bug is that isSquareComplete always returns true
assertFalse(isComplete, "The square completion check should fail because the method is broken.");
}
@Test
public void testDrawLineTwiceThrowsException() {
logger.info("Testing drawing the same line twice throws exception");
// Create a new game grid
DotsAndBoxesGrid grid = new DotsAndBoxesGrid();
// Draw a line once
grid.drawLine(0, 0, 0, 1);
// Attempt to draw the same line again
assertThrows(IllegalStateException.class, () -> {
grid.drawLine(0, 0, 0, 1);
}, "Drawing the same line twice should throw IllegalStateException.");
}
}
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