Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul of Various TreeTent Tests (Current Tests in Pull Request: 4) #635

Merged
merged 10 commits into from
Oct 17, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="-4" x="2" y="0"/>
</cells>
</board>
</puzzle>
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="-4" x="2" y="0"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="-4" x="0" y="2"/>
</cells>
</board>
</puzzle>
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="-4" x="0" y="2"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.rpi.legup.model.PuzzleExporter;
import edu.rpi.legup.model.gameboard.PuzzleElement;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import org.w3c.dom.Document;

public class FillapixExporter extends PuzzleExporter {
Expand All @@ -15,7 +16,7 @@ protected org.w3c.dom.Element createBoardElement(Document newDocument) {
FillapixBoard board;
if (puzzle.getTree() != null) {
board = (FillapixBoard) puzzle.getTree().getRootNode().getBoard();
}
}
else {
board = (FillapixBoard) puzzle.getBoardView().getBoard();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* Tests if a tree is next to only grass in a 2x2 grid triggers the contradiction
*/
@Test
public void NoTentForTreeContradictionRule_() throws InvalidFileFormatException {
public void NoTentForTreeContradictionRule_Basic() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTree", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
Expand All @@ -43,5 +47,65 @@ public void NoTentForTreeContradictionRule_() throws InvalidFileFormatException
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests similarly to above, but now with a tent diagonally next to the tree, which should still contradict
*/
@Test
public void NoTentForTreeContradictionRule_Diagonal() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeDiagonal", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests that adjacent trees do not allow a pass
*/
@Test
public void NoTentForTreeContradictionRule_TwoTrees() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTrees", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests similarly to above, but now with a tent diagonally next to two trees, which should still contradict on one.
*/
@Test
public void NoTentForTreeContradictionRule_TwoTreesDiagonal() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTentForTreeContradictionRule/NoTentForTreeTwoTreesDiagonal", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@

import edu.rpi.legup.puzzle.treetent.TreeTent;
import edu.rpi.legup.puzzle.treetent.TreeTentBoard;
import edu.rpi.legup.puzzle.treetent.TreeTentCell;
import edu.rpi.legup.puzzle.treetent.TreeTentType;
import edu.rpi.legup.puzzle.treetent.rules.NoTreeForTentContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.awt.*;

public class NoTreeForTentContradictionRuleTest {

private static final NoTreeForTentContradictionRule RULE = new NoTreeForTentContradictionRule();
Expand All @@ -28,9 +24,13 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent", treetent);
public void NoTreeForTentContradictionRule_NW() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNW", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand All @@ -43,5 +43,165 @@ public void NoTreeForTentContradictionRule_() throws InvalidFileFormatException
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NE corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_NE() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentNE", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the NW corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_SW() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSW", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 2x2 Grid, a Tent in the SE corner has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_SE() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentSE", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with no trees, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_3x3() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTent3x3", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with diagonal trees, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_3x3WithDiagonalTrees() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentDiagonals", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with an adjacent tree, test does not assert null.
*/
@Test
public void NoTreeForTentContradictionRule_YesTree() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentYesTree", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNotNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}

/**
* @throws InvalidFileFormatException
* Tests if, in a 3x3 Grid with touching tents, a Tent in the center cell has no adjacent trees
*/
@Test
public void NoTreeForTentContradictionRule_JustTent() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/treetent/rules/NoTreeForTentContradictionRule/NoTreeForTentJustTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();

Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 0)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 1)));
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(2, 2)));
}
}

Loading
Loading