From d4b851d200e7db562059d9c2877ad800e2ca2dda Mon Sep 17 00:00:00 2001 From: gachia Date: Thu, 12 Sep 2019 22:12:34 +0800 Subject: [PATCH] Added Assertion Added assertion checks in setDone and delete functions of Tasklist. Enabled assertions in gradle build --- build.gradle | 3 ++- src/main/java/TaskList.java | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 163d48c5c1..d6e2cf5d7a 100644 --- a/build.gradle +++ b/build.gradle @@ -39,9 +39,10 @@ test { run { standardInput = System.in; + enableAssertions = true; } application { // Change this to your main class. - mainClassName = "GUI" + mainClassName = "Gui" } diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java index 80bd17e873..e4ae364aad 100644 --- a/src/main/java/TaskList.java +++ b/src/main/java/TaskList.java @@ -43,6 +43,7 @@ public String addTask(Task task) { * @return confirmation message of task being deleted */ public String deleteTask(int deleteIndex) { + assert deleteIndex < list.size() : "deleteIndex should not be larger than amount of tasks in list"; Task temp = list.remove(deleteIndex - 1); String message = "Noted. I've removed this task:\n" + temp + "\nNow you have " + list.size() + " tasks in the list."; @@ -97,6 +98,11 @@ public String searchTaskList(String searchTerm) { * @return confirmation message of task being done */ public String setDoneTask(int doneIndex) { + /* + // Code for testing assertion + doneIndex = 20; + */ + assert doneIndex < list.size() : "doneIndex should not be larger than amount of tasks in list"; list.get(doneIndex - 1).markAsDone(); String message = "Nice! I've marked this task as done:\n" + list.get(doneIndex - 1);