Skip to content

Commit

Permalink
Check Rule on Columns
Browse files Browse the repository at this point in the history
Adjust all simple cases to also check the central column rule
  • Loading branch information
jadeandtea committed Mar 29, 2024
1 parent 0362f80 commit 49e8fc4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 27 deletions.
99 changes: 99 additions & 0 deletions src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void TentOrTreeTestZeroTentClue() 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);

Expand All @@ -66,6 +68,31 @@ public void TentOrTreeTestZeroTentClue() throws InvalidFileFormatException {
Assert.assertEquals(original_cell.getType(), case_cell.getType());
}
}

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

// assert one case was created
Assert.assertEquals(1, cases.size());

// assert the case filled the row with grass
testCase = (TreeTentBoard) cases.getFirst();
Assert.assertEquals(3, testCase.getRowCol(1, 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 == 1) {
continue;
}

original_cell = board.getCell(w, h);

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

/**
Expand All @@ -91,6 +118,8 @@ public void FillInRowEmptyOneTentClue() 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);

Expand Down Expand Up @@ -128,6 +157,43 @@ public void FillInRowEmptyOneTentClue() throws InvalidFileFormatException {
}
}
}

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

// assert correct number of cases created
Assert.assertEquals(3, 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 1 tent in the row
Assert.assertEquals(1, testCase.getRowCol(1, TreeTentType.TENT, false).size());

// and they must have 2 grass tiles in the row
Assert.assertEquals(2, testCase.getRowCol(1, 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 == 1) {
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 All @@ -150,6 +216,7 @@ public void FillInRowEmptyTwoTentClue() 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);

Expand Down Expand Up @@ -183,6 +250,38 @@ public void FillInRowEmptyTwoTentClue() throws InvalidFileFormatException {
Assert.assertEquals(original_cell.getType(), case_cell.getType());
}
}

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

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

testCase = (TreeTentBoard) cases.getFirst();

// The two side tiles are tents,
Assert.assertEquals(TreeTentType.TENT, testCase.getCell(1, 0).getType());
Assert.assertEquals(TreeTentType.TENT, testCase.getCell(1, 2).getType());

// and the center tile is grass.
Assert.assertEquals(TreeTentType.GRASS, testCase.getCell(1, 1).getType());

// 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 == 1) {
continue;
}

original_cell = board.getCell(w, h);

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,12 +2,6 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="2" x="0" y="0"/>
<cell value="1" x="1" y="0"/>
<cell value="2" x="2" y="0"/>
<cell value="2" x="0" y="2"/>
<cell value="2" x="1" y="2"/>
<cell value="2" x="2" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
Expand All @@ -16,7 +10,7 @@
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="2" value="1"/>
<clue index="3" value="0"/>
</axis>
</board>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="2" x="0" y="0"/>
<cell value="1" x="1" y="0"/>
<cell value="2" x="2" y="0"/>
<cell value="2" x="0" y="2"/>
<cell value="2" x="1" y="2"/>
<cell value="2" x="2" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
Expand All @@ -16,7 +10,7 @@
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="2" value="3"/>
<clue index="3" value="0"/>
</axis>
</board>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="2" x="0" y="0"/>
<cell value="1" x="1" y="0"/>
<cell value="2" x="2" y="0"/>
<cell value="2" x="0" y="2"/>
<cell value="2" x="1" y="2"/>
<cell value="2" x="2" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
Expand All @@ -16,7 +10,7 @@
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="2" value="2"/>
<clue index="3" value="0"/>
</axis>
</board>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
<cell value="2" x="0" y="0"/>
<cell value="1" x="1" y="0"/>
<cell value="2" x="2" y="0"/>
<cell value="2" x="0" y="2"/>
<cell value="2" x="1" y="2"/>
<cell value="2" x="2" y="2"/>
</cells>
<axis side="east">
<clue index="A" value="0"/>
Expand Down

0 comments on commit 49e8fc4

Please sign in to comment.