From e7a65460431d5421544871389d82201f699b9e43 Mon Sep 17 00:00:00 2001 From: willyoung366 Date: Wed, 27 Nov 2024 18:39:00 -0500 Subject: [PATCH] Contradiction Rules Test Test suites for both of the contradiction rules --- ...ty.java => FinishWithEmptyDirectRule.java} | 4 +- ...es.java => FinishWithMinesDirectRule.java} | 4 +- ... => NonTouchingSharedEmptyDirectRule.java} | 4 +- ...a => NonTouchingSharedMineDirectRule.java} | 4 +- src/test/java/legup/TestRunner.java | 2 +- ...ishWithEmptyDirectRuleDirectRuleTest.java} | 2 +- .../FinishWithEmptyDirectRuleTest.java | 18 ++--- .../FinishWithMinesDirectRuleTest.java | 18 ++--- .../NonTouchingSharedEmptyDirectRuleTest.java | 4 +- .../NonTouchingSharedMineDirectRuleTest.java | 4 +- .../TooFewMinesContradictionRuleTest.java | 70 +++++++++++++++++++ .../TooManyMinesContradictionRuleTest.java | 46 ++++++++++++ .../minesweeper/rules/TooFewMines1.txt | 19 +++++ .../minesweeper/rules/TooFewMines2.txt | 19 +++++ .../minesweeper/rules/TooManyMines.txt | 19 +++++ 15 files changed, 205 insertions(+), 32 deletions(-) rename src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/{FinishWithEmpty.java => FinishWithEmptyDirectRule.java} (96%) rename src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/{FinishWithMines.java => FinishWithMinesDirectRule.java} (96%) rename src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/{NonTouchingSharedEmpty.java => NonTouchingSharedEmptyDirectRule.java} (95%) rename src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/{NonTouchingSharedMine.java => NonTouchingSharedMineDirectRule.java} (96%) rename src/test/java/puzzles/lightup/rules/{FinishWithEmptyDirectRuleTest.java => FinishWithEmptyDirectRuleDirectRuleTest.java} (98%) create mode 100644 src/test/java/puzzles/minesweeper/TooFewMinesContradictionRuleTest.java create mode 100644 src/test/java/puzzles/minesweeper/TooManyMinesContradictionRuleTest.java create mode 100644 src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt create mode 100644 src/test/resources/puzzles/minesweeper/rules/TooFewMines2.txt create mode 100644 src/test/resources/puzzles/minesweeper/rules/TooManyMines.txt diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmpty.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmptyDirectRule.java similarity index 96% rename from src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmpty.java rename to src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmptyDirectRule.java index 97009a627..2dd80a01b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmpty.java +++ b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithEmptyDirectRule.java @@ -7,8 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.minesweeper.*; -public class FinishWithEmpty extends DirectRule { - public FinishWithEmpty() { +public class FinishWithEmptyDirectRule extends DirectRule { + public FinishWithEmptyDirectRule() { super( "MINE-BASC-0002", "Finish With Empty", diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMines.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMinesDirectRule.java similarity index 96% rename from src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMines.java rename to src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMinesDirectRule.java index e7077c9b7..4b4c6435a 100644 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMines.java +++ b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/FinishWithMinesDirectRule.java @@ -7,8 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.minesweeper.*; -public class FinishWithMines extends DirectRule { - public FinishWithMines() { +public class FinishWithMinesDirectRule extends DirectRule { + public FinishWithMinesDirectRule() { super( "MINE-BASC-0001", "Finish With Mines", diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmpty.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmptyDirectRule.java similarity index 95% rename from src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmpty.java rename to src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmptyDirectRule.java index 544caf17a..0c86c59b8 100644 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmpty.java +++ b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedEmptyDirectRule.java @@ -7,8 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.minesweeper.*; -public class NonTouchingSharedEmpty extends DirectRule { - public NonTouchingSharedEmpty() { +public class NonTouchingSharedEmptyDirectRule extends DirectRule { + public NonTouchingSharedEmptyDirectRule() { super( "MINE-BASC-0003", "Non Shared Empty", diff --git a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMine.java b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMineDirectRule.java similarity index 96% rename from src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMine.java rename to src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMineDirectRule.java index 03feb4275..e6724753b 100644 --- a/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMine.java +++ b/src/main/java/edu/rpi/legup/puzzle/minesweeper/rules/NonTouchingSharedMineDirectRule.java @@ -7,8 +7,8 @@ import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.minesweeper.*; -public class NonTouchingSharedMine extends DirectRule { - public NonTouchingSharedMine() { +public class NonTouchingSharedMineDirectRule extends DirectRule { + public NonTouchingSharedMineDirectRule() { super( "MINE-BASC-0003", "Non Shared Mine", diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 5486a0353..e5619681e 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -30,7 +30,7 @@ public static void main(String[] args) { printTestResults(result6); Result result7 = JUnitCore.runClasses(FinishWithBulbsDirectRuleTest.class); printTestResults(result7); - Result result8 = JUnitCore.runClasses(FinishWithEmptyDirectRuleTest.class); + Result result8 = JUnitCore.runClasses(FinishWithEmptyDirectRuleDirectRuleTest.class); printTestResults(result8); Result result9 = JUnitCore.runClasses(LightOrEmptyCaseRuleTest.class); printTestResults(result9); diff --git a/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleDirectRuleTest.java similarity index 98% rename from src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java rename to src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleDirectRuleTest.java index 079641ee7..f80db6625 100644 --- a/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java +++ b/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleDirectRuleTest.java @@ -13,7 +13,7 @@ import org.junit.BeforeClass; import org.junit.Test; -public class FinishWithEmptyDirectRuleTest { +public class FinishWithEmptyDirectRuleDirectRuleTest { private static final FinishWithEmptyDirectRule RULE = new FinishWithEmptyDirectRule(); private static LightUp lightUp; diff --git a/src/test/java/puzzles/minesweeper/FinishWithEmptyDirectRuleTest.java b/src/test/java/puzzles/minesweeper/FinishWithEmptyDirectRuleTest.java index e627577e5..0469bfc71 100644 --- a/src/test/java/puzzles/minesweeper/FinishWithEmptyDirectRuleTest.java +++ b/src/test/java/puzzles/minesweeper/FinishWithEmptyDirectRuleTest.java @@ -6,7 +6,7 @@ import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; import edu.rpi.legup.puzzle.minesweeper.MinesweeperCell; import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; -import edu.rpi.legup.puzzle.minesweeper.rules.FinishWithEmpty; +import edu.rpi.legup.puzzle.minesweeper.rules.FinishWithEmptyDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; import legup.TestUtilities; @@ -18,7 +18,7 @@ public class FinishWithEmptyDirectRuleTest { - public static final FinishWithEmpty RULE = new FinishWithEmpty(); + public static final FinishWithEmptyDirectRule RULE = new FinishWithEmptyDirectRule(); private static Minesweeper minesweeper; @BeforeClass @@ -28,7 +28,7 @@ public static void setUp() { } @Test - public void MustNotContainBombDirectRule_OneUnsetOneEmptyOneClueTest1() + public void FinishWithEmptyDirectRule_OneUnsetOneEmptyOneClueTest1() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test8.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -58,7 +58,7 @@ public void MustNotContainBombDirectRule_OneUnsetOneEmptyOneClueTest1() } @Test - public void MustNotContainBombDirectRule_FiveUnsetOneEmptyOneClueTest2() + public void FinishWithEmptyDirectRule_FiveUnsetOneEmptyOneClueTest2() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test9.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -88,7 +88,7 @@ public void MustNotContainBombDirectRule_FiveUnsetOneEmptyOneClueTest2() } @Test - public void MustNotContainBombDirectRule_NineUnsetOneEmptyZeroCluesTest3() + public void FinishWithEmptyDirectRule_NineUnsetOneEmptyZeroCluesTest3() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -118,7 +118,7 @@ public void MustNotContainBombDirectRule_NineUnsetOneEmptyZeroCluesTest3() } @Test - public void MustNotContainBombDirectRule_NineUnsetNineEmptyZeroCluesTest4() + public void FinishWithEmptyDirectRule_NineUnsetNineEmptyZeroCluesTest4() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -176,7 +176,7 @@ public void MustNotContainBombDirectRule_NineUnsetNineEmptyZeroCluesTest4() } @Test - public void MustNotContainBombDirectRule_OneUnsetOneEmptyThreeCluesTest5() + public void FinishWithEmptyDirectRule_OneUnsetOneEmptyThreeCluesTest5() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test10.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -206,7 +206,7 @@ public void MustNotContainBombDirectRule_OneUnsetOneEmptyThreeCluesTest5() } @Test - public void MustNotContainBombDirectRule_OneUnsetOneEmptyThreeCluesTest6() + public void FinishWithEmptyDirectRule_OneUnsetOneEmptyThreeCluesTest6() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test11.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -236,7 +236,7 @@ public void MustNotContainBombDirectRule_OneUnsetOneEmptyThreeCluesTest6() } @Test - public void MustNotContainBombDirectRule_FiveUnsetTwoEmptyTwoCluesTest7() + public void FinishWithEmptyDirectRule_FiveUnsetTwoEmptyTwoCluesTest7() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test12.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); diff --git a/src/test/java/puzzles/minesweeper/FinishWithMinesDirectRuleTest.java b/src/test/java/puzzles/minesweeper/FinishWithMinesDirectRuleTest.java index cf1d36781..cce25dcc2 100644 --- a/src/test/java/puzzles/minesweeper/FinishWithMinesDirectRuleTest.java +++ b/src/test/java/puzzles/minesweeper/FinishWithMinesDirectRuleTest.java @@ -3,7 +3,7 @@ import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.minesweeper.*; -import edu.rpi.legup.puzzle.minesweeper.rules.FinishWithMines; +import edu.rpi.legup.puzzle.minesweeper.rules.FinishWithMinesDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; import legup.TestUtilities; @@ -15,7 +15,7 @@ public class FinishWithMinesDirectRuleTest { - public static final FinishWithMines RULE = new FinishWithMines(); + public static final FinishWithMinesDirectRule RULE = new FinishWithMinesDirectRule(); private static Minesweeper minesweeper; @BeforeClass @@ -25,7 +25,7 @@ public static void setUp() { } @Test - public void MustContainBombDirectRule_OneUnsetOneBombOneClueTest1() + public void FinishWithMinesDirectRule_OneUnsetOneBombOneClueTest1() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test2.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -55,7 +55,7 @@ public void MustContainBombDirectRule_OneUnsetOneBombOneClueTest1() } @Test - public void MustContainBombDirectRule_FourUnsetOneBombOneClueTest2() + public void FinishWithMinesDirectRule_FourUnsetOneBombOneClueTest2() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test3.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -86,7 +86,7 @@ public void MustContainBombDirectRule_FourUnsetOneBombOneClueTest2() @Test - public void MustContainBombDirectRule_FourUnsetFourBombsOneClueTest3() + public void FinishWithMinesDirectRule_FourUnsetFourBombsOneClueTest3() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test3.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -126,7 +126,7 @@ public void MustContainBombDirectRule_FourUnsetFourBombsOneClueTest3() } @Test - public void MustContainBombDirectRule_EightUnsetEightBombsOneClueTest4() + public void FinishWithMinesDirectRule_EightUnsetEightBombsOneClueTest4() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test4.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -180,7 +180,7 @@ public void MustContainBombDirectRule_EightUnsetEightBombsOneClueTest4() } @Test - public void MustContainBombDirectRule_OneUnsetOneBombFourCluesTest5() + public void FinishWithMinesDirectRule_OneUnsetOneBombFourCluesTest5() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test5.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -210,7 +210,7 @@ public void MustContainBombDirectRule_OneUnsetOneBombFourCluesTest5() } @Test - public void MustContainBombDirectRule_TwoUnsetTwoBombsTwoCluesTest6() + public void FinishWithMinesDirectRule_TwoUnsetTwoBombsTwoCluesTest6() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test6.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); @@ -243,7 +243,7 @@ public void MustContainBombDirectRule_TwoUnsetTwoBombsTwoCluesTest6() } @Test - public void MustContainBombDirectRule_ThreeUnsetOneBombTwoCluesTest7() + public void FinishWithMinesDirectRule_ThreeUnsetOneBombTwoCluesTest7() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/minesweeper/rules/3x3test7.txt", minesweeper); TreeNode rootNode = minesweeper.getTree().getRootNode(); diff --git a/src/test/java/puzzles/minesweeper/NonTouchingSharedEmptyDirectRuleTest.java b/src/test/java/puzzles/minesweeper/NonTouchingSharedEmptyDirectRuleTest.java index 7c95333a5..e7bdb11c6 100644 --- a/src/test/java/puzzles/minesweeper/NonTouchingSharedEmptyDirectRuleTest.java +++ b/src/test/java/puzzles/minesweeper/NonTouchingSharedEmptyDirectRuleTest.java @@ -6,7 +6,7 @@ import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; import edu.rpi.legup.puzzle.minesweeper.MinesweeperCell; import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; -import edu.rpi.legup.puzzle.minesweeper.rules.NonTouchingSharedEmpty; +import edu.rpi.legup.puzzle.minesweeper.rules.NonTouchingSharedEmptyDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; import legup.TestUtilities; @@ -18,7 +18,7 @@ public class NonTouchingSharedEmptyDirectRuleTest { - public static final NonTouchingSharedEmpty RULE = new NonTouchingSharedEmpty(); + public static final NonTouchingSharedEmptyDirectRule RULE = new NonTouchingSharedEmptyDirectRule(); private static Minesweeper minesweeper; @BeforeClass diff --git a/src/test/java/puzzles/minesweeper/NonTouchingSharedMineDirectRuleTest.java b/src/test/java/puzzles/minesweeper/NonTouchingSharedMineDirectRuleTest.java index 3251bc949..f44436192 100644 --- a/src/test/java/puzzles/minesweeper/NonTouchingSharedMineDirectRuleTest.java +++ b/src/test/java/puzzles/minesweeper/NonTouchingSharedMineDirectRuleTest.java @@ -6,7 +6,7 @@ import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; import edu.rpi.legup.puzzle.minesweeper.MinesweeperCell; import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; -import edu.rpi.legup.puzzle.minesweeper.rules.NonTouchingSharedMine; +import edu.rpi.legup.puzzle.minesweeper.rules.NonTouchingSharedMineDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; import legup.TestUtilities; @@ -18,7 +18,7 @@ public class NonTouchingSharedMineDirectRuleTest { - public static final NonTouchingSharedMine RULE = new NonTouchingSharedMine(); + public static final NonTouchingSharedMineDirectRule RULE = new NonTouchingSharedMineDirectRule(); private static Minesweeper minesweeper; @BeforeClass diff --git a/src/test/java/puzzles/minesweeper/TooFewMinesContradictionRuleTest.java b/src/test/java/puzzles/minesweeper/TooFewMinesContradictionRuleTest.java new file mode 100644 index 000000000..82cecf8a4 --- /dev/null +++ b/src/test/java/puzzles/minesweeper/TooFewMinesContradictionRuleTest.java @@ -0,0 +1,70 @@ +package puzzles.minesweeper; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.minesweeper.Minesweeper; +import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; +import edu.rpi.legup.puzzle.minesweeper.rules.TooFewMinesContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TooFewMinesContradictionRuleTest { + private static final TooFewMinesContradictionRule RULE = new TooFewMinesContradictionRule(); + private static Minesweeper minesweeper; + + @BeforeClass + public static void setUp() { + minesweeper = new Minesweeper(); + } + + @Test + // tests a 3x3 board with a 3 in the center surrounded by 2 mines and 6 empty + public void TooManyMinesTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/minesweeper/rules/TooFewMines1.txt", minesweeper); + TreeNode rootNode = minesweeper.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); + + // confirm it is impossible to satisfy up the center square + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + + // every square except the center + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); + } + + @Test + // tests a 3x3 board with a 3 in the center surrounded by 2 unset and 6 empty + public void TooManyMinesTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/minesweeper/rules/TooFewMines2.txt", minesweeper); + TreeNode rootNode = minesweeper.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); + + // confirm it is impossible to satisfy up the center square + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + + // every square except the center + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); + } +} diff --git a/src/test/java/puzzles/minesweeper/TooManyMinesContradictionRuleTest.java b/src/test/java/puzzles/minesweeper/TooManyMinesContradictionRuleTest.java new file mode 100644 index 000000000..64f2ad810 --- /dev/null +++ b/src/test/java/puzzles/minesweeper/TooManyMinesContradictionRuleTest.java @@ -0,0 +1,46 @@ +package puzzles.minesweeper; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.minesweeper.Minesweeper; +import edu.rpi.legup.puzzle.minesweeper.MinesweeperBoard; +import edu.rpi.legup.puzzle.minesweeper.rules.TooManyMinesContradictionRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TooManyMinesContradictionRuleTest { + private static final TooManyMinesContradictionRule RULE = new TooManyMinesContradictionRule(); + private static Minesweeper minesweeper; + + @BeforeClass + public static void setUp() { + minesweeper = new Minesweeper(); + } + + @Test + // tests a 3x3 board with a 3 in the center and 4 surrounding mines + public void TooManyMinesTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard( + "puzzles/minesweeper/rules/TooManyMines.txt", minesweeper); + TreeNode rootNode = minesweeper.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); + + // confirm it is impossible to satisfy up the center square + Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1))); + + // every square except the center + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 2))); + Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1))); + } +} diff --git a/src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt b/src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt new file mode 100644 index 000000000..a817ad6bb --- /dev/null +++ b/src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/minesweeper/rules/TooFewMines2.txt b/src/test/resources/puzzles/minesweeper/rules/TooFewMines2.txt new file mode 100644 index 000000000..b1bade015 --- /dev/null +++ b/src/test/resources/puzzles/minesweeper/rules/TooFewMines2.txt @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/minesweeper/rules/TooManyMines.txt b/src/test/resources/puzzles/minesweeper/rules/TooManyMines.txt new file mode 100644 index 000000000..bba206653 --- /dev/null +++ b/src/test/resources/puzzles/minesweeper/rules/TooManyMines.txt @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file