Skip to content

Commit

Permalink
Merge pull request #562 from Bram-Hub/file-path
Browse files Browse the repository at this point in the history
Save File Path
  • Loading branch information
Bram28 authored Jun 23, 2023
2 parents 0ca6926 + c8cbc44 commit f6418b6
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/main/java/edu/rpi/legup/app/LegupPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class LegupPreferences {

private static LegupPreferences instance;

private static String SAVED_PATH = "";

private static final Preferences preferences = Preferences.userNodeForPackage(LegupPreferences.class);

private static final Map<String, String> preferencesMap = new HashMap<>();
Expand Down Expand Up @@ -104,4 +106,13 @@ public boolean getUserPrefAsBool(String key) {
}
}
}


public String getSavedPath() {
return SAVED_PATH;
}

public void setSavedPath(String path) {
SAVED_PATH = path;
}
}
7 changes: 6 additions & 1 deletion src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ public Object[] promptPuzzle() {

LegupPreferences preferences = LegupPreferences.getInstance();
String preferredDirectory = preferences.getUserPref(LegupPreferences.WORK_DIRECTORY);
if (preferences.getSavedPath() != "") {
preferredDirectory = preferences.getSavedPath();
}

File preferredDirectoryFile = new File(preferredDirectory);
JFileChooser fileBrowser = new JFileChooser(preferredDirectoryFile);
Expand All @@ -388,7 +391,7 @@ public Object[] promptPuzzle() {

fileBrowser.showOpenDialog(this);
fileBrowser.setVisible(true);
fileBrowser.setCurrentDirectory(new File(LegupPreferences.WORK_DIRECTORY));
fileBrowser.setCurrentDirectory(new File(preferredDirectory));
fileBrowser.setDialogTitle("Select Proof File");
fileBrowser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileBrowser.setAcceptAllFileFilterUsed(false);
Expand All @@ -398,6 +401,8 @@ public Object[] promptPuzzle() {

if (puzzlePath != null) {
fileName = puzzlePath.getAbsolutePath();
String lastDirectoryPath = fileName.substring(0, fileName.lastIndexOf(File.separator));
preferences.setSavedPath(lastDirectoryPath);
puzzleFile = puzzlePath;
}
else {
Expand Down
108 changes: 108 additions & 0 deletions src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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.*;

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();
}


}
9 changes: 9 additions & 0 deletions src/test/java/legup/TestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
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 {
Expand All @@ -16,4 +21,8 @@ public static void importTestBoard(String fileName, Puzzle puzzle) throws Invali
TreeTransition transition = new TreeTransition(rootNode, board);
rootNode.getChildren().add(transition);
}


}


0 comments on commit f6418b6

Please sign in to comment.