diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 40cc5fa6c..21d2ef500 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -18,7 +18,7 @@ public static void main(String[] args) { Result result2 = JUnitCore.runClasses(FinishWithShipsDirectRuleTests.class); printTestResults(result2); - // Lightup Tests + // LightUp Tests Result result3 = JUnitCore.runClasses(BulbsInPathContradictionRuleTest.class); printTestResults(result3); Result result4 = JUnitCore.runClasses(CannotLightACellContradictionRuleTest.class); @@ -29,68 +29,70 @@ public static void main(String[] args) { printTestResults(result6); Result result7 = JUnitCore.runClasses(FinishWithBulbsDirectRuleTest.class); printTestResults(result7); - Result result8 = JUnitCore.runClasses(LightOrEmptyCaseRuleTest.class); + Result result8 = JUnitCore.runClasses(FinishWithEmptyDirectRuleTest.class); printTestResults(result8); - Result result9 = JUnitCore.runClasses(MustLightDirectRuleTest.class); + Result result9 = JUnitCore.runClasses(LightOrEmptyCaseRuleTest.class); printTestResults(result9); - Result result10 = JUnitCore.runClasses(SatisfyNumberCaseRuleTest.class); + Result result10 = JUnitCore.runClasses(MustLightDirectRuleTest.class); printTestResults(result10); - Result result11 = JUnitCore.runClasses(TooFewBulbsContradictionRuleTest.class); + Result result11 = JUnitCore.runClasses(SatisfyNumberCaseRuleTest.class); printTestResults(result11); - Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class); + Result result12 = JUnitCore.runClasses(TooFewBulbsContradictionRuleTest.class); printTestResults(result12); - - // nurikabe tests - Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class); + Result result13 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class); printTestResults(result13); - Result result14 = JUnitCore.runClasses(BlackBottleNeckDirectRuleTest.class); + + //nurikabe tests + Result result14 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class); printTestResults(result14); - Result result15 = JUnitCore.runClasses(BlackOrWhiteCaseRuleTest.class); + Result result15 = JUnitCore.runClasses(BlackBottleNeckDirectRuleTest.class); printTestResults(result15); - Result result16 = JUnitCore.runClasses(BlackSquareContradictionRuleTest.class); + Result result16 = JUnitCore.runClasses(BlackOrWhiteCaseRuleTest.class); printTestResults(result16); - Result result17 = JUnitCore.runClasses(CornerBlackDirectRuleTest.class); + Result result17 = JUnitCore.runClasses(BlackSquareContradictionRuleTest.class); printTestResults(result17); - Result result18 = JUnitCore.runClasses(FillinBlackDirectRuleTest.class); + Result result18 = JUnitCore.runClasses(CornerBlackDirectRuleTest.class); printTestResults(result18); - Result result19 = JUnitCore.runClasses(FillinWhiteDirectRuleTest.class); + Result result19 = JUnitCore.runClasses(FillinBlackDirectRuleTest.class); printTestResults(result19); - Result result20 = JUnitCore.runClasses(IsolateBlackContradictionRuleTest.class); + Result result20 = JUnitCore.runClasses(FillinWhiteDirectRuleTest.class); printTestResults(result20); - Result result21 = JUnitCore.runClasses(MultipleNumbersContradictionRuleTest.class); + Result result21 = JUnitCore.runClasses(IsolateBlackContradictionRuleTest.class); printTestResults(result21); - Result result22 = JUnitCore.runClasses(NoNumbersContradictionRuleTest.class); + Result result22 = JUnitCore.runClasses(MultipleNumbersContradictionRuleTest.class); printTestResults(result22); - Result result23 = JUnitCore.runClasses(PreventBlackSquareDirectRuleTest.class); + Result result23 = JUnitCore.runClasses(NoNumbersContradictionRuleTest.class); printTestResults(result23); - Result result24 = JUnitCore.runClasses(SurroundRegionDirectRuleTest.class); + Result result24 = JUnitCore.runClasses(PreventBlackSquareDirectRuleTest.class); printTestResults(result24); - Result result25 = JUnitCore.runClasses(TooFewSpacesContradictionRuleTest.class); + Result result25 = JUnitCore.runClasses(SurroundRegionDirectRuleTest.class); printTestResults(result25); - Result result26 = JUnitCore.runClasses(TooManySpacesContradictionRuleTest.class); + Result result26 = JUnitCore.runClasses(TooFewSpacesContradictionRuleTest.class); printTestResults(result26); - Result result27 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class); + Result result27 = JUnitCore.runClasses(TooManySpacesContradictionRuleTest.class); printTestResults(result27); + Result result28 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class); + printTestResults(result28); // Treetent - Result result28 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class); - printTestResults(result28); - Result result29 = JUnitCore.runClasses(FinishWithGrassDirectRuleTest.class); + Result result29 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class); printTestResults(result29); - Result result30 = JUnitCore.runClasses(FinishWithTentsDirectRuleTest.class); + Result result30 = JUnitCore.runClasses(FinishWithGrassDirectRuleTest.class); printTestResults(result30); - Result result31 = JUnitCore.runClasses(LastCampingSpotDirectRuleTest.class); + Result result31 = JUnitCore.runClasses(FinishWithTentsDirectRuleTest.class); printTestResults(result31); - Result result32 = JUnitCore.runClasses(NoTentForTreeContradictionRuleTest.class); + Result result32 = JUnitCore.runClasses(LastCampingSpotDirectRuleTest.class); printTestResults(result32); - Result result33 = JUnitCore.runClasses(NoTreeForTentContradictionRuleTest.class); + Result result33 = JUnitCore.runClasses(NoTentForTreeContradictionRuleTest.class); printTestResults(result33); - Result result34 = JUnitCore.runClasses(SurroundTentWithGrassDirectRuleTest.class); + Result result34 = JUnitCore.runClasses(NoTreeForTentContradictionRuleTest.class); printTestResults(result34); - Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class); + Result result35 = JUnitCore.runClasses(SurroundTentWithGrassDirectRuleTest.class); printTestResults(result35); - Result result36 = JUnitCore.runClasses(TentOrGrassCaseRuleTest.class); + Result result36 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class); printTestResults(result36); + Result result37 = JUnitCore.runClasses(TentOrGrassCaseRuleTest.class); + printTestResults(result37); } private static void printTestResults(Result result) { diff --git a/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java b/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java new file mode 100644 index 000000000..3a032a35d --- /dev/null +++ b/src/test/java/puzzles/lightup/rules/FinishWithEmptyDirectRuleTest.java @@ -0,0 +1,102 @@ +package puzzles.lightup.rules; + +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import edu.rpi.legup.puzzle.lightup.LightUp; +import edu.rpi.legup.puzzle.lightup.LightUpBoard; +import edu.rpi.legup.puzzle.lightup.LightUpCell; +import edu.rpi.legup.puzzle.lightup.LightUpCellType; +import edu.rpi.legup.puzzle.lightup.rules.FinishWithEmptyDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class FinishWithEmptyDirectRuleTest { + private static final FinishWithEmptyDirectRule RULE = new FinishWithEmptyDirectRule(); + private static LightUp lightUp; + + @BeforeClass + public static void setUp() { lightUp = new LightUp(); } + + @Test + public void FinishEmptyTestWithOne() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithOne", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + //get board state + LightUpBoard board = (LightUpBoard) transition.getBoard(); + // The board has a "1" clue at (1,1) with a bulb one space above at (1,0); + + //change the board's cells considering the FinishWithEmpty rule to empty + LightUpCell cell1 = board.getCell(0,1); //left + cell1.setData(LightUpCellType.EMPTY.value); + board.addModifiedData(cell1); + + LightUpCell cell2 = board.getCell(2,1); //right + cell2.setData(LightUpCellType.EMPTY.value); + board.addModifiedData(cell2); + + LightUpCell cell3 = board.getCell(1,2); //below + cell3.setData(LightUpCellType.EMPTY.value); + board.addModifiedData(cell3); + + //confirm there is a logical following of the FinishWithEmpty rule + Assert.assertNull(RULE.checkRule(transition)); + + //check every square except the top center (2,0) + LightUpCell c; + for (int i = 0; i < board.getHeight(); i++) { + for (int j = 0; j < board.getWidth(); j++) { + c = board.getCell(j, i); + if ((i == 1 && j == 0) || (i == 1 && j == 2) || (i == 2 && j == 1)){ + //logically follows + Assert.assertNull(RULE.checkRuleAt(transition, c)); + } + else { + //does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + } + + @Test + public void FinishEmptyTestWithThree() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithThree", lightUp); + TreeNode rootNode = lightUp.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + //get board state + LightUpBoard board = (LightUpBoard) transition.getBoard(); + // The board has a "3" clue at (1,1) with a bulbs at (0,1), (2,1), and (1,2) + + //change the board's cells considering the FinishWithBulbs rule to empty + LightUpCell cell1 = board.getCell(1,0); + cell1.setData(LightUpCellType.EMPTY.value); + board.addModifiedData(cell1); + + //confirm there is a logical following of the FinishWithBulbs rule + Assert.assertNull(RULE.checkRule(transition)); + + //check every square for logical following + LightUpCell c; + for (int i = 0; i < board.getHeight(); i++) { + for (int j = 0; j < board.getWidth(); j++) { + c = board.getCell(j, i); + if (i == 0 && j == 1){ + //logically follows + Assert.assertNull(RULE.checkRuleAt(transition, c)); + } + else { + //does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + } +} diff --git a/src/test/resources/puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithThree b/src/test/resources/puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithThree index c5ad17cba..2e2712a50 100644 --- a/src/test/resources/puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithThree +++ b/src/test/resources/puzzles/lightup/rules/FinishWithEmptyDirectRule/FinishWithEmptyWithThree @@ -3,9 +3,9 @@ - +