From bcb8629d97adcd839413702045aefae473de0fed Mon Sep 17 00:00:00 2001 From: Viane Matsibekker <117249183+04vmatsibekker@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:34:47 -0400 Subject: [PATCH] Have null changes be valid and fix IsolatedBlackContradicitonRule error message (#561) * Get Tests to be called Revert "Create first cypress test template" This reverts commit 3e50909b93b5aa9634cf0d296e9aeff756b0a909. First commit Finish Lightup tests * Add more tests Update TestRunner.java * Somehow ended up in the wrong spot Fix Import * Please let this be the fix Update TreeTransition.java Update TreeTransition.java Update DirectRule.java Check to see which is not correct Update ElementController.java Revert "maybe the null is making it think that it's not valid" This reverts commit 7bf1de0d66ced6749ee37fbb9c252636b2fcdc79. Just trying to change color Revert "Just trying to change color" This reverts commit ec44695ee578d664055d135a668927a0fd900f5d. Revert "maybe the null is making it think that it's not valid" This reverts commit 3f162fbdc32e6fbd23da321a14a6af96f0ff520d. Check to see which is not correct Revert "Check to see which is not correct" This reverts commit 136b0a41b9d103e6f3e9a7f8cd5d970bf76b050b. Update TreeTransition.java Update TreeTransition.java Revert "Update TreeTransition.java" This reverts commit cde45bb9001cfbfa4f6e2a49b4e9990d2fa7ad33. * Fix error with isolated Black Fix error message with isolated black * Removed excess whitespace and imports. Added short JavaDoc for `TestRunner.java` --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> Co-authored-by: Bram van Heuveln Co-authored-by: Corppet --- .../history/ValidateContradictionRuleCommand.java | 12 ++++++++++-- .../java/edu/rpi/legup/model/rules/DirectRule.java | 14 ++++---------- src/test/java/legup/TestRunner.java | 7 ++++--- src/test/java/legup/TestUtilities.java | 9 --------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java index c5f8f0831..a0f58a571 100644 --- a/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java +++ b/src/main/java/edu/rpi/legup/history/ValidateContradictionRuleCommand.java @@ -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)); } diff --git a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java index 940bbe32f..4acc7573e 100644 --- a/src/main/java/edu/rpi/legup/model/rules/DirectRule.java +++ b/src/main/java/edu/rpi/legup/model/rules/DirectRule.java @@ -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); } } diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 7e2dbe737..9d79c590e 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -9,6 +9,9 @@ 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 @@ -103,6 +106,4 @@ private static void printTestResults(Result result) { System.out.println("All tests passed: " + result.wasSuccessful()); System.out.println(); } - - -} \ No newline at end of file +} diff --git a/src/test/java/legup/TestUtilities.java b/src/test/java/legup/TestUtilities.java index d49529921..9f203b223 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -6,11 +6,6 @@ import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.save.InvalidFileFormatException; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; -import org.junit.runner.notification.Failure; -import puzzles.battleship.rules.AdjacentShipsContradictionRuleTest; -import puzzles.battleship.rules.FinishWithShipsDirectRuleTests; public final class TestUtilities { public static void importTestBoard(String fileName, Puzzle puzzle) throws InvalidFileFormatException { @@ -21,8 +16,4 @@ public static void importTestBoard(String fileName, Puzzle puzzle) throws Invali TreeTransition transition = new TreeTransition(rootNode, board); rootNode.getChildren().add(transition); } - - } - -