forked from Bram-Hub/LEGUP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d0026e
commit 9e9d8b2
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |