forked from Bram-Hub/LEGUP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cases for Too Many Stars contradiction rule started on with boards and a visualization pdf added as well
- Loading branch information
1 parent
9ef4cd4
commit d3a677e
Showing
6 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
src/test/java/puzzles/starbattle/rules/TooManyStarsContradictionRuleTests.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,138 @@ | ||
package puzzles.starbattle.rules; | ||
|
||
import edu.rpi.legup.puzzle.starbattle.rules.TooManyStarsContradictionRule; | ||
import edu.rpi.legup.model.tree.TreeNode; | ||
import edu.rpi.legup.model.tree.TreeTransition; | ||
import edu.rpi.legup.puzzle.starbattle.StarBattle; | ||
import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; | ||
import edu.rpi.legup.puzzle.starbattle.StarBattleCell; | ||
import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; | ||
import edu.rpi.legup.save.InvalidFileFormatException; | ||
import java.awt.*; | ||
import legup.MockGameBoardFacade; | ||
import legup.TestUtilities; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class TooManyStarsContradictionRuleTests { | ||
private static final TooManyStarsContradictionRule RULE = new TooManyStarsContradictionRule(); | ||
private static StarBattle starBattle; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
MockGameBoardFacade.getInstance(); | ||
starBattle = new StarBattle(); | ||
} | ||
|
||
/* Tests the Too Many Stars contradiction rule where a region has | ||
more stars than the puzzle number */ | ||
@Test | ||
public void TooManyStarsContradictionRule_RegionOverloaded() | ||
throws InvalidFileFormatException | ||
{ | ||
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RegionOverloaded", starBattle); | ||
TreeNode rootNode = starBattle.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
StarBattleBoard board = (StarBattleBoard) transition.getBoard(); | ||
StarBattleCell cell1 = board.getCell(2,1); | ||
StarBattleCell cell2 = board.getCell(0,2); | ||
|
||
Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); | ||
|
||
for (int i = 0; i < board.getHeight(); ++i) { | ||
for (int j = 0; j < board.getWidth(); ++j) { | ||
Point point = new Point(j,i); | ||
if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { | ||
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* Tests the Too Many Stars contradiction rule where a column has | ||
more stars than the puzzle number */ | ||
@Test | ||
public void TooManyStarsContradictionRule_ColumnOverloaded() | ||
throws InvalidFileFormatException | ||
{ | ||
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/ColumnOverloaded", starBattle); | ||
TreeNode rootNode = starBattle.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
StarBattleBoard board = (StarBattleBoard) transition.getBoard(); | ||
StarBattleCell cell1 = board.getCell(0,0); | ||
StarBattleCell cell2 = board.getCell(0,3); | ||
|
||
Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); | ||
|
||
for (int i = 0; i < board.getHeight(); ++i) { | ||
for (int j = 0; j < board.getWidth(); ++j) { | ||
Point point = new Point(j,i); | ||
if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { | ||
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
} | ||
} | ||
} | ||
/* Tests the Too Many Stars contradiction rule where a row has | ||
more stars than the puzzle number */ | ||
@Test | ||
public void TooManyStarsContradictionRule_RowOverloaded() | ||
throws InvalidFileFormatException | ||
{ | ||
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/RowOverloaded", starBattle); | ||
TreeNode rootNode = starBattle.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
StarBattleBoard board = (StarBattleBoard) transition.getBoard(); | ||
StarBattleCell cell1 = board.getCell(0,0); | ||
StarBattleCell cell2 = board.getCell(3,0); | ||
|
||
Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); | ||
|
||
for (int i = 0; i < board.getHeight(); ++i) { | ||
for (int j = 0; j < board.getWidth(); ++j) { | ||
Point point = new Point(j,i); | ||
if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation())) { | ||
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
else { | ||
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
} | ||
} | ||
} | ||
} | ||
/* Tests the Too Many Stars contradiction rule where it is used incorrectly */ | ||
@Test | ||
public void TooManyStarsContradictionRule_Correct() | ||
throws InvalidFileFormatException | ||
{ | ||
TestUtilities.importTestBoard("puzzles/starbattle/rules/TooManyStarsContradictionRule/Correct", starBattle); | ||
TreeNode rootNode = starBattle.getTree().getRootNode(); | ||
TreeTransition transition = rootNode.getChildren().get(0); | ||
transition.setRule(RULE); | ||
|
||
StarBattleBoard board = (StarBattleBoard) transition.getBoard(); | ||
|
||
Assert.assertNull(RULE.checkContradiction((StarBattleBoard) transition.getBoard())); | ||
|
||
for (int i = 0; i < board.getHeight(); ++i) { | ||
for (int j = 0; j < board.getWidth(); ++j) { | ||
Point point = new Point(j,i); | ||
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i))); | ||
|
||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/resources/puzzles/starbattle/rules/TooManyStarsContradictionRule/ColumnOverloaded
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="StarBattle"> | ||
<board size="4" puzzle_num="1"> | ||
<region> | ||
<cells> | ||
<cell value="-2" x="0" y="0"/> | ||
<cell value="0" x="1" y="0"/> | ||
<cell value="0" x="2" y="0"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="3" y="0"/> | ||
<cell value="0" x="3" y="1"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="1"/> | ||
<cell value="0" x="1" y="1"/> | ||
<cell value="0" x="2" y="1"/> | ||
<cell value="0" x="0" y="2"/> | ||
<cell value="0" x="1" y="2"/> | ||
<cell value="-2" x="0" y="3"/> | ||
<cell value="0" x="1" y="3"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="2" y="2"/> | ||
<cell value="0" x="3" y="2"/> | ||
<cell value="0" x="2" y="3"/> | ||
<cell value="0" x="3" y="4"/> | ||
</cells> | ||
</region> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> | ||
|
41 changes: 41 additions & 0 deletions
41
src/test/resources/puzzles/starbattle/rules/TooManyStarsContradictionRule/Correct
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="StarBattle"> | ||
<board size="4" puzzle_num="1"> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="0"/> | ||
<cell value="-2" x="1" y="0"/> | ||
<cell value="0" x="2" y="0"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="3" y="0"/> | ||
<cell value="-2" x="3" y="1"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="1"/> | ||
<cell value="0" x="1" y="1"/> | ||
<cell value="0" x="2" y="1"/> | ||
<cell value="-2" x="0" y="2"/> | ||
<cell value="0" x="1" y="2"/> | ||
<cell value="0" x="0" y="3"/> | ||
<cell value="0" x="1" y="3"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="2" y="2"/> | ||
<cell value="0" x="3" y="2"/> | ||
<cell value="-2" x="2" y="3"/> | ||
<cell value="0" x="3" y="4"/> | ||
</cells> | ||
</region> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> | ||
|
Binary file added
BIN
+15.1 KB
...rbattle/rules/TooManyStarsContradictionRule/Region Overloaded Visualized-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions
41
src/test/resources/puzzles/starbattle/rules/TooManyStarsContradictionRule/RegionOverloaded
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="StarBattle"> | ||
<board size="4" puzzle_num="1"> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="0"/> | ||
<cell value="0" x="1" y="0"/> | ||
<cell value="0" x="2" y="0"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="3" y="0"/> | ||
<cell value="0" x="3" y="1"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="1"/> | ||
<cell value="0" x="1" y="1"/> | ||
<cell value="-2" x="2" y="1"/> | ||
<cell value="-2" x="0" y="2"/> | ||
<cell value="0" x="1" y="2"/> | ||
<cell value="0" x="0" y="3"/> | ||
<cell value="0" x="1" y="3"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="2" y="2"/> | ||
<cell value="0" x="3" y="2"/> | ||
<cell value="0" x="2" y="3"/> | ||
<cell value="0" x="3" y="4"/> | ||
</cells> | ||
</region> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> | ||
|
41 changes: 41 additions & 0 deletions
41
src/test/resources/puzzles/starbattle/rules/TooManyStarsContradictionRule/RowOverloaded
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,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> | ||
<Legup version="2.0.0"> | ||
<puzzle name="StarBattle"> | ||
<board size="4" puzzle_num="1"> | ||
<region> | ||
<cells> | ||
<cell value="-2" x="0" y="0"/> | ||
<cell value="0" x="1" y="0"/> | ||
<cell value="0" x="2" y="0"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="-2" x="3" y="0"/> | ||
<cell value="0" x="3" y="1"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="0" y="1"/> | ||
<cell value="0" x="1" y="1"/> | ||
<cell value="0" x="2" y="1"/> | ||
<cell value="0" x="0" y="2"/> | ||
<cell value="0" x="1" y="2"/> | ||
<cell value="0" x="0" y="3"/> | ||
<cell value="0" x="1" y="3"/> | ||
</cells> | ||
</region> | ||
<region> | ||
<cells> | ||
<cell value="0" x="2" y="2"/> | ||
<cell value="0" x="3" y="2"/> | ||
<cell value="0" x="2" y="3"/> | ||
<cell value="0" x="3" y="4"/> | ||
</cells> | ||
</region> | ||
</board> | ||
</puzzle> | ||
<solved isSolved="false" lastSaved="--"/> | ||
</Legup> | ||
|