Skip to content

Commit

Permalink
Merge pull request #164 from lmtaek/delete-assigned-tasks-update
Browse files Browse the repository at this point in the history
Parser revisions made to aid DeleteAssignedTaskCommand
  • Loading branch information
HUANGXUANKUN authored Oct 23, 2019
2 parents 99c943d + 97c2d4d commit 93b6e7a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/java/duke/core/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static Command manageCommand(String userInput) throws DukeException {
return new DeleteTaskCommand(parser.parseDeleteTask());
case "find patient":
return new FindPatientCommand((parser.parseFindPatient()));
case "find patient tasks":
return new FindPatientTaskCommand((parser.parseFindPatientTasks()));
case "find assigned tasks":
return new FindPatientTaskCommand((parser.parseFindAssignedTasks()));
case "update patient":
return new UpdatePatientCommand(parser.parseUpdatePatient());
case "update task":
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/duke/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,30 @@ public String parseDeleteTask() throws DukeException {
}

/**
* Takes user input and formats it so it is compatible with 'delete patient task' command.
* `delete patient task` output: patient_name or #patient_id, task_name or #task_id
* Takes user input and formats it so it is compatible with 'delete assigned task' command.
* `delete assigned task` output: patient_name or #patient_id, task_name or #task_id
* `delete assigned task` output: assigned_task_unique_id
*
* @return Array of strings to be used by 'delete patient task' command.
* @return Array of strings to be used by 'delete assigned task' command.
* @throws DukeException when user input cannot be parsed properly.
*/
public String[] parseDeleteAssignedTask() throws DukeException {
try {
String[] formattedInput = new String[2];
for (int i = 1; i <= formattedInput.length; i++) {
formattedInput[i - 1] = parsedInput[i].trim();

if (parsedInput[1].trim().charAt(0) == '%') {
formattedInput[0] = parsedInput[1];
return formattedInput;
} else {
for (int i = 1; i <= formattedInput.length; i++) {
formattedInput[i - 1] = parsedInput[i].trim();
}
return formattedInput;
}
return formattedInput;
} catch (Exception e) {
throw new DukeException("Please follow the `delete patient task :<patient name> or #<patient id>"
+ " :<task name> or #<task id>` format.");
throw new DukeException("Please follow the `delete assigned task :<patient name> or #<patient id>"
+ " :<task name> or #<task id>` or "
+ " `delete patient task :%<unique assigned task id>` format.");
}
}

Expand All @@ -179,7 +187,7 @@ public String[] parseUpdatePatient() throws DukeException {
return formattedInput;
} catch (Exception e) {
throw new DukeException("Please use the `update patient :<patient name> or #<patient id>"
+ "/<edited info type> :<updated info>` format.");
+ ":<edited info type> :<updated info>` format.");
}
}

Expand All @@ -198,7 +206,7 @@ public String[] parseUpdateTask() throws DukeException {
}
return formattedInput;
} catch (Exception e) {
throw new DukeException("Please use the `update patient :<task name> or #<task id>"
throw new DukeException("Please use the `update task :<task name> or #<task id>"
+ " :<updated description>` format.");
}
}
Expand All @@ -220,18 +228,18 @@ public String parseFindPatient() throws DukeException {
}

/**
* Takes the user input and formats it so it is compatible with 'find patient task' command.
* `find patient tasks` output: patient_name or #patient_id
* Takes the user input and formats it so it is compatible with 'find assigned tasks' command.
* `find assigned tasks` output: patient_name or #patient_id
*
* @return A string of formatted output to be used by 'find patient task' command.
* @return A string of formatted output to be used by 'find assigned tasks' command.
* @throws DukeException Thrown when the user input cannot be parsed in the desired manner.
*/
public String parseFindPatientTasks() throws DukeException {
public String parseFindAssignedTasks() throws DukeException {
try {
String formattedInput = parsedInput[1].trim();
return formattedInput;
} catch (Exception e) {
throw new DukeException("Please use the `find patient tasks :<patient name> or #<patient id>` format.");
throw new DukeException("Please use the `find assigned tasks :<patient name> or #<patient id>` format.");
}
}
}
15 changes: 10 additions & 5 deletions src/test/java/duke/core/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ParserTest {
String deleteTaskInputWithName = "delete task :Take medicine";
String deleteAssignedTaskInputWithID = "delete assigned task :#2 :#5";
String deleteAssignedTaskInputWithName = "delete assigned task :patient name :task name";
String deleteAssignedTaskInputWithUniqueID = "delete assigned task :%3";

@Test
public void parseAddPatientTest() throws DukeException {
Expand Down Expand Up @@ -98,26 +99,30 @@ public void parseDeleteTask() throws DukeException {
@Test
public void parseDeleteAssignedTask() throws DukeException {
Parser testParserID = new Parser(deleteAssignedTaskInputWithID);
Parser testParserName = new Parser(deleteAssignedTaskInputWithName);

String[] testOutputID = testParserID.parseDeleteAssignedTask();
String[] testOutputName = testParserName.parseDeleteAssignedTask();

String[] desiredOutputID = {"#2", "#5"};
String[] desiredOutputName = {"patient name", "task name"};

assertTrue(desiredOutputID.length == testOutputID.length);
for (int i = 0; i < desiredOutputID.length; i++) {
assertTrue(desiredOutputID[i].equals(testOutputID[i]), "Parsing failed. Expected: "
+ desiredOutputID[i] + " but got: " + testOutputID[i]);
}

Parser testParserName = new Parser(deleteAssignedTaskInputWithName);
String[] testOutputName = testParserName.parseDeleteAssignedTask();
String[] desiredOutputName = {"patient name", "task name"};
assertTrue(desiredOutputName.length == testOutputName.length);
for (int i = 0; i < desiredOutputName.length; i++) {
assertTrue(desiredOutputName[i].equals(testOutputName[i]), "Parsing failed. Expected: "
+ desiredOutputName[i] + " but got: " + testOutputName[i]);
}

Parser testParserUniqueID = new Parser(deleteAssignedTaskInputWithUniqueID);
String[] testOutputUniqueID = testParserUniqueID.parseDeleteAssignedTask();
String[] desiredOutputUniqueID = {"%3"};
assertTrue(desiredOutputUniqueID[0].equals(testOutputUniqueID[0]), "Parsing failed. Expected: "
+ desiredOutputUniqueID[0] + " but got: " + testOutputUniqueID[0]);

}

}

0 comments on commit 93b6e7a

Please sign in to comment.