8000 Add Assertions to taskList related methods by Rachelcoll · Pull Request #1 · Rachelcoll/ip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Assertions to taskList related methods #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions data/topaz.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
D | 0 | cs2103t project | 2024-08-28T19:00
E | 0 | sleep | 2024-08-28T23:00 | 2024-08-29T08:00
E | 0 | project meeting | 2024-08-28T09:03 | 2024-08-28T12:30
E | 0 | project meeting | 2024-08-28T09:03 | 9999-01-01T12:59
E | 1 | project meeting | 2024-01-01T00:00 | 9999-01-01T12:59
T | 0 | read book
E | 0 | dreaming | 2024-08-29T10:54 | 2024-09-29T10:00
T | 0 | eat lunch
T | 1 | eat dinner
D | 0 | gohome | 2024-01-01T13:00
D | 0 | iosdoai | 2024-09-11T12:00
3 changes: 3 additions & 0 deletions src/main/java/topaz/command/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ private Task addTodo(TaskList taskList) throws InvalidTaskException {
try {
String description = this.detail.substring(5);
Todo todo = new Todo(description);
int originalSize = taskList.getSize();
taskList.addTask(todo);
assert taskList.getSize() == originalSize + 1 : "Error in adding new taskList";
return todo;
} catch (IndexOutOfBoundsException e) {
throw new InvalidTaskException(Topaz.TaskType.T);
Expand All @@ -91,6 +93,7 @@ private Task addDeadline(TaskList taskList) throws InvalidTaskException {
try {
Deadline deadline = new Deadline(description, LocalDateTime.parse(by, dateTimeFormatter));
taskList.addTask(deadline);
assert taskList.find(description).getSize() > 0 : "Fail to add to taskList";
return deadline;
} catch (DateTimeParseException dateTimeParseException) {
throw new InvalidTaskException(Topaz.TaskType.D);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/topaz/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public String execute(TaskList tasks, Ui ui, Storage storage) {
return ui.showDeleteTask(task, tasks.getSize());
} catch (IOException e) {
return ui.showSaveIoeException(e);
} catch (IndexOutOfBoundsException e) {
return ui.showException(e);
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/topaz/main/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public void addTask(Task task) {
* @return The {@link Task} that was removed.
*/
public Task removeTask(int index) {
return tasks.remove(index);
Task remove = tasks.remove(index);
assert !tasks.contains(remove) : "Fail to remove the task in TaskList::removeTask";
return remove;
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/topaz/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String showMarkIobError(int index) {
return "Invalid index number: " + index + " Please refer to your list.";
}
public String showException(Exception e) {
return e + "Try agian!";
return e + "\nTry again!";
}

public String goodbye() {
Expand Down
0