Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOPPA1 committed Nov 14, 2023
2 parents ea7f8d3 + 72a88df commit 815bf5f
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ src/main/resources/docs/
*.iml
bin/

/text-ui-test/ACTUAL.TXT
/text-ui-test/EXPECTED.TXT
text-ui-test/EXPECTED-UNIX.TXT

data
4 changes: 0 additions & 4 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ private void start(String[] launchArgs) {
ui = new TextUi();
exerciseLogStorage = ExerciseLogStorage.initializeStorage(dirPath, exerciseLogFilePath);
exerciseLogStorage.checkForLogTextFile(exerciseLog);
goalStorage = GoalStorage.initializeGoalStorage(dirPath, goalFilePath);
goalStorage.restoreGoalRecord();
achmStorage = AchmStorage.initializeGoalStorage(dirPath, achmFilePath);
achmStorage.restoreGoalRecord();
ui.showWelcomeMessage(VERSION, "storage.getPath()");
} catch (Exception e) { // TODO: change to specific storage exceptions later
ui.showInitFailedMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public CommandResult execute() {
} catch (Exception e) {
feedbackToUser = "Something went wrong, please try again.";
}

return new CommandResult(feedbackToUser);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ public CommandResult execute() {

return new CommandResult(feedbackToUser);
}


}
2 changes: 0 additions & 2 deletions src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ public CommandResult execute() {

return new CommandResult(feedbackToUser);
}


}
4 changes: 0 additions & 4 deletions src/main/java/seedu/duke/commands/goal/GoalCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public CommandResult execute() {
feedbackToUser = "Something went wrong, please try again.";
}




return new CommandResult(feedbackToUser);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ public CommandResult execute() {

return new CommandResult(feedbackToUser);
}

}
12 changes: 5 additions & 7 deletions src/main/java/seedu/duke/data/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.time.format.DateTimeFormatter;
import java.util.Locale;

// import com.google.gson.annotations.SerializedName;

/**
* Customized class for showing date and parsing supported string to date.
*/
Expand All @@ -29,22 +27,22 @@ public class Date {
* @param NotAllowPast true for all goal related commands only
* @throws IncorrectFormatException if failed to parse date string input
*/
public Date(String rawData, Boolean NotAllowPast) throws IncorrectFormatException {
setRawData(rawData, NotAllowPast);
public Date(String rawData, Boolean notAllowPast) throws IncorrectFormatException {
setRawData(rawData, notAllowPast);
}

/**
* The method is used to set up the date field of a Date object
* It contains the actual implementation to parse date information from a string
* @param rawData refers to a date string
* @param NotAllowPast if past is not allowed, for example for goal functions
* @param notAllowPast if past is not allowed, for example for goal functions
* @throws IncorrectFormatException if failed to parse date string input
*/
public void setRawData(String rawData, boolean NotAllowPast) throws IncorrectFormatException {
public void setRawData(String rawData, boolean notAllowPast) throws IncorrectFormatException {
for (DateTimeFormatter formatter : formatters) {
try {
date = LocalDate.parse(rawData, formatter);
if (NotAllowPast) {
if (notAllowPast) {
if (date.isBefore(LocalDate.now())) {
throw new IncorrectFormatException("Target Deadline has passed! ");
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/seedu/duke/goal/GoalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public int getGoalCount() {
/**
* This method removes a goal object from the global field goals list by indexing
* It also decrements goalCount by 1
* @param cmd Raw user Command
* @param cmd Raw user command
* @return message of succeeding to delete goal and tell user the updated total number of goals
* @throws IOException if failed to access output file
* @throws NumberFormatException if index is invalid number
* @throws IncorrectFormatException is user command is in incorrect format
* @return message of succeeding to delete goal and tell user the updated total number of goals
*/
public static String deleteGoal(String cmd) throws IncorrectFormatException,
NumberFormatException, IOException {
Expand Down Expand Up @@ -145,10 +145,10 @@ private static void verifyAchieveGoalInput(String cmd) throws IncorrectFormatExc
* @param userCmd represents raw user input
* @param target represents to target list to add new goal
* @param storage represents the target storage to update goal data
* @return String about succeeding to create goal object
* @throws IncorrectFormatException if user input is in wrong format
* @throws NumberFormatException if the user does not input a valid number
* @throws IOException if failed to access and update output file
* @return String about succeeding to create goal object
*/
public static String addGoal(String userCmd, GoalList target, GoalStorage storage) throws IncorrectFormatException,
NumberFormatException, IOException {
Expand Down Expand Up @@ -207,5 +207,4 @@ public String toString() {
return "Consume " + this.calories + " kcal on " + this.date;
}
}

}
7 changes: 5 additions & 2 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import java.util.regex.Pattern;

import seedu.duke.commands.Command;
import seedu.duke.commands.goal.*;
import seedu.duke.commands.HelpCommand;
import seedu.duke.commands.goal.GoalCommand;
import seedu.duke.commands.goal.DeleteGoalCommand;
import seedu.duke.commands.goal.ViewGoalCommand;
import seedu.duke.commands.goal.AchievementCommand;
import seedu.duke.commands.goal.AchieveGoalCommand;
import seedu.duke.commands.IncorrectCommand;
import seedu.duke.commands.logcommands.LogCommand;
import seedu.duke.commands.logcommands.DeleteLogCommand;
Expand Down Expand Up @@ -146,5 +150,4 @@ public static class ParseException extends Exception {
super(message);
}
}

}
4 changes: 0 additions & 4 deletions src/main/java/seedu/duke/storagefile/AchmStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,4 @@ protected void textToGoalObject(String goalRecord) throws Exception {
String restoredCommand = restoreOrigionalCommand(goalRecord);
GoalList.addGoal(restoredCommand, Duke.achievedGoals, Duke.achmStorage);
}



}

1 change: 0 additions & 1 deletion src/main/java/seedu/duke/storagefile/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

class Storage {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import java.util.Optional;
import java.util.Scanner;

import seedu.duke.Duke;
import seedu.duke.commands.CommandResult;
import seedu.duke.goal.GoalList;
import seedu.duke.data.Printable;
import seedu.duke.Duke;

/**
* Text UI of the application.
Expand Down
33 changes: 18 additions & 15 deletions src/test/java/seedu/duke/parser/ParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.duke.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.duke.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -26,15 +27,8 @@ public void parse_emptyInput_returnsIncorrect() throws Exception {
parseAndAssertIncorrectWithMessage(resultMessage, emptyInputs);
}

@Test
public void parse_unknownCommandWord_returnsHelp() throws Exception {
final String input = "unknowncommandword arguments arguments";
parseAndAssertCommandType(input, HelpCommand.class);
}

/*
* Tests for 0-argument commands
* =======================================================================
* Tests for 0-argument commands =======================================================================
*/

@Test
Expand All @@ -50,21 +44,30 @@ public void parse_exitCommand_parsedCorrectly() throws Exception {
}

/*
* Utility methods
* =============================================================================
* =======
* Utility methods ====================================================================================
*/

/**
* Asserts that parsing the given inputs will return IncorrectCommand with the
* given feedback message.
*
* @throws Exception
* Asserts that parsing the given inputs will return IncorrectCommand with the given feedback message.
*/
private void parseAndAssertIncorrectWithMessage(String feedbackMessage, String... inputs) throws Exception {
for (String input : inputs) {
final IncorrectCommand result = parseAndAssertCommandType(input, IncorrectCommand.class);
assertEquals(result.feedbackToUser, feedbackMessage);
}
}

/**
* Parses input and asserts the class/type of the returned command object.
*
* @param input to be parsed
* @param expectedCommandClass expected class of returned command
* @return the parsed command object
*/
private <T extends Command> T parseAndAssertCommandType(String input, Class<T> expectedCommandClass)
throws Exception {
final Command result = parser.parseCommand(input);
assertTrue(result.getClass().isAssignableFrom(expectedCommandClass));
return (T) result;
}
}
13 changes: 0 additions & 13 deletions text-ui-test/EXPECTED.TXT

This file was deleted.

0 comments on commit 815bf5f

Please sign in to comment.