-
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.
Created the test suites for both of the case rules. Also some minor changes
- Loading branch information
1 parent
fafd7d6
commit 8c7ebf8
Showing
9 changed files
with
209 additions
and
6 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
75 changes: 75 additions & 0 deletions
75
src/test/java/puzzles/minesweeper/MineOrEmptyCaseRuleTest.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,75 @@ | ||
package puzzles.minesweeper; | ||
|
||
import edu.rpi.legup.model.gameboard.Board; | ||
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.MinesweeperCell; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; | ||
import edu.rpi.legup.puzzle.minesweeper.rules.MineOrEmptyCaseRule; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.awt.*; | ||
import java.util.ArrayList; | ||
|
||
public class MineOrEmptyCaseRuleTest { | ||
|
||
private static final MineOrEmptyCaseRule RULE = new MineOrEmptyCaseRule(); | ||
private static Minesweeper minesweeper; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
minesweeper = new Minesweeper(); | ||
} | ||
|
||
/** | ||
* Tests the Mine or Empty case rule by ensuring that it results in two children, that contain | ||
* a modified cell that is either black or white | ||
*/ | ||
@Test | ||
public void MineOrEmptyCaseRuleTest1() | ||
throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard( | ||
"puzzles/minesweeper/rules/MineOrEmpty.txt", minesweeper); | ||
TreeNode rootNode = minesweeper.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); | ||
MinesweeperCell cell = board.getCell(0, 0); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
Assert.assertEquals(2, cases.size()); | ||
|
||
MinesweeperBoard caseBoard = (MinesweeperBoard) cases.get(0); | ||
MinesweeperBoard caseBoard2 = (MinesweeperBoard) cases.get(1); | ||
|
||
MinesweeperTileData board1Type = caseBoard.getCell(0, 0).getData(); | ||
MinesweeperTileData board2Type = caseBoard2.getCell(0, 0).getData(); | ||
|
||
Assert.assertTrue( | ||
((board1Type.equals(MinesweeperTileData.mine()) || board1Type.equals(MinesweeperTileData.empty()))) | ||
&& (board2Type.equals(MinesweeperTileData.mine()) || board2Type.equals(MinesweeperTileData.empty()))); | ||
Assert.assertFalse(board1Type.equals(board2Type)); | ||
|
||
Assert.assertEquals(caseBoard.getHeight(), caseBoard2.getHeight(), board.getHeight()); | ||
Assert.assertEquals(caseBoard.getWidth(), caseBoard2.getWidth(), board.getWidth()); | ||
|
||
for (int i = 0; i < caseBoard.getHeight(); i++) { | ||
for (int k = 0; k < caseBoard.getWidth(); k++) { | ||
Point point = new Point(k, i); | ||
if (point.equals(caseBoard.getCell(k, i).getLocation())) { | ||
continue; | ||
} | ||
Assert.assertTrue(caseBoard.getCell(k, i).equals(caseBoard2.getCell(k, i))); | ||
} | ||
} | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
src/test/java/puzzles/minesweeper/SatisfyNumberCaseRuleTest.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,100 @@ | ||
package puzzles.minesweeper; | ||
|
||
import edu.rpi.legup.model.gameboard.Board; | ||
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.MinesweeperCell; | ||
import edu.rpi.legup.puzzle.minesweeper.MinesweeperTileData; | ||
import edu.rpi.legup.puzzle.minesweeper.rules.SatisfyNumberCaseRule; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.awt.*; | ||
import java.util.ArrayList; | ||
|
||
public class SatisfyNumberCaseRuleTest { | ||
|
||
private static final SatisfyNumberCaseRule RULE = new SatisfyNumberCaseRule(); | ||
private static Minesweeper minesweeper; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
minesweeper = new Minesweeper(); | ||
} | ||
|
||
/** | ||
* Tests the Satisfy Number case rule by ensuring that it results in all possibilities | ||
* for the number. This case tests a number 2 with three unset cells around it, so each | ||
* case must a different arrangement of two bombs and one empty. | ||
*/ | ||
@Test | ||
public void SatisfyNumberCaseRuleTest1() | ||
throws InvalidFileFormatException { | ||
TestUtilities.importTestBoard( | ||
"puzzles/minesweeper/rules/SatisfyNumber.txt", minesweeper); | ||
TreeNode rootNode = minesweeper.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
MinesweeperBoard board = (MinesweeperBoard) transition.getBoard(); | ||
MinesweeperCell cell = board.getCell(1, 1); | ||
ArrayList<Board> cases = RULE.getCases(board, cell); | ||
|
||
Assert.assertEquals(3, cases.size()); | ||
|
||
MinesweeperBoard caseBoard = (MinesweeperBoard) cases.get(0); | ||
MinesweeperBoard caseBoard2 = (MinesweeperBoard) cases.get(1); | ||
MinesweeperBoard caseBoard3 = (MinesweeperBoard) cases.get(2); | ||
|
||
MinesweeperTileData board1Tile1 = caseBoard.getCell(0, 1).getData(); | ||
MinesweeperTileData board1Tile2 = caseBoard.getCell(2, 1).getData(); | ||
MinesweeperTileData board1Tile3 = caseBoard.getCell(1, 2).getData(); | ||
MinesweeperTileData board2Tile1 = caseBoard2.getCell(0, 1).getData(); | ||
MinesweeperTileData board2Tile2 = caseBoard2.getCell(2, 1).getData(); | ||
MinesweeperTileData board2Tile3 = caseBoard2.getCell(1, 2).getData(); | ||
MinesweeperTileData board3Tile1 = caseBoard3.getCell(0, 1).getData(); | ||
MinesweeperTileData board3Tile2 = caseBoard3.getCell(2, 1).getData(); | ||
MinesweeperTileData board3Tile3 = caseBoard3.getCell(1, 2).getData(); | ||
|
||
Assert.assertTrue((board1Tile1.equals(MinesweeperTileData.mine()) && board1Tile2.equals(MinesweeperTileData.mine()) | ||
&& board1Tile3.equals(MinesweeperTileData.empty())) | ||
|| (board1Tile1.equals(MinesweeperTileData.mine()) && board1Tile2.equals(MinesweeperTileData.empty()) && board1Tile3.equals(MinesweeperTileData.mine())) | ||
|| ((board1Tile1.equals(MinesweeperTileData.empty()) && board1Tile2.equals(MinesweeperTileData.mine()) && board1Tile3.equals(MinesweeperTileData.mine())))); | ||
|
||
Assert.assertTrue((board2Tile1.equals(MinesweeperTileData.mine()) && board2Tile2.equals(MinesweeperTileData.mine()) | ||
&& board2Tile3.equals(MinesweeperTileData.empty())) | ||
|| (board2Tile1.equals(MinesweeperTileData.mine()) && board2Tile2.equals(MinesweeperTileData.empty()) && board2Tile3.equals(MinesweeperTileData.mine())) | ||
|| ((board2Tile1.equals(MinesweeperTileData.empty()) && board2Tile2.equals(MinesweeperTileData.mine()) && board2Tile3.equals(MinesweeperTileData.mine())))); | ||
|
||
Assert.assertTrue((board3Tile1.equals(MinesweeperTileData.mine()) && board3Tile2.equals(MinesweeperTileData.mine()) | ||
&& board3Tile3.equals(MinesweeperTileData.empty())) | ||
|| (board3Tile1.equals(MinesweeperTileData.mine()) && board3Tile2.equals(MinesweeperTileData.empty()) && board3Tile3.equals(MinesweeperTileData.mine())) | ||
|| ((board3Tile1.equals(MinesweeperTileData.empty()) && board3Tile2.equals(MinesweeperTileData.mine()) && board3Tile3.equals(MinesweeperTileData.mine())))); | ||
|
||
Assert.assertFalse(board1Tile1.equals(board2Tile1) && board1Tile1.equals(board3Tile1)); | ||
Assert.assertFalse(board1Tile2.equals(board2Tile2) && board1Tile2.equals(board3Tile2)); | ||
Assert.assertFalse(board1Tile3.equals(board2Tile3) && board1Tile3.equals(board3Tile3)); | ||
|
||
Assert.assertEquals(caseBoard.getHeight(), caseBoard2.getHeight(), caseBoard3.getHeight()); | ||
Assert.assertEquals(caseBoard.getHeight(), board.getHeight()); | ||
Assert.assertEquals(caseBoard.getWidth(), caseBoard2.getWidth(), caseBoard3.getWidth()); | ||
Assert.assertEquals(caseBoard.getWidth(), board.getWidth()); | ||
|
||
for (int i = 0; i < caseBoard.getHeight(); i++) { | ||
for (int k = 0; k < caseBoard.getWidth(); k++) { | ||
Point point = new Point(k, i); | ||
if (point.equals(caseBoard.getCell(k, i).getLocation())) { | ||
continue; | ||
} | ||
Assert.assertTrue(caseBoard.getCell(k, i).equals(caseBoard2.getCell(k, i))); | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/resources/puzzles/minesweeper/rules/MineOrEmpty.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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="Minesweeper"> | ||
<board height="3" width="3"> | ||
<cells> | ||
</cells> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> |
19 changes: 19 additions & 0 deletions
19
src/test/resources/puzzles/minesweeper/rules/SatisfyNumber.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="-2" x="0" y="1"/> | ||
<cell value="2" x="1" y="1"/> | ||
<cell value="-2" x="2" y="1"/> | ||
<cell value="0" x="0" y="2"/> | ||
<cell value="-2" x="1" y="2"/> | ||
<cell value="0" x="2" y="2"/> | ||
</cells> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> |