Skip to content

Commit

Permalink
Merge pull request #2 from ChangruHenryQian/branch-A-Assertions
Browse files Browse the repository at this point in the history
Implement assertions
  • Loading branch information
ChangruHenryQian authored Sep 15, 2023
2 parents e20422e + f1c1337 commit ed26f34
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ shadowJar {

run{
standardInput = System.in

enableAssertions = true
}

mainClassName = "duke.Launcher"
2 changes: 0 additions & 2 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
T | 1 | daf
T | 1 | 2rd
1 change: 1 addition & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private File getFile(String path) throws IOException {
* @throws FileNotFoundException If an attempt to open the file fails.
*/
private ArrayList<Task> loadTasks(File f) throws FileNotFoundException {
assert f.exists();
Scanner s = new Scanner(f);
ArrayList<Task> tasks = new ArrayList<>();
while (s.hasNext()) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ public class Task {
* @param description Description of the task.
*/
public Task(String description) {
assert !description.isEmpty();

this.description = description;
this.isDone = false;
}

public Task(String description, boolean isDone) {
assert !description.isEmpty();

this.description = description;
this.isDone = isDone;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public String addTask(Task t) {
* @return The message for deleting.
*/
public String deleteTask(int num) {
assert num >= 0;

Task re = tasks.remove(num);
this.storage.rewriteFile(tasks);
return Ui.deleteTask(re, tasks);
Expand All @@ -59,6 +61,8 @@ public String deleteTask(int num) {
* @return The message for marking.
*/
public String markTask(int num) {
assert num >= 0;

Task t = tasks.get(num);
t.markAsDone();
this.storage.rewriteFile(tasks);
Expand All @@ -72,6 +76,8 @@ public String markTask(int num) {
* @return The message for searching results.
*/
public String findTask(String keyword) {
assert keyword != null;

ArrayList<Task> result = new ArrayList<>();
for (int i = 0; i < this.tasks.size(); i++) {
if (!tasks.get(i).toString().contains(keyword)) {
Expand Down

0 comments on commit ed26f34

Please sign in to comment.