From 3ec5ea8839f32eb6fe7630c0b482a06229755f92 Mon Sep 17 00:00:00 2001 From: Jun Date: Tue, 28 Mar 2023 17:16:41 -0400 Subject: [PATCH] Added another set of tests for TooManyBulbsContradictionRule --- .../BlockEnclosed | 13 +++ .../CompleteBoardBlockEnclosed | 15 ++++ .../CornerBlockEnclosed | 11 +++ .../ManyBlocksEnclosed | 17 ++++ .../TooFewBulbsContradictionRuleTest.java | 1 - .../TooManyBulbsContradictionRuleTest.java | 82 ++++++++++++++++++- 6 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed create mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed create mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed create mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed new file mode 100644 index 000000000..c5760aede --- /dev/null +++ b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed new file mode 100644 index 000000000..88fb0a8f1 --- /dev/null +++ b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed new file mode 100644 index 000000000..a9a8dc5a0 --- /dev/null +++ b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed new file mode 100644 index 000000000..e743862eb --- /dev/null +++ b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java index c131d09e0..14b2a10bd 100644 --- a/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooFewBulbsContradictionRuleTest.java @@ -1,7 +1,6 @@ package puzzles.lightup.rules; import edu.rpi.legup.puzzle.lightup.LightUpBoard; -import edu.rpi.legup.puzzle.lightup.rules.CannotLightACellContradictionRule; import edu.rpi.legup.puzzle.lightup.rules.TooFewBulbsContradictionRule; import legup.MockGameBoardFacade; import legup.TestUtilities; diff --git a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java index ac4c49520..bb7c31d6e 100644 --- a/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/TooManyBulbsContradictionRuleTest.java @@ -1,19 +1,97 @@ package puzzles.lightup.rules; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.rules.TooManyBulbsContradictionRule; +import legup.MockGameBoardFacade; +import legup.TestUtilities; +import edu.rpi.legup.model.PuzzleImporter; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import org.junit.Assert; +import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.save.InvalidFileFormatException; + import org.junit.BeforeClass; import org.junit.Test; -import edu.rpi.legup.puzzle.lightup.LightUp; public class TooManyBulbsContradictionRuleTest { + private static final TooManyBulbsContradictionRule RULE = new TooManyBulbsContradictionRule(); private static LightUp lightUp; + private static PuzzleImporter importer; @BeforeClass public static void setUp() { + MockGameBoardFacade.getInstance(); lightUp = new LightUp(); + importer = lightUp.getImporter(); + } + @Test + public void TooManyBulbsContradictionRule_BlockEnclosed() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + LightUpBoard board = (LightUpBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); } @Test - public void simpleCaseTest() { + public void TooManyBulbsContradictionRule_CornerBlockEnclosed() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/TooManybulbsContradictionRule/CornerBlockEnclosed", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + LightUpBoard board = (LightUpBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + } +// + @Test + public void TooManyBulbsContradictionRule_ManyBlocksEnclosed() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + LightUpBoard board = (LightUpBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2))); + } + + @Test + public void TooManyBulbsContradictionRule_CompleteBoardBlockEnclosed() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + LightUpBoard board = (LightUpBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2))); } }