Skip to content

Commit

Permalink
Enable assertions to TaskList to catch potential bugs
Browse files Browse the repository at this point in the history
Currently, the `TaskList` class methods lack assertions, which means potential bugs could go undetected during runtime, leading to unexpected behaviors and potential data corruption.

The lack of assertions makes the system vulnerable to subtle bugs that can be difficult to detect and diagnose.

Using assertions to catch potential bugs is a proactive approach to software development.
  • Loading branch information
ncduy0303 committed Sep 14, 2023
1 parent 1e5f512 commit 694a4b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ shadowJar {

run {
standardInput = System.in
enableAssertions = true
}
4 changes: 4 additions & 0 deletions src/main/java/alice/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public String getDescription() {
return this.description;
}

public boolean getIsDone() {
return this.isDone;
}

/**
* Marks the task as done.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/alice/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public List<Task> getTasks() {
*/
public void add(Task task) {
this.tasks.add(task);
assert this.tasks.contains(task) : "Task should be added to the list";
}

/**
Expand All @@ -99,7 +100,9 @@ public void delete(int index) {
* @param index The index of the task to be marked as done.
*/
public void markAsDone(int index) {

this.tasks.get(index).markAsDone();
assert this.tasks.get(index).getIsDone() : "Task should be marked as done";
}

/**
Expand All @@ -109,6 +112,7 @@ public void markAsDone(int index) {
*/
public void unmarkAsDone(int index) {
this.tasks.get(index).unmarkAsDone();
assert !this.tasks.get(index).getIsDone() : "Task should be marked as not done";
}

/**
Expand Down

0 comments on commit 694a4b4

Please sign in to comment.