diff --git a/src/main/java/edu/rpi/legup/app/LegupPreferences.java b/src/main/java/edu/rpi/legup/app/LegupPreferences.java index f9c3791f6..578cefc5b 100644 --- a/src/main/java/edu/rpi/legup/app/LegupPreferences.java +++ b/src/main/java/edu/rpi/legup/app/LegupPreferences.java @@ -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 preferencesMap = new HashMap<>(); @@ -104,4 +106,13 @@ public boolean getUserPrefAsBool(String key) { } } } + + + public String getSavedPath() { + return SAVED_PATH; + } + + public void setSavedPath(String path) { + SAVED_PATH = path; + } } diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 86a0ca2c1..aac040bdb 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -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); @@ -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); @@ -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 { diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java new file mode 100644 index 000000000..7e2dbe737 --- /dev/null +++ b/src/test/java/legup/TestRunner.java @@ -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(); + } + + +} \ No newline at end of file diff --git a/src/test/java/legup/TestUtilities.java b/src/test/java/legup/TestUtilities.java index 9f203b223..d49529921 100644 --- a/src/test/java/legup/TestUtilities.java +++ b/src/test/java/legup/TestUtilities.java @@ -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 { @@ -16,4 +21,8 @@ public static void importTestBoard(String fileName, Puzzle puzzle) throws Invali TreeTransition transition = new TreeTransition(rootNode, board); rootNode.getChildren().add(transition); } + + } + +