Skip to content

Commit

Permalink
Finishing Blackout Test
Browse files Browse the repository at this point in the history
Added incorrect use of rule test
  • Loading branch information
offline171 committed Jun 21, 2024
1 parent 02bf6f5 commit b222cdc
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 42 deletions.
148 changes: 144 additions & 4 deletions src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,71 @@ public void BlackoutDirectRuleTestCorner()
cell3.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell4 = board.getCell(0,1);
cell4.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell5 = board.getCell(0,2);
StarBattleCell cell5 = board.getCell(1,1);
cell5.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell6 = board.getCell(0,3);
StarBattleCell cell6 = board.getCell(0,2);
cell6.setData(StarBattleCellType.BLACK.value);

StarBattleCell cell7 = board.getCell(0,3);
cell7.setData(StarBattleCellType.BLACK.value);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);
board.addModifiedData(cell5);
board.addModifiedData(cell6);
board.addModifiedData(cell7);

Assert.assertNull(RULE.checkRule(transition));

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()) ||
point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) ||
point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) ||
point.equals(cell7.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
}
}
}
/* Blackout Direct Rule where star is on the edge */
@Test
public void BlackoutDirectRuleTestEdge()
throws InvalidFileFormatException
{
TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Edge", 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);
cell1.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell2 = board.getCell(2,0);
cell2.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell3 = board.getCell(3,0);
cell3.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell4 = board.getCell(0,1);
cell4.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell5 = board.getCell(1,1);
cell5.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell6 = board.getCell(1,2);
cell6.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell7 = board.getCell(1,3);
cell7.setData(StarBattleCellType.BLACK.value);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);
board.addModifiedData(cell5);
board.addModifiedData(cell6);
board.addModifiedData(cell7);

Assert.assertNull(RULE.checkRule(transition));

Expand All @@ -63,7 +117,8 @@ public void BlackoutDirectRuleTestCorner()
Point point = new Point(j,i);
if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) ||
point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) ||
point.equals(cell5.getLocation()) || point.equals(cell6.getLocation())) {
point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) ||
point.equals(cell7.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
else {
Expand All @@ -73,4 +128,89 @@ public void BlackoutDirectRuleTestCorner()
}
}

/* Blackout Direct Rule where star is on the edge */
@Test
public void BlackoutDirectRuleTestMiddle()
throws InvalidFileFormatException
{
TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", 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);
cell1.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell2 = board.getCell(1,0);
cell2.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell3 = board.getCell(0,1);
cell3.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell4 = board.getCell(2,1);
cell4.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell5 = board.getCell(3,1);
cell5.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell6 = board.getCell(1,2);
cell6.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell7 = board.getCell(1,3);
cell7.setData(StarBattleCellType.BLACK.value);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);
board.addModifiedData(cell5);
board.addModifiedData(cell6);
board.addModifiedData(cell7);

Assert.assertNull(RULE.checkRule(transition));

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()) ||
point.equals(cell3.getLocation()) || point.equals(cell4.getLocation()) ||
point.equals(cell5.getLocation()) || point.equals(cell6.getLocation()) ||
point.equals(cell7.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
}
}
}
/* Blackout Direct Rule where rule is called incorrectly */
@Test
public void BlackoutDirectRuleTestFalse()
throws InvalidFileFormatException
{
TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/Middle", 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,2);
cell1.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell2 = board.getCell(2,3);
cell2.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell3 = board.getCell(3,2);
cell3.setData(StarBattleCellType.BLACK.value);
StarBattleCell cell4 = board.getCell(3,3);

board.addModifiedData(cell1);
board.addModifiedData(cell2);
board.addModifiedData(cell3);
board.addModifiedData(cell4);

Assert.assertNotNull(RULE.checkRule(transition));

for (int i = 0; i < board.getHeight(); ++i) {
for (int j = 0; j < board.getWidth(); ++j) {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(j, i)));
}
}
}


}
43 changes: 24 additions & 19 deletions src/test/resources/puzzles/starbattle/rules/BlackoutDirectRule/Edge
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
<Legup>
<puzzle name="Star Battle">
<?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="2">
<cell value="0" x="1" y="2">
<cell value="0" x="0" y="3">
<cell value="0" x="1" y="3">
<cell value="0" x="0" y="0"/>
<cell value="-2" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="0" x="1" y="1"/>
</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="3">
<cell value="0" x="2" y="0"/>
<cell value="0" x="3" y="0"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="3" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="0">
<cell value="-2" x="1" y="0">
<cell value="0" x="0" y="1">
<cell value="0" x="1" 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="0">
<cell value="0" x="3" y="0">
<cell value="0" x="2" y="1">
<cell value="0" x="3" y="1">
<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="3"/>
</cells>
</region>
</board>
</puzzle>
</Legup>
<solved isSolved="false" lastSaved="--"/>
</Legup>

Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
<Legup>
<puzzle name="Star Battle">
<?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="2">
<cell value="0" x="1" y="2">
<cell value="0" x="0" y="3">
<cell value="0" x="1" y="3">
<cell value="0" x="0" y="0"/>
<cell value="0" x="1" y="0"/>
<cell value="0" x="0" y="1"/>
<cell value="-2" x="1" y="1"/>
</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="3">
<cell value="0" x="2" y="0"/>
<cell value="0" x="3" y="0"/>
<cell value="0" x="2" y="1"/>
<cell value="0" x="3" y="1"/>
</cells>
</region>
<region>
<cells>
<cell value="0" x="0" y="0">
<cell value="-2" x="1" y="0">
<cell value="0" x="0" y="1">
<cell value="0" x="1" 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="0">
<cell value="0" x="3" y="0">
<cell value="0" x="2" y="1">
<cell value="0" x="3" y="1">
<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="3"/>
</cells>
</region>
</board>
</puzzle>
</Legup>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit b222cdc

Please sign in to comment.