Skip to content

Commit

Permalink
Contradiction Rules Test
Browse files Browse the repository at this point in the history
Test suites for both of the contradiction rules
  • Loading branch information
willyoung366 committed Nov 27, 2024
1 parent 8c7ebf8 commit e7a6546
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)));
}
}
Original file line number Diff line number Diff line change
@@ -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)));
}
}
19 changes: 19 additions & 0 deletions src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Minesweeper">
<board height="3" width="3">
<cells>
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="2" y="0"/>
<cell value="-1" x="0" y="1"/>
<cell value="3" x="1" y="1"/>
<cell value="-1" x="2" y="1"/>
<cell value="0" x="0" y="2"/>
<cell value="0" x="1" y="2"/>
<cell value="0" x="2" y="2"/>
</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
Loading

0 comments on commit e7a6546

Please sign in to comment.