diff --git a/src/main/java/awex/Storage.java b/src/main/java/awex/Storage.java index 129b5cbe73..1f85eac258 100644 --- a/src/main/java/awex/Storage.java +++ b/src/main/java/awex/Storage.java @@ -18,6 +18,7 @@ public File load() throws IOException { public void store(TaskList t) throws IOException { FileWriter fw = new FileWriter(this.filepath); int len = t.size(); + assert len >= 0; String str = ""; for (int i = 0; i < len; i++) { str += t.get(i).toString() + "\n"; diff --git a/src/main/java/awex/TaskList.java b/src/main/java/awex/TaskList.java index 5ce561c7ae..ed8d0b8c22 100644 --- a/src/main/java/awex/TaskList.java +++ b/src/main/java/awex/TaskList.java @@ -42,6 +42,7 @@ public void add(Task t) { public LinkedList find(String str) { LinkedList list = new LinkedList<>(); int len = this.tasks.size(); + assert len >= 0; for (int i = 0; i < len; i++) { Task t = this.tasks.get(i); if (t.isPartOfDesc(str)) { diff --git a/src/main/java/awex/Ui.java b/src/main/java/awex/Ui.java index fc7759256d..8b359f555d 100644 --- a/src/main/java/awex/Ui.java +++ b/src/main/java/awex/Ui.java @@ -54,6 +54,7 @@ public String emptyListMessage() { public String showListMessage(TaskList list) { String str = "Here are the tasks in your list:\n"; int len = list.size(); + assert len >= 0; for (int i = 1; i <= len; i++) { str += i + "." + list.get(i - 1).showAll() + "\n"; } @@ -70,6 +71,7 @@ public String showFindMessage(TaskList tasks, String str) { String stri = "Here are the matching tasks in your list:\n"; LinkedList list = tasks.find(str); int len = list.size(); + assert len >= 0; for (int i = 1; i <= len; i++) { stri += i + "." + list.get(i - 1).showAll() + "\n"; } @@ -87,6 +89,7 @@ public String wrongMarkDeleteFormatMessage(String str) { * Prints explainer message when user provides inaccessible list index. */ public String wrongIndexMessage(int i, int len) { + assert len >= 0; if (i == 0) { return "Pick a value between 1 and " + len + "."; } else { diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index 9c3b46c0a8..f2d1247c8a 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -16,6 +16,7 @@ public class Task { public Task(String what, String status, String type) { this.what = what; this.type = type; + assert status.equals("t") || status.equals("f"); if (status.equals("t")) { this.status = "[X]"; } else { @@ -38,9 +39,10 @@ public String showAll() { * @param status completion status of task */ public void changeStatus(String status) { + assert status.equals("mark") || status.equals("unmark"); if (status.equals("mark")) { this.status = "[X]"; - } else if (status.equals("unmark")) { + } else { this.status = "[ ]"; } }