Skip to content

Commit

Permalink
EmptyFieldTest
Browse files Browse the repository at this point in the history
added test to EmptyFieldTest
added comments to tests in EmptyFieldTest
  • Loading branch information
Kevin-771 committed Oct 10, 2023
1 parent 12eb296 commit cf72a81
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
72 changes: 62 additions & 10 deletions src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,114 @@ public static void setUp() {
treetent = new TreeTent();
}

// creates a 3x3 puzzle with no trees
// make the (1,1) tile GRASS
// checks if tiles logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyField", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

// change the board's cells considering the EmptyField rule
TreeTentCell cell1 = board.getCell(1, 1);
cell1.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Point point = new Point(k, i);
if (point.equals(cell1.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

// creates a 3x3 puzzle with 4 trees
// trees are at (0,0), (2,0), (0,2), and (2,2)
// make the (1,1) tile GRASS.
// checks if tiles logically follow the EmptyFieldDirectRule
@Test
public void DiagonalTreeTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/DiagonalTree", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

//change the board's cells considering the EmptyField rule
TreeTentCell cell1 = board.getCell(1, 1);
cell1.setData(TreeTentType.GRASS);

board.addModifiedData(cell1);

// confirm there is a logical following of the EmptyField rule
Assert.assertNull(RULE.checkRule(transition));

// only the cell above should change following the rule
TreeTentCell c;
for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Point point = new Point(k, i);
if (point.equals(cell1.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
c = board.getCell(k, i);
if (c.getLocation().equals(cell1.getLocation())) {
// logically follows
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

// creates a 3x3 puzzle with 4 trees
// trees are at (0,1), (1,0), (1,2), and (2,1)
// make the center tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFail() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

// get board state
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

//change the board's cells considering breaking the EmptyField rule
TreeTentCell cell1 = board.getCell(1, 1);
cell1.setData(TreeTentType.GRASS);
board.addModifiedData(cell1);

// confirm there is not a logical following of the EmptyField rule
Assert.assertNotNull(RULE.checkRule(transition));

// the cells should not follow the rule
TreeTentCell c;
for (int i = 0; i < board.getWidth(); i++) {
for (int j = 0; j < board.getHeight(); j++) {
c = board.getCell(j, i);
// does not use the rule to logically follow
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="1" x="1" y="0"/>
<cell value="1" x="0" y="1"/>
<cell value="1" x="2" y="1"/>
<cell value="1" x="1" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="3" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit cf72a81

Please sign in to comment.