From 9e9d8b27b5cb2b2e5903420416a9f297cf5a668e Mon Sep 17 00:00:00 2001 From: summerhenson Date: Tue, 6 Aug 2024 14:58:38 -0400 Subject: [PATCH] Star or Empty case rule test --- .../rules/StarOrEmptyCaseRuleTest.java | 68 +++++++++++++++++++ .../StarOrEmptyCaseRule/SimpleStarOrEmpty | 29 ++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java create mode 100644 src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty diff --git a/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java new file mode 100644 index 000000000..e1f9cb990 --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/StarOrEmptyCaseRuleTest.java @@ -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 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))); + } + } + } + +} diff --git a/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty b/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty new file mode 100644 index 000000000..4d065b28f --- /dev/null +++ b/src/test/resources/puzzles/starbattle/rules/StarOrEmptyCaseRule/SimpleStarOrEmpty @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file