Skip to content

Commit

Permalink
Star or Empty case rule test
Browse files Browse the repository at this point in the history
  • Loading branch information
summerhenson committed Aug 6, 2024
1 parent 2d0026e commit 9e9d8b2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package puzzles.starbattle.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.starbattle.StarBattle;
import edu.rpi.legup.puzzle.starbattle.StarBattleBoard;
import edu.rpi.legup.puzzle.starbattle.StarBattleCell;
import edu.rpi.legup.puzzle.starbattle.StarBattleCellType;
import edu.rpi.legup.puzzle.starbattle.rules.StarOrEmptyCaseRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import java.awt.*;
import java.util.ArrayList;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class StarOrEmptyCaseRuleTest {

private static final StarOrEmptyCaseRule RULE = new StarOrEmptyCaseRule();
private static StarBattle starBattle;

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

@Test
public void StarOrEmptyCaseRuleTest_SimpleStarOrEmpty()
throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty", starBattle);
TreeNode rootNode = starBattle.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

StarBattleBoard board = (StarBattleBoard) transition.getBoard();
StarBattleCell cell = board.getCell(0,0);
ArrayList<Board> cases = RULE.getCases(board, cell);

StarBattleBoard caseBoard1 = (StarBattleBoard) cases.get(0);
StarBattleBoard caseBoard2 = (StarBattleBoard) cases.get(1);
StarBattleCellType board1Type = caseBoard1.getCell(0, 0).getType();
StarBattleCellType board2Type = caseBoard2.getCell(0, 0).getType();

Assert.assertTrue(
(board1Type.equals(StarBattleCellType.BLACK) || board1Type.equals(StarBattleCellType.STAR))
&& (board2Type.equals(StarBattleCellType.BLACK)
|| board2Type.equals(StarBattleCellType.STAR)));
Assert.assertFalse(board1Type.equals(board2Type));
Assert.assertEquals(caseBoard1.getHeight(), caseBoard2.getHeight(), board.getHeight());
Assert.assertEquals(caseBoard1.getWidth(), caseBoard2.getWidth(), board.getWidth());

for (int i = 0; i < caseBoard1.getHeight(); i++) {
for (int k = 0; k < caseBoard1.getWidth(); k++) {
Point point = new Point(k, i);
if (point.equals(caseBoard1.getCell(k, i).getLocation())) {
continue;
}
Assert.assertTrue(caseBoard1.getCell(k, i).equals(caseBoard2.getCell(k, i)));
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Legup version="2.0.0">
<puzzle name="StarBattle">
<board size="3" puzzle_num="1">
<region>
<cells>
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="0" x="0" y="2"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="0"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="2" y="2"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="1" y="1"/>
</cells>
</region>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit 9e9d8b2

Please sign in to comment.