Skip to content
Snippets Groups Projects
Commit 53af0e51 authored by jnepali's avatar jnepali
Browse files

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

fixed the test cases and main code

See merge request !1
parents dd640054 a81670d4
Branches main
No related tags found
1 merge request!1fixed the test cases and main code
......@@ -8,11 +8,11 @@ public class Main {
public static void main(String... args) throws Exception {
JFrame mainWindow = new JFrame("Dots and Boxes");
JFrame mainWindow = new JFrame("Welcome to Dots and Boxes Games");
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(15, 8, 2);
// FIXME: Update this label to show your name and student number
JLabel label = new JLabel("Name: (Your name and student number goes here)");
JLabel label = new JLabel("Name: Jaya Nepali ");
JPanel borderPane = new JPanel(new BorderLayout());
borderPane.add(label, BorderLayout.SOUTH);
......
......@@ -28,4 +28,36 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testBoxCompletionDetection() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4, 3, 2);
// Draw four sides of a box (not completing it)
grid.drawHorizontal(0, 0, 1); // Top
grid.drawVertical(0, 0, 1); // Left
grid.drawHorizontal(0, 1, 1); // Bottom
grid.drawVertical(1,0,1); //Right
assertTrue(grid.boxComplete(0, 0), "The box should be completed.");
}
@Test
public void testDrawHorizontalLineAlreadyDrawn() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4,4,2);
grid.drawHorizontal(0, 0, 1);
assertThrows(IllegalStateException.class, () -> {
grid.drawHorizontal(0, 0, 1); // Drawing the same line should throw an exception
});
}
@Test
public void testDrawVerticalLineAlreadyDrawn() {
DotsAndBoxesGrid grid = new DotsAndBoxesGrid(4,4,2);
grid.drawVertical(0, 0, 1);
assertThrows(IllegalStateException.class, () -> {
grid.drawVertical(0, 0, 1); // Drawing the same line should throw an exception
});
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment