Skip to content

Commit

Permalink
Merge branch 'dev' into stt-test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestian23 authored Oct 18, 2023
2 parents 11821ce + f69fbe3 commit 8893406
Show file tree
Hide file tree
Showing 28 changed files with 976 additions and 15 deletions.
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 @@ -154,7 +154,7 @@ public static ArrayList<FillapixCell> getCellsAtDistance(FillapixBoard board, Fi
*
* @return an ArrayList of Boolean arrays. Each index in the ArrayList represents
* a distinct combination. Each Boolean array will be <code>totalNumItems</code>
* long and each index will be <code>true<\code> if the corresponding item is
* long and each index will be <code>true</code> if the corresponding item is
* included in that combination, and <code>false</code> otherwise.
*/
public static ArrayList<boolean[]> getCombinations(int chosenNumItems, int totalNumItems) {
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

0 comments on commit 8893406

Please sign in to comment.