Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have null changes be valid and fix IsolatedBlackContradicitonRule error message #561

Merged
merged 8 commits into from
Sep 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,17 @@ public void executeCommand() {
}
else {
TreeTransitionView transitionView = (TreeTransitionView) firstSelectedView;
finalTreeElement = transitionView.getChildView().getTreeElement();
if (transitionView.getChildView() != null) {
finalTreeElement = transitionView.getChildView().getTreeElement();
}
else {
finalTreeElement = null;
}
}

if (finalTreeElement != null) {
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
}
puzzle.notifyBoardListeners(listener -> listener.onTreeElementChanged(finalTreeElement));
puzzle.notifyTreeListeners(listener -> listener.onTreeSelectionChanged(newSelection));
}

Expand Down
14 changes: 4 additions & 10 deletions src/main/java/edu/rpi/legup/model/rules/DirectRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,12 @@ public DirectRule(String ruleID, String ruleName, String description, String ima
*/
public String checkRule(TreeTransition transition) {
Board finalBoard = transition.getBoard();

if (!finalBoard.isModified()) {
return "State must be modified";
if (transition.getParents().size() != 1 ||
transition.getParents().get(0).getChildren().size() != 1) {
return "State must have only 1 parent and 1 child";
}
else {
if (transition.getParents().size() != 1 ||
transition.getParents().get(0).getChildren().size() != 1) {
return "State must have only 1 parent and 1 child";
}
else {
return checkRuleRaw(transition);
}
return checkRuleRaw(transition);
}
}

Expand Down
109 changes: 109 additions & 0 deletions src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package legup;


import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import puzzles.battleship.rules.*;
import puzzles.lightup.rules.*;
import puzzles.nurikabe.rules.*;
import puzzles.treetent.rules.*;

/**
* This class runs all of the tests for the project without needing to run build scripts.
*/
public class TestRunner {
public static void main(String[] args) {
// Battleship Tests
Result result1 = JUnitCore.runClasses(AdjacentShipsContradictionRuleTest.class);
printTestResults(result1);
Result result2 = JUnitCore.runClasses(FinishWithShipsDirectRuleTests.class);
printTestResults(result2);

// Lightup Tests
Result result3 = JUnitCore.runClasses(BulbsInPathContradictionRuleTest.class);
printTestResults(result3);
Result result4 = JUnitCore.runClasses(CannotLightACellContradictionRuleTest.class);
printTestResults(result4);
Result result5 = JUnitCore.runClasses(EmptyCellinLightDirectRuleTest.class);
printTestResults(result5);
Result result6 = JUnitCore.runClasses(EmptyCornersDirectRuleTest.class);
printTestResults(result6);
Result result7 = JUnitCore.runClasses(FinishWithBulbsDirectRuleTest.class);
printTestResults(result7);
Result result8 = JUnitCore.runClasses(LightOrEmptyCaseRuleTest.class);
printTestResults(result8);
Result result9 = JUnitCore.runClasses(MustLightDirectRuleTest.class);
printTestResults(result9);
Result result10 = JUnitCore.runClasses(SatisfyNumberCaseRuleTest.class);
printTestResults(result10);
Result result11 = JUnitCore.runClasses(TooFewBulbsContradictionRuleTest.class);
printTestResults(result11);
Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class);
printTestResults(result12);



//nurikabe tests
Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class);
printTestResults(result13);
Result result14 = JUnitCore.runClasses(BlackBottleNeckDirectRuleTest.class);
printTestResults(result14);
Result result15 = JUnitCore.runClasses(BlackOrWhiteCaseRuleTest.class);
printTestResults(result15);
Result result16 = JUnitCore.runClasses(BlackSquareContradictionRuleTest.class);
printTestResults(result16);
Result result17 = JUnitCore.runClasses(CornerBlackDirectRuleTest.class);
printTestResults(result17);
Result result18 = JUnitCore.runClasses(FillinBlackDirectRuleTest.class);
printTestResults(result18);
Result result19 = JUnitCore.runClasses(FillinWhiteDirectRuleTest.class);
printTestResults(result19);
Result result20 = JUnitCore.runClasses(IsolateBlackContradictionRuleTest.class);
printTestResults(result20);
Result result21 = JUnitCore.runClasses(MultipleNumbersContradictionRuleTest.class);
printTestResults(result21);
Result result22 = JUnitCore.runClasses(NoNumbersContradictionRuleTest.class);
printTestResults(result22);
Result result23 = JUnitCore.runClasses(PreventBlackSquareDirectRuleTest.class);
printTestResults(result23);
Result result24 = JUnitCore.runClasses(SurroundRegionDirectRuleTest.class);
printTestResults(result24);
Result result25 = JUnitCore.runClasses(TooFewSpacesContradictionRuleTest.class);
printTestResults(result25);
Result result26 = JUnitCore.runClasses(TooManySpacesContradictionRuleTest.class);
printTestResults(result26);
Result result27 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class);
printTestResults(result27);


// Treetent
Result result28 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class);
printTestResults(result28);
Result result29 = JUnitCore.runClasses(FinishWithGrassDirectRuleTest.class);
printTestResults(result29);
Result result30 = JUnitCore.runClasses(FinishWithTentsDirectRuleTest.class);
printTestResults(result30);
Result result31 = JUnitCore.runClasses(LastCampingSpotDirectRuleTest.class);
printTestResults(result31);
Result result32 = JUnitCore.runClasses(NoTentForTreeContradictionRuleTest.class);
printTestResults(result32);
Result result33 = JUnitCore.runClasses(NoTreeForTentContradictionRuleTest.class);
printTestResults(result33);
Result result34 = JUnitCore.runClasses(SurroundTentWithGrassDirectRuleTest.class);
printTestResults(result34);
Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class);
printTestResults(result35);
}

private static void printTestResults(Result result) {
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}

System.out.println("Tests run: " + result.getRunCount());
System.out.println("Tests failed: " + result.getFailureCount());
System.out.println("All tests passed: " + result.wasSuccessful());
System.out.println();
}
}
Loading