Skip to content

Commit

Permalink
added TentOrGrassCaseRuleTests (#688)
Browse files Browse the repository at this point in the history
* added a test

* added more to test

* test

* should work now

* should work now

---------

Co-authored-by: Charles Tian <[email protected]>
  • Loading branch information
Kevin-771 and charlestian23 authored Dec 15, 2023
1 parent e6f3279 commit 14b0750
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public static void main(String[] args) {
Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class);
printTestResults(result12);



//nurikabe tests
Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class);
printTestResults(result13);
Expand Down Expand Up @@ -76,7 +74,6 @@ public static void main(String[] args) {
Result result27 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class);
printTestResults(result27);


// Treetent
Result result28 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class);
printTestResults(result28);
Expand All @@ -94,6 +91,8 @@ public static void main(String[] args) {
printTestResults(result34);
Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class);
printTestResults(result35);
Result result36 = JUnitCore.runClasses(TentOrGrassCaseRuleTest.class);
printTestResults(result36);
}

private static void printTestResults(Result result) {
Expand Down
51 changes: 40 additions & 11 deletions src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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;
Expand All @@ -23,32 +21,63 @@
public class TentOrGrassCaseRuleTest {
private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule();
private static TreeTent treetent;

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

/**
* empty 3x3 TreeTent puzzle
* Tests TentOrGrassCaseRule on UNKOWN tile
* at (0,0)
*
* checks 2 cases are created
* checks first case is TENT tile
* checks second case is GRASS tile
* checks other cells have not been modified
*
* @throws InvalidFileFormatException
* A temporary test
*/
@Test
public void TentOrGrassCaseRule_Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest", treetent);
public void TentOrTreeTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle", 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);
TreeTentCell testing_cell = board.getCell(0, 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.

}
// TENT case
TreeTentBoard tentCase = (TreeTentBoard) cases.get(0);
Assert.assertEquals(tentCase.getCell(0, 0).getType(), TreeTentType.TENT);

// GRASS case
TreeTentBoard grassCase = (TreeTentBoard) cases.get(1);
Assert.assertEquals(grassCase.getCell(0, 0).getType(), TreeTentType.GRASS);

// checks other cells have not been modified
TreeTentCell original_cell;
TreeTentCell case_cell;

for (int w =0; w < board.getWidth(); w++) {
for (int h = 0; h < board.getHeight(); h++) {
if (w == 0 && h ==0) {
continue;
}
original_cell = board.getCell(w, h);
case_cell = tentCase.getCell(w, h);
Assert.assertEquals(original_cell.getType(), case_cell.getType());

case_cell = grassCase.getCell(w, h);
Assert.assertEquals(original_cell.getType(), case_cell.getType());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Legup>
<puzzle name="TreeTent">
<board height="3" width="3">
<cells>
</cells>
<axis side="east">
<clue index="A" value="0"/>
<clue index="B" value="0"/>
<clue index="C" value="0"/>
</axis>
<axis side="south">
<clue index="1" value="0"/>
<clue index="2" value="0"/>
<clue index="3" value="0"/>
</axis>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit 14b0750

Please sign in to comment.