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
54 changes: 54 additions & 0 deletions src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package puzzles.treetent.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.tree.Tree;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
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.FillinRowCaseRule;
import edu.rpi.legup.puzzle.treetent.rules.TentOrGrassCaseRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.awt.*;
import java.util.ArrayList;

public class TentOrGrassCaseRuleTest {
private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule();
private static TreeTent treetent;

@BeforeClass
public static void setUp(){
MockGameBoardFacade.getInstance();
treetent = new TreeTent();
}

/**
* @throws InvalidFileFormatException
* A temporary test
*/
@Test
public void TentOrGrassCaseRule_Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

TreeTentBoard board = (TreeTentBoard) transition.getBoard();
TreeTentCell testing_cell = board.getCell(1, 0);
ArrayList<Board> cases = RULE.getCases(board, testing_cell);
// assert correct number of cases created
Assert.assertEquals(2, cases.size());
//Store the 0,1 cells from each case
//Assert that the Array of their states match to a an array of the expected.

}

}
Loading
Loading