From 999fa1780ad12f8ecbe0912d3da285b7b7c902ee Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 5 Apr 2024 16:42:27 -0400 Subject: [PATCH 1/4] Made small test board --- .../rules/BlackoutDirectRuleTest.java | 19 ++++++++++ .../BlackoutDirectRule/ColumnBlackout | 36 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java create mode 100644 src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/ColumnBlackout diff --git a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java new file mode 100644 index 000000000..b87b88de5 --- /dev/null +++ b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java @@ -0,0 +1,19 @@ +package puzzles.starbattle.rules; + +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +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.BlackoutDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; + +public class BlackoutDirectRuleTest { +} diff --git a/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/ColumnBlackout b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/ColumnBlackout new file mode 100644 index 000000000..f2a5b42d9 --- /dev/null +++ b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/ColumnBlackout @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 15e19d39a03c41b0807233927bac1b7eb63d454b Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 5 Apr 2024 16:52:31 -0400 Subject: [PATCH 2/4] Add image paths to rule constructors --- .../rpi/legup/puzzle/starbattle/rules/BlackoutDirectRule.java | 2 +- .../puzzle/starbattle/rules/ClashingOrbitContradictionRule.java | 2 +- .../puzzle/starbattle/rules/FinishWithStarsDirectRule.java | 2 +- .../legup/puzzle/starbattle/rules/SurroundStarDirectRule.java | 2 +- .../puzzle/starbattle/rules/TooFewStarsContradictionRule.java | 2 +- .../puzzle/starbattle/rules/TooManyStarsContradictionRule.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/BlackoutDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/BlackoutDirectRule.java index ceea86164..45c550bde 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/BlackoutDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/BlackoutDirectRule.java @@ -16,7 +16,7 @@ public BlackoutDirectRule() { super("STBL-BASC-0001", "Blackout", "If a row, column, or region has enough stars, its unknown spaces are black.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/rules/BlackOutDirectRule.png"); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ClashingOrbitContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ClashingOrbitContradictionRule.java index 28398143e..0ca27ab4a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ClashingOrbitContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/ClashingOrbitContradictionRule.java @@ -17,7 +17,7 @@ public ClashingOrbitContradictionRule() { super("STBL-CONT-0003", "Clashing Orbit", "No two stars can be adjacent to each other.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/contradictions/ClashingOrbitContradictionRule.png"); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/FinishWithStarsDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/FinishWithStarsDirectRule.java index ed6a8a986..f6b7eef86 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/FinishWithStarsDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/FinishWithStarsDirectRule.java @@ -16,7 +16,7 @@ public FinishWithStarsDirectRule() { super("STBL-BASC-0004", "Finish With Stars", "Unknown spaces must be stars if there are just enough in a row, column, or region to satisfy the puzzle number.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/rules/FinishWithStarDirectRule.png"); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/SurroundStarDirectRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/SurroundStarDirectRule.java index 0608d388f..5d42e895e 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/SurroundStarDirectRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/SurroundStarDirectRule.java @@ -16,7 +16,7 @@ public SurroundStarDirectRule() { super("STBL-BASC-0009", "Surround Star", "Any space adjacent to a star must be black.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/rules/SurroundStar.png"); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java index af30a5e18..d1ed62107 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooFewStarsContradictionRule.java @@ -18,7 +18,7 @@ public TooFewStarsContradictionRule() { super("STBL-CONT-0002", "Too Few Stars", "There are too few stars in this region/row/column and there are not enough places to put the remaining stars.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/contradictions/TooFewStarsContradictionRule.png"); } /** diff --git a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooManyStarsContradictionRule.java b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooManyStarsContradictionRule.java index 7777ff5a4..880e3b8ac 100644 --- a/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooManyStarsContradictionRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/starbattle/rules/TooManyStarsContradictionRule.java @@ -21,7 +21,7 @@ public TooManyStarsContradictionRule() { super("STBL-CONT-0001", "Too Many Stars", "There are too many stars in this region/row/column.", - "INSERT IMAGE NAME HERE"); + "edu/rpi/legup/images/starbattle/contradictions/TooManyStarsContradictionRule.png"); } /** From 729d6b7fe2908851f8cd9915be63883b9de88fcd Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 5 Apr 2024 17:18:02 -0400 Subject: [PATCH 3/4] Write first test for blackout direct rule --- .../rules/BlackoutDirectRuleTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java index b87b88de5..d42f40c87 100644 --- a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java @@ -1,5 +1,9 @@ package puzzles.starbattle.rules; +import edu.rpi.legup.puzzle.nurikabe.Nurikabe; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; import legup.MockGameBoardFacade; import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; @@ -15,5 +19,51 @@ import edu.rpi.legup.puzzle.starbattle.rules.BlackoutDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.awt.*; + public class BlackoutDirectRuleTest { + + private static final BlackoutDirectRule RULE = new BlackoutDirectRule(); + private static StarBattle starbattle; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + starbattle = new StarBattle(); + } + + @Test + public void BlackoutDirectRuleTest_ColumnBlackout() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/ColumnBlackout", starbattle); + TreeNode rootNode = starbattle.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + StarBattleBoard board = (StarBattleBoard) transition.getBoard(); + + StarBattleCell cell1 = board.getCell(1, 1); + cell1.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell2 = board.getCell(1, 2); + cell2.setData(StarBattleCellType.BLACK.value); + StarBattleCell cell3 = board.getCell(1, 3); + cell3.setData(StarBattleCellType.BLACK.value); + + board.addModifiedData(cell1); + board.addModifiedData(cell2); + board.addModifiedData(cell3); + + Assert.assertNull(RULE.checkRule(transition)); + + for (int i = 0; i < board.getHeight(); i++) { + for (int k = 0; k < board.getWidth(); k++) { + Point point = new Point(k, i); + if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } } From ee074b1b63917e8cfea295d72ddb6a87731a2713 Mon Sep 17 00:00:00 2001 From: summerhenson Date: Fri, 5 Apr 2024 17:24:06 -0400 Subject: [PATCH 4/4] Test puzzle files --- .../BlackoutDirectRule/RegionBlackout | 36 +++++++++++++++++++ .../BlackoutDirectRule/RowBlackout | 36 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RegionBlackout create mode 100644 src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RowBlackout diff --git a/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RegionBlackout b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RegionBlackout new file mode 100644 index 000000000..f2a5b42d9 --- /dev/null +++ b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RegionBlackout @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RowBlackout b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RowBlackout new file mode 100644 index 000000000..f2a5b42d9 --- /dev/null +++ b/src/test/resources/puzzles/starbattle.rules/BlackoutDirectRule/RowBlackout @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file