Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1-fix-assignment-errors
  • main
  • testsfail
3 results

Target

Select target project
  • jllamera/cosc220-assessment2
1 result
Select Git revision
  • 1-fix-assignment-errors
  • main
  • testsfail
3 results
Show changes
Commits on Source (3)
......@@ -112,8 +112,12 @@ public class DotsAndBoxesGrid {
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first).
else if (getHorizontal(x, y) && getHorizontal(x, y + 1)
&& getVertical(x, y) && getVertical(x + 1, y)) {
return true;
}
return false;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
private boolean claimBox(int x, int y, int p) {
......@@ -140,6 +144,9 @@ public class DotsAndBoxesGrid {
}
// FIXME: You need to throw an exception if the line was already drawn.
if (horizontals[x][y]) {
throw new IllegalStateException("Line has been already drawn!");
}
this.horizontals[x][y] = true;
......@@ -171,8 +178,11 @@ public class DotsAndBoxesGrid {
}
// You need to throw an exception if the line was already drawn.
if (verticals[x][y]) {
throw new IllegalStateException("Line has been already drawn!");
}
this.verticals[x][y] = true;
// Try to claim the north or south boxes
boolean claimE = claimBox(x, y, player);
boolean claimW = claimBox(x-1, y, player);
......
......@@ -12,7 +12,7 @@ public class Main {
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: Jennica Llamera 220278632");
JPanel borderPane = new JPanel(new BorderLayout());
borderPane.add(label, BorderLayout.SOUTH);
......
......@@ -2,25 +2,34 @@ 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.
* 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 DotsAndBoxesGrid gridTest;
/*
* 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
* 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
*/
@BeforeEach
public void setup() {
// Setting up a new DotsAndBoxesGrid for every test
gridTest = new DotsAndBoxesGrid(4, 4, 2);
}
@Test
public void testTestSuiteRuns() {
logger.info("Dummy test to show the test suite runs");
......@@ -28,4 +37,25 @@ public class DotsAndBoxesGridTest {
}
// FIXME: You need to write tests for the two known bugs in the code.
@Test
public void testBoxCompletion() {
logger.info("Testing box completion");
gridTest.drawHorizontal(0, 0, 1);
gridTest.drawVertical(0, 0, 1);
gridTest.drawHorizontal(0, 1, 1);
gridTest.drawVertical(1, 0, 1);
assertTrue(gridTest.boxComplete(0,0), "Box should be completed");
}
@Test
public void testVerticalLineRedrawn() {
logger.info("Testing if throws exception if redrawn a line ");
gridTest.drawVertical(0, 0, 1);
assertThrows(IllegalStateException.class, () -> gridTest.drawVertical(0, 0, 1));
}
}