Skip to content

Commit

Permalink
FillInRowCaseRule Test
Browse files Browse the repository at this point in the history
Checks that the rule works on an empty 5x5 board
  • Loading branch information
jadeandtea committed Mar 29, 2024
1 parent 9a23697 commit 5582367
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 4 deletions.
105 changes: 101 additions & 4 deletions src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class FillinRowCaseRuleTest {
Expand Down Expand Up @@ -76,7 +77,7 @@ public void TentOrTreeTestZeroTentClue() throws InvalidFileFormatException {
// assert one case was created
Assert.assertEquals(1, cases.size());

// assert the case filled the row with grass
// assert the case filled the column with grass
testCase = (TreeTentBoard) cases.getFirst();
Assert.assertEquals(3, testCase.getRowCol(1, TreeTentType.GRASS, false).size());

Expand Down Expand Up @@ -170,10 +171,10 @@ public void FillInRowEmptyOneTentClue() throws InvalidFileFormatException {
for (Board testCaseBoard : cases) {
TreeTentBoard testCase = (TreeTentBoard) testCaseBoard;

// Each case must have 1 tent in the row
// Each case must have 1 tent in the column
Assert.assertEquals(1, testCase.getRowCol(1, TreeTentType.TENT, false).size());

// and they must have 2 grass tiles in the row
// and they must have 2 grass tiles in the column
Assert.assertEquals(2, testCase.getRowCol(1, TreeTentType.GRASS, false).size());
}

Expand Down Expand Up @@ -301,11 +302,107 @@ public void FillInRowEmptyThreeTentClue() throws InvalidFileFormatException {
transition.setRule(RULE);

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

/* Test the Row */
TreeTentClue testing_row = board.getClue(3, 1);
ArrayList<Board> cases = RULE.getCases(board, testing_row);

// assert there were no cases found, as filling in all tiles causes the tents to touch
Assert.assertEquals(null, cases);
Assert.assertNull(cases);

/* Test the Column */
TreeTentClue testing_col = board.getClue(1, 3);
cases = RULE.getCases(board, testing_row);

Assert.assertNull(cases);
}

@Test
public void FillInRowEmpty5x5TwoTentClue() throws InvalidFileFormatException {
TestUtilities.importTestBoard(
"puzzles/treetent/rules/FillInRowCaseRule/EmptyRow5x5TwoTent", treetent);
TreeNode rootNode = treetent.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

/* Test the Row */
TreeTentClue testing_row = board.getClue(5, 2);
ArrayList<Board> cases = RULE.getCases(board, testing_row);

// assert correct number of cases created
Assert.assertEquals(6, cases.size());
// Only one arrangement is possible when taking into account the
// touching tents contradiction rule.

for (Board testCaseBoard : cases) {
TreeTentBoard testCase = (TreeTentBoard) testCaseBoard;

// Each case must have 2 tens in the row
Assert.assertEquals(2, testCase.getRowCol(2, TreeTentType.TENT, true).size());

// and they must have 3 grass tiles in the row
Assert.assertEquals(3, testCase.getRowCol(2, TreeTentType.GRASS, true).size());
}

TreeTentCell original_cell;
TreeTentCell case_cell;

// checks other cells have not been modified
for (int w = 0; w < board.getWidth(); w++) {
for (int h = 0; h < board.getHeight(); h++) {
if (h == 2) {
continue;
}

original_cell = board.getCell(w, h);

for (Board testCaseBoard : cases) {
TreeTentBoard testCase = (TreeTentBoard) testCaseBoard;

case_cell = testCase.getCell(w, h);
Assert.assertEquals(original_cell.getType(), case_cell.getType());
}
}
}

/* Test the Column */
TreeTentClue testing_col = board.getClue(2, 5);
cases = RULE.getCases(board, testing_col);

// assert correct number of cases created
Assert.assertEquals(6, cases.size());
// Only one arrangement is possible when taking into account the
// touching tents contradiction rule.

for (Board testCaseBoard : cases) {
TreeTentBoard testCase = (TreeTentBoard) testCaseBoard;

// Each case must have 2 tents in the column
Assert.assertEquals(2, testCase.getRowCol(2, TreeTentType.TENT, false).size());

// and they must have 4 grass tiles in the column
Assert.assertEquals(3, testCase.getRowCol(2, TreeTentType.GRASS, false).size());
}

// checks other cells have not been modified
for (int w = 0; w < board.getWidth(); w++) {
for (int h = 0; h < board.getHeight(); h++) {
if (w == 2) {
continue;
}

original_cell = board.getCell(w, h);

for (Board testCaseBoard : cases) {
TreeTentBoard testCase = (TreeTentBoard) testCaseBoard;

case_cell = testCase.getCell(w, h);
Assert.assertEquals(original_cell.getType(), case_cell.getType());
}
}
}
}

// /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="3"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="2"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="3.0.0">
<saved/>
<puzzle name="TreeTent">
<board height="5" width="5">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
<clue index="C" value="2"/>
<clue index="D" value="0"/>
<clue index="E" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="3" value="2"/>
<clue index="4" value="0"/>
<clue index="5" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="2024-03-29 16:49:04"/>
</Legup>

0 comments on commit 5582367

Please sign in to comment.