-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test suites for both of the contradiction rules
- Loading branch information
1 parent
8c7ebf8
commit e7a6546
Showing
15 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/test/java/puzzles/minesweeper/TooFewMinesContradictionRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/puzzles/minesweeper/TooManyMinesContradictionRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/test/resources/puzzles/minesweeper/rules/TooFewMines1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.