Skip to content

Commit

Permalink
Merge pull request #637 from Kevin-771/emptyFieldTests
Browse files Browse the repository at this point in the history
added EmptyFieldTest
  • Loading branch information
jac-oblong authored Oct 27, 2023
2 parents ab59072 + f565c78 commit 14ef71c
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 10 deletions.
204 changes: 194 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,246 @@ 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 (1,1) 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));
}
}
}

// creates a 3x3 puzzle with 1 tree
// tree is at (1,0)
// make the (1,1) tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFailTop() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop", 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));
}
}
}

// creates a 3x3 puzzle with 1 tree
// tree is at (1,2)
// make the (1,1) tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFailTopBottom() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom", 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));
}
}
}

// creates a 3x3 puzzle with 1 tree
// tree is at (0,1)
// make the (1,1) tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFailLeft() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft", 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));
}
}
}

// creates a 3x3 puzzle with 1 tree
// tree is at (2,1)
// make the (1,1) tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFailRight() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight", 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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="1" x="0" y="1"/>
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="1" x="2" y="1"/>
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="1" x="1" y="0"/>
</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 14ef71c

Please sign in to comment.