Skip to content

Commit

Permalink
Added another set of tests for TooManyBulbsContradictionRule
Browse files Browse the repository at this point in the history
  • Loading branch information
Acewvrs authored and Corppet committed Apr 4, 2023
1 parent 15dbee6 commit 3ec5ea8
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="1"/>
<cell value="-4" x="1" y="0"/>
<cell value="1" x="1" y="1"/>
<cell value="-4" x="1" y="2"/>
<cell value="-4" x="2" y="1"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="1" x="0" y="1"/>
<cell value="-3" x="0" y="2"/>
<cell value="-4" x="1" y="1"/>
<cell value="-3" x="2" y="0"/>
<cell value="1" x="2" y="1"/>
<cell value="-4" x="2" y="2"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="1" x="0" y="0"/>
<cell value="-4" x="0" y="1"/>
<cell value="-4" x="1" y="0"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Legup>
<puzzle name="LightUp">
<board width="3" height="3">
<cells>
<cell value="-4" x="0" y="0"/>
<cell value="1" x="0" y="1"/>
<cell value="-4" x="0" y="2"/>
<cell value="2" x="1" y="0"/>
<cell value="-4" x="1" y="1"/>
<cell value="1" x="1" y="2"/>
<cell value="-4" x="2" y="0"/>
<cell value="3" x="2" y="1"/>
<cell value="-4" x="2" y="2"/>
</cells>
</board>
</puzzle>
</Legup>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package puzzles.lightup.rules;

import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.rules.CannotLightACellContradictionRule;
import edu.rpi.legup.puzzle.lightup.rules.TooFewBulbsContradictionRule;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,97 @@
package puzzles.lightup.rules;

import edu.rpi.legup.puzzle.lightup.LightUpBoard;
import edu.rpi.legup.puzzle.lightup.rules.TooManyBulbsContradictionRule;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.PuzzleImporter;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import org.junit.Assert;
import edu.rpi.legup.puzzle.lightup.LightUp;
import edu.rpi.legup.save.InvalidFileFormatException;

import org.junit.BeforeClass;
import org.junit.Test;
import edu.rpi.legup.puzzle.lightup.LightUp;

public class TooManyBulbsContradictionRuleTest {
private static final TooManyBulbsContradictionRule RULE = new TooManyBulbsContradictionRule();
private static LightUp lightUp;
private static PuzzleImporter importer;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
lightUp = new LightUp();
importer = lightUp.getImporter();
}
@Test
public void TooManyBulbsContradictionRule_BlockEnclosed() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
}

@Test
public void simpleCaseTest() {
public void TooManyBulbsContradictionRule_CornerBlockEnclosed() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/TooManybulbsContradictionRule/CornerBlockEnclosed", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
Assert.assertNull(RULE.checkContradiction(board));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
}
//
@Test
public void TooManyBulbsContradictionRule_ManyBlocksEnclosed() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
Assert.assertNull(RULE.checkContradiction(board));

Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(1, 2)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2)));
}

@Test
public void TooManyBulbsContradictionRule_CompleteBoardBlockEnclosed() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed", lightUp);
TreeNode rootNode = lightUp.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

LightUpBoard board = (LightUpBoard) transition.getBoard();
Assert.assertNull(RULE.checkContradiction(board));

Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(0, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(0, 2)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(1, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 0)));
Assert.assertNull(RULE.checkContradictionAt(board, board.getCell(2, 1)));
Assert.assertNotNull(RULE.checkContradictionAt(board, board.getCell(2, 2)));
}
}

0 comments on commit 3ec5ea8

Please sign in to comment.