Skip to content

Commit 425a2a8

Browse files
authored
Merge pull request #87 from CS2103AUG2016-W13-C4/history-tests
History tests
2 parents bf9a076 + f2ccf16 commit 425a2a8

File tree

20 files changed

+576
-259
lines changed

20 files changed

+576
-259
lines changed

src/main/java/seedu/address/commons/util/StringUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,18 @@
99
* Helper functions for handling strings.
1010
*/
1111
public class StringUtil {
12+
13+
/**
14+
* Returns true if query is a valid substring of source (beginning at the first character of source)
15+
* Will return false if either source or query is null
16+
* Will also return false if the substring of query found in source is different capitalization
17+
*
18+
* @param source the base/source string to check on
19+
* @param query the query string that you want to check if is substring and begins in source
20+
* @return
21+
*/
1222
public static boolean isSubstringFromStart(String source, String query) {
13-
return source.indexOf(query) == 0;
23+
return source != null & query != null && source.indexOf(query) == 0;
1424
}
1525

1626
public static boolean containsIgnoreCase(String source, String query) {

src/main/java/seedu/address/history/History.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* Stores the history of undoable and redoable commands for UndoCommand to use.
9-
*
9+
* Also stores the history of user inputs for navigating previous and next user inputs using up and down arrow keys.
1010
*/
1111
public class History implements UndoableCommandHistory, InputHistory{
1212

@@ -122,12 +122,7 @@ public String pushNextInput(String input){
122122
assert nextCommands != null;
123123
return nextCommands.push(input);
124124
}
125-
126-
public void updateCurrentShownInput(String input){
127-
assert input != null;
128-
this.currentStoredCommandShown = input;
129-
}
130-
125+
131126
public String getStoredCurrentShownInput(){
132127
return currentStoredCommandShown;
133128
}

src/main/java/seedu/address/history/InputHistory.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22

33
public interface InputHistory {
44

5+
/** Updates the user input history and resets the current state to be the latest input with the given userInput String **/
56
public void updateInputHistory(String userInput);
67

8+
/** Returns whether we are already at the earliest input state (no more previous input in memory to backtrack to) **/
79
public boolean isEarliestInput();
810

11+
/** Returns whether we are already at the latest input state (no more later input in memory to move forward to) **/
912
public boolean isLatestInput();
1013

14+
/** Returns the immediate previous input stored in memory and no longer keep in memory **/
1115
public String popPrevInput();
1216

17+
/** Stores the given input string in memory as the immediate 'previous' input from the current state **/
1318
public String pushPrevInput(String input);
1419

20+
/**
21+
* Returns the immediate next input (that was previously stored when we try to get previous) stored in memory
22+
* and no longer keep it in memory
23+
*/
1524
public String popNextInput();
1625

26+
/** Stores the given input string in memory as the immediate 'next' input from the current state **/
1727
public String pushNextInput(String input);
1828

19-
public void updateCurrentShownInput(String input);
20-
29+
/** Returns the current shown input string that is to be displayed to the user **/
2130
public String getStoredCurrentShownInput();
2231
}

src/main/java/seedu/address/history/UndoableCommandHistory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
public interface UndoableCommandHistory {
66

7+
/** Updates the command history with the given UndoableCommand **/
78
public void updateCommandHistory(UndoableCommand undoableCommand);
89

10+
/** Returns whether we are already at the earliest command state (there is nothing to undo anymore) **/
911
public boolean isEarliestCommand();
1012

13+
/** Returns whether we are already at the latest command state (there is nothing to redo anymore) **/
1114
public boolean isLatestCommand();
1215

16+
/** Executes an undo step on the command history, returning the UndoableCommand that was undone **/
1317
public UndoableCommand undoStep();
1418

19+
/** Executes a redo step on the command history, returning the UndoableCommand that was redone **/
1520
public UndoableCommand redoStep();
1621

22+
/** Resets the history of undos (the past undos that can be redone) **/
1723
public void resetRedo();
1824
}

src/main/java/seedu/address/logic/Logic.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public interface Logic {
2121
/** Returns the filtered list of done tasks **/
2222
ObservableList<ReadOnlyTask> getFilteredDoneTaskList();
2323

24-
String decideToolTip(String commandText);
24+
/** Generates the tool tip for the current user input **/
25+
String generateToolTip(String commandText);
2526

2627
}

src/main/java/seedu/address/logic/LogicManager.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ public ObservableList<ReadOnlyTask> getFilteredDoneTaskList() {
5353
return model.getFilteredDoneTaskList();
5454
}
5555

56+
/**
57+
* Generates the tool tip for the current user input.
58+
*
59+
* @param commandText the user input string
60+
* @return the tooltip that fits the user input string
61+
*/
5662
@Override
57-
public String decideToolTip(String commandText){
63+
public String generateToolTip(String commandText){
64+
assert commandText != null;
65+
5866
//logger.info("----------------[INCOMPLETE USER COMMAND][" + commandText + "]");
5967
List<String> toolTips = parser.parseIncompleteCommand(commandText);
6068

61-
// toolTips should at least have 1 item
62-
assert toolTips.size() > 0;
69+
// toolTips should have at least one string in it
70+
// as there is a default case (add command)
71+
assert toolTips != null && toolTips.size() > 0;
6372

6473
// check if invalid command format
6574
if (toolTips.contains(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE))){
@@ -82,5 +91,6 @@ public String decideToolTip(String commandText){
8291

8392
// return the tooltip as a single string separated by \n
8493
return stringBuilder.toString();
94+
8595
}
8696
}

src/main/java/seedu/address/logic/commands/AddCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class AddCommand extends UndoableCommand {
3232

3333
public static final String MESSAGE_SUCCESS = "New item added: %1$s";
3434

35-
public static final String TOOL_TIP = "[add] NAME, [start DATE_TIME] [end DATE_TIME] [repeat every RECURRING_INTERVAL] [-PRIORITY]";
35+
public static final String TOOL_TIP = "[add] NAME [start DATE_TIME] [end DATE_TIME] [repeat every RECURRING_INTERVAL] [-PRIORITY]";
3636

3737
public static final String MESSAGE_UNDO_SUCCESS = "Undid add item: %1$s";
3838

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package seedu.address.logic.commands;
22

3-
import java.util.ArrayList;
4-
import java.util.Date;
5-
import java.util.List;
6-
import java.util.Optional;
7-
8-
import seedu.address.model.item.Name;
9-
import seedu.address.model.item.Priority;
10-
import seedu.address.model.item.ReadOnlyTask;
11-
import seedu.address.model.item.RecurrenceRate;
12-
import seedu.address.model.item.Task;
13-
143
/**
154
* Selects a person identified using it's last displayed index from the address book.
165
*/
@@ -41,116 +30,7 @@ public CommandResult execute() {
4130
UndoableCommand cmdToRedo = history.redoStep();
4231
return cmdToRedo.execute();
4332

44-
/*
45-
ReversibleEffect reversibleEffect = history.redoStep();
46-
String commandName = reversibleEffect.getCommandName();
47-
List<Task> tasksAffected = reversibleEffect.getTasksAffected();
48-
List<ReadOnlyTask> readOnlyTasksAffected = convertTaskListToReadOnlyTaskList(tasksAffected);
49-
50-
assert tasksAffected.size() > 0 && readOnlyTasksAffected.size() > 0;
51-
Task firstAffectedTask = getFirstTaskInList(tasksAffected);
52-
53-
switch(commandName){
54-
case "add":
55-
model.addTask(firstAffectedTask);
56-
return new CommandResult("Redid last undo command:\n\t" + commandName + " " + firstAffectedTask);
57-
58-
case "delete":
59-
model.deleteTasks(readOnlyTasksAffected);
60-
// TODO: inform user if task is not found and so not deleted if necessary, exception somewhere..
61-
return new CommandResult("Redid last undo command:\n\t" + commandName + " " + firstAffectedTask);
62-
63-
64-
case "edit":
65-
assert tasksAffected.size() == 2;
66-
67-
// this is the updated task before edit
68-
Task prevStateOfEditedTask = getSecondTaskInList(tasksAffected);
69-
70-
// keep a deep copy for printing since the task will be changed
71-
Task copyOfEditedTask = new Task(prevStateOfEditedTask);
72-
73-
Task editedTaskToRevert = firstAffectedTask;
74-
75-
redoEditCommand(prevStateOfEditedTask, editedTaskToRevert);
76-
return new CommandResult("Redid last command:\n\t" + commandName + " " + copyOfEditedTask + " reverted back to " + prevStateOfEditedTask);
77-
78-
case "clear":
79-
model.deleteTasks(readOnlyTasksAffected);
80-
return new CommandResult("Redid last command:\n\t" + commandName);
81-
82-
83-
case "done":
84-
model.addDoneTasks(tasksAffected);
85-
model.deleteTasks(readOnlyTasksAffected);
86-
return new CommandResult("Undid last command:\n\t" + commandName);
87-
88-
default:
89-
return new CommandResult("Nothing to redo.");
90-
}
91-
*/
92-
93-
}
94-
95-
private void redoEditCommand(Task prevStateOfEditedTask, Task editedTaskToRevert) {
96-
// temporary method of undoing edit by editing back all fields
97-
// until there is a single unified edit method
98-
99-
Name oldTaskName = prevStateOfEditedTask.getName();
100-
Optional<Date> oldStartDate = prevStateOfEditedTask.getStartDate();
101-
Optional<Date> oldEndDate = prevStateOfEditedTask.getEndDate();
102-
Priority oldPriority = prevStateOfEditedTask.getPriorityValue();
103-
Optional<RecurrenceRate> oldReccurence = prevStateOfEditedTask.getRecurrenceRate();
104-
105-
Task taskInListToRevert = model.getTaskManager().getUniqueUndoneTaskList().getTask(editedTaskToRevert);
106-
107-
model.editName(taskInListToRevert, oldTaskName);
108-
109-
model.editPriority(taskInListToRevert, oldPriority);
110-
111-
// edit back the start date
112-
if (oldStartDate.isPresent()){
113-
model.editStartDate(taskInListToRevert, oldStartDate.get());
114-
}
115-
else {
116-
model.editStartDate(taskInListToRevert, null);
117-
}
118-
119-
// edit back the end date
120-
if (oldEndDate.isPresent()){
121-
model.editEndDate(taskInListToRevert, oldEndDate.get());
122-
}
123-
else {
124-
model.editEndDate(taskInListToRevert, null);
125-
}
126-
127-
// edit back the recurrence rate
128-
if (oldReccurence.isPresent()){
129-
model.editRecurrence(taskInListToRevert, oldReccurence.get());
130-
}
131-
else{
132-
model.editRecurrence(taskInListToRevert, null);
133-
}
134-
135-
136-
}
137-
138-
private List<ReadOnlyTask> convertTaskListToReadOnlyTaskList(List<Task> tasks){
139-
List<ReadOnlyTask> readOnlyTaskList = new ArrayList<ReadOnlyTask>();
140-
for (Task task: tasks){
141-
readOnlyTaskList.add(task);
142-
}
143-
return readOnlyTaskList;
144-
}
145-
146-
private Task getFirstTaskInList(List<Task> tasks){
147-
assert tasks.size() >= 1;
148-
return tasks.get(0);
149-
}
150-
151-
private Task getSecondTaskInList(List<Task> tasks){
152-
assert tasks.size() >= 2;
153-
return tasks.get(1);
15433
}
15534

35+
15636
}
Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package seedu.address.logic.commands;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
6-
import seedu.address.model.item.ReadOnlyTask;
7-
import seedu.address.model.item.Task;
83

94
/**
105
* Selects a person identified using it's last displayed index from the address book.
@@ -35,81 +30,7 @@ public CommandResult execute() {
3530
// Undo is now OCP friendly :-)
3631
UndoableCommand cmdToUndo = history.undoStep();
3732
return cmdToUndo.undo();
38-
39-
40-
/*
41-
ReversibleEffect reversibleEffect = history.undoStep();
42-
String commandName = reversibleEffect.getCommandName();
43-
List<Task> tasksAffected = reversibleEffect.getTasksAffected();
44-
List<ReadOnlyTask> readOnlyTasksAffected = convertTaskListToReadOnlyTaskList(tasksAffected);
45-
46-
assert tasksAffected.size() > 0 && readOnlyTasksAffected.size() > 0;
47-
Task firstAffectedTask = getFirstTaskInList(tasksAffected);
48-
49-
switch(commandName){
50-
case "add":
51-
try {
52-
model.deleteTask(firstAffectedTask);
53-
} catch (TaskNotFoundException e) {
54-
// TODO Auto-generated catch block
55-
return new CommandResult("Unable to undo last add command.");
56-
}
57-
return new CommandResult("Undid last command:\n\t" + commandName + " " + firstAffectedTask);
58-
59-
case "delete":
60-
model.addTasks(tasksAffected);
61-
return new CommandResult("Undid last command:\n\t" + commandName + " " + firstAffectedTask);
62-
63-
64-
case "edit":
65-
assert tasksAffected.size() == 2;
66-
67-
// this is the updated task
68-
Task editedTaskToRevert = getSecondTaskInList(tasksAffected);
69-
70-
// keep a deep copy for printing since the task will be changed
71-
Task copyOfEditedTask = new Task(editedTaskToRevert);
72-
73-
Task prevStateOfEditedTask = firstAffectedTask;
74-
75-
undoEditCommand(prevStateOfEditedTask, editedTaskToRevert);
76-
return new CommandResult("Undid last command:\n\t" + commandName + " " + copyOfEditedTask + " reverted back to " + prevStateOfEditedTask);
77-
78-
case "clear":
79-
model.addTasks(tasksAffected);
80-
return new CommandResult("Undid last command:\n\t" + commandName);
81-
82-
83-
case "done":
84-
model.deleteDoneTasks(readOnlyTasksAffected);
85-
model.addTasks(tasksAffected);
86-
return new CommandResult("Undid last command:\n\t" + commandName);
87-
88-
89-
default:
90-
return new CommandResult("Nothing to undo.");
91-
}
92-
*/
93-
94-
}
95-
9633

97-
private List<ReadOnlyTask> convertTaskListToReadOnlyTaskList(List<Task> tasks){
98-
List<ReadOnlyTask> readOnlyTaskList = new ArrayList<ReadOnlyTask>();
99-
for (Task task: tasks){
100-
readOnlyTaskList.add(task);
101-
}
102-
return readOnlyTaskList;
103-
}
104-
105-
private Task getFirstTaskInList(List<Task> tasks){
106-
assert tasks.size() >= 1;
107-
return tasks.get(0);
10834
}
109-
110-
private Task getSecondTaskInList(List<Task> tasks){
111-
assert tasks.size() >= 2;
112-
return tasks.get(1);
113-
}
114-
35+
11536
}

0 commit comments

Comments
 (0)