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

Tree Tent Test Suite- All Remaining Non-Case Type Tests #683

Merged
merged 12 commits into from
Dec 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void FinishWithTentsTest() throws InvalidFileFormatException {
TreeTentCell cell2 = board.getCell(1, 2);
TreeTentCell cell3 = board.getCell(0, 1);
TreeTentCell cell4 = board.getCell(2, 1);

cell1.setData(TreeTentType.TENT);
cell2.setData(TreeTentType.TENT);
cell3.setData(TreeTentType.TENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ public static void setUp() {
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
*
* Checks if a test works for an empty square above a tree which is surrounded on all other sides.
*/
@Test
public void EmptyFieldTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpot", treetent);
public void EmptyFieldTest_Up() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand All @@ -55,6 +60,108 @@ public void EmptyFieldTest() throws InvalidFileFormatException {
}
}
}

/**
* @throws InvalidFileFormatException
*
* Checks if a test works for an empty square below a tree which is surrounded on all other sides.
*/
@Test
public void EmptyFieldTest_Down() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

TreeTentCell cell1 = board.getCell(1, 2);
cell1.setData(TreeTentType.TENT);

board.addModifiedData(cell1);

Assert.assertNull(RULE.checkRule(transition));

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)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
*
* Checks if a test works for an empty square to the left of a tree which is surrounded on all other sides.
*/
@Test
public void EmptyFieldTest_Left() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

TreeTentCell cell1 = board.getCell(0, 1);
cell1.setData(TreeTentType.TENT);

board.addModifiedData(cell1);

Assert.assertNull(RULE.checkRule(transition));

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)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}

/**
* @throws InvalidFileFormatException
*
* Checks if a test works for an empty square to the right of a tree which is surrounded on all other sides.
*/
@Test
public void EmptyFieldTest_Right() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

TreeTentCell cell1 = board.getCell(2, 1);
cell1.setData(TreeTentType.TENT);

board.addModifiedData(cell1);

Assert.assertNull(RULE.checkRule(transition));

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)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}
}


Expand Down
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.TooFewTentsContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.awt.*;

public class TooFewTentsContradictionRuleTest {

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

/**
* @throws InvalidFileFormatException
* Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on the y-axis is caught.
*/
@Test
public void TooFewTentsContradictionRule_JustY() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY", 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)));
}

/**
* @throws InvalidFileFormatException
* Using a 1x1 Puzzle Grid, which is just a tent, checks if the fact it expects 2 tents on the y-axis is caught.
* (This is an impossible situation given the constraints, but for the purposes of the test it is fine)
*/
@Test
public void TooFewTentsContradictionRule_WithTent() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent", 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)));
}

/**
* @throws InvalidFileFormatException
* Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on both x and y is caught.
*/
@Test
public void TooFewTentsContradictionRule_() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents", treetent);
public void TooFewTentsContradictionRule_DoubleBad() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand Down
Loading
Loading