Skip to content

Commit

Permalink
added FinishWithTentsTest (#676)
Browse files Browse the repository at this point in the history
* added some tests

* added another test

* adhere to style guide

* added comments to tests

---------

Co-authored-by: Ivan Ho <41582274+Corppet@users.noreply.github.com>
  • Loading branch information
Kevin-771 and Corppet authored Nov 9, 2023
1 parent 3401742 commit 0e2d70b
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.junit.Test;

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

public class FinishWithTentsDirectRuleTest {

Expand All @@ -26,9 +27,94 @@ public static void setUp() {
MockGameBoardFacade.getInstance();
treetent = new TreeTent();
}

/**
* 3x3 TreeTent puzzle with a GRASS tile at (0,0)
* Tests FinishWithTentsDirectRule on TENT tiles horizontal of the GRASS tile
* at (1,0) and (2,0)
*
* @throws InvalidFileFormatException
*/
@Test
public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithHorizontalTents", 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, 0);
cell1.setData(TreeTentType.TENT);
TreeTentCell cell2 = board.getCell(2, 0);
cell2.setData(TreeTentType.TENT);

board.addModifiedData(cell1);
board.addModifiedData(cell2);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
TreeTentCell c = board.getCell(k, i);
if ((c.getLocation()).equals(cell1.getLocation()) || (c.getLocation()).equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with a GRASS tile at (0,0)
* Tests FinishWithTentsDirectRule on TENT tiles vertical of the GRASS tile
* at (0,1) and (0,2)
*
* @throws InvalidFileFormatException
*/
@Test
public void FinishWithVerticalTentsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithVerticalTents", 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);
TreeTentCell cell2 = board.getCell(0, 2);
cell2.setData(TreeTentType.TENT);

board.addModifiedData(cell1);
board.addModifiedData(cell2);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
TreeTentCell c = board.getCell(k, i);
if ((c.getLocation()).equals(cell1.getLocation()) || (c.getLocation()).equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with a GRASS tile at (1,1)
* Tests FinishWithTentsDirectRule on TENT tiles around the GRASS tile
* at (1,0), (1,2), (0,1), and (2,1)
*
* @throws InvalidFileFormatException
*/
@Test
public void EmptyFieldTest() throws InvalidFileFormatException {
public void FinishWithTentsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTents", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
Expand All @@ -37,27 +123,238 @@ public void EmptyFieldTest() throws InvalidFileFormatException {
TreeTentBoard board = (TreeTentBoard) transition.getBoard();

TreeTentCell cell1 = board.getCell(1, 0);
TreeTentCell cell2 = board.getCell(1, 2);
TreeTentCell cell3 = board.getCell(0, 1);
TreeTentCell cell4 = board.getCell(2, 1);

cell1.setData(TreeTentType.TENT);
TreeTentCell cell2 = board.getCell(2, 0);
cell2.setData(TreeTentType.TENT);
cell3.setData(TreeTentType.TENT);
cell4.setData(TreeTentType.TENT);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

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()) || point.equals(cell2.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
TreeTentCell c = board.getCell(k, i);
if ((c.getLocation()).equals(cell1.getLocation()) ||
(c.getLocation()).equals(cell2.getLocation()) ||
(c.getLocation()).equals(cell3.getLocation()) ||
(c.getLocation()).equals(cell4.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* 3x3 TreeTent puzzle with a TENT tile at (1,1)
* Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile
* at (1,0), (1,2), (0,1), and (2,1)
*
* @throws InvalidFileFormatException
*/
@Test
public void AdditionalTentsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/AdditionalTents", 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, 0);
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);
cell4.setData(TreeTentType.TENT);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
TreeTentCell c = board.getCell(k, i);
if ((c.getLocation()).equals(cell1.getLocation()) ||
(c.getLocation()).equals(cell2.getLocation()) ||
(c.getLocation()).equals(cell3.getLocation()) ||
(c.getLocation()).equals(cell4.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, c));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
}
}
}
}

/**
* Empty 3x3 TreeTent puzzle
* Tests FinishWithTentsDirectRule on TENT tiles of entire puzzle
* all TENT tiles should fail FinishWithTentsDirectRule
* as no TENT tiles should be there
*
* @throws InvalidFileFormatException
*/
@Test
public void FinishWithTentsFailTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsFail", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

ArrayList<TreeTentCell> cells = new ArrayList<TreeTentCell>();

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
TreeTentCell c = board.getCell(k, i);
c.setData(TreeTentType.TENT);
board.addModifiedData(c);
cells.add(c);
}
}

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}

/**
* 3x3 TreeTent puzzle with a TENT tile at (1,1)
* Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile
* at (1,0), (1,2), (0,1), and (2,1)
* all TENT tiles should fail FinishWithTentsDirectRule
* as there were already sufficient number of TENT tiles
*
* @throws InvalidFileFormatException
*/
@Test
public void TooManyTentsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/TooManyTents", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

ArrayList<TreeTentCell> cells = new ArrayList<TreeTentCell>();

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
if((k == 1)&&(i == 1)) {
continue;
}
TreeTentCell c = board.getCell(k, i);
c.setData(TreeTentType.TENT);
board.addModifiedData(c);
cells.add(c);
}
}

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}

/**
* 3x3 TreeTent puzzle with a TENT tile at (1,1)
* Tests FinishWithTentsDirectRule on TENT tiles around the TENT tile
* at (1,0), (1,2), (0,1), and (2,1)
* all TENT tiles should fail FinishWithTentsDirectRule
* as there are multiple configurations of the placement
* of the TENT tiles
*
* @throws InvalidFileFormatException
*/
@Test
public void AmbiguousTentsTest () throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/FinishWithTentsDirectRule/AmbiguousTents", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

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

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}

cell.setData(TreeTentType.UNKNOWN);
board.addModifiedData(cell);
cell = board.getCell(1, 0);
cell.setData(TreeTentType.TENT);
board.addModifiedData(cell);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}

cell.setData(TreeTentType.UNKNOWN);
board.addModifiedData(cell);
cell = board.getCell(2, 1);
cell.setData(TreeTentType.TENT);
board.addModifiedData(cell);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}

cell.setData(TreeTentType.UNKNOWN);
board.addModifiedData(cell);
cell = board.getCell(1, 2);
cell.setData(TreeTentType.TENT);
board.addModifiedData(cell);

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

for (int i = 0; i < board.getHeight(); i++) {
for (int k = 0; k < board.getWidth(); k++) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
}
}
}


Expand Down
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="3" x="1" y="1"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="3"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="3"/>
<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="3" x="1" y="1"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="2"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="2"/>
<clue index="3" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Loading

0 comments on commit 0e2d70b

Please sign in to comment.