Skip to content

Commit

Permalink
Duke A-JUnit: Testing behaviour of Code + Updated Printing Methods fo…
Browse files Browse the repository at this point in the history
…r Tasks
  • Loading branch information
nicljr committed Feb 2, 2023
1 parent 45f7698 commit 45d6446
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void printTasks() throws DukeException {
}
for (int i = 0; i < num_tasks; i++) {
Task ref = tasks.get(i);
System.out.println((i + 1) + "." + ref.getStatusIcon() + " " + ref.getDescription());
System.out.println((i + 1) + "." + ref.toString());
}
}
}
9 changes: 4 additions & 5 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,22 @@ public void showList(TaskList taskList) {
}

public void printMarkTask(Task markedTask) {
System.out.println("Nice! I have marked this task as Done:\n" + "[X] " +
markedTask.getDescription() + "\n");
System.out.println("Nice! I have marked this task as Done:\n" + markedTask.toString() + "\n");
}

public void printAddTask(Task to_add, Integer num_tasks) {
System.out.println("Got it fam! I've added this task:\n " + to_add.getDescription());
System.out.println("Got it fam! I've added this task:\n " + to_add.toString());
System.out.println("You currently have " + num_tasks + " tasks in this list!\n");
}

public void printUnmarkTask(Task unmarkedTask) {
System.out.println("Ok! I have marked this task as not done yet:\n" +
"[ ] " + unmarkedTask.getDescription() + "\n");
unmarkedTask.toString() + "\n");
}

public void printDeleteTask(Task removedTask, Integer num_tasks) {
System.out.println("Noted!I have deleted the task for you:\n " +
removedTask.getDescription() + "\nyou currently have " + num_tasks +
removedTask.toString() + "\nyou currently have " + num_tasks +
" tasks in this list!\n");
}
}
9 changes: 7 additions & 2 deletions src/main/java/duke/tasks/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Deadline(String description, String by) {

@Override
public String getStatusIcon() {
return "[D]" + super.getStatusIcon();
return super.getStatusIcon();
}

public String getBy() {
Expand All @@ -25,7 +25,7 @@ public String getBy() {

@Override
public String getDescription() {
return super.getDescription() + " (by: " + this.getBy() + ")";
return super.getDescription();
}

public String parseBySaving() {
Expand All @@ -36,4 +36,9 @@ public String parseBySaving() {
public String saveString() {
return String.format("D|%s|%s|%s", super.saveString(), super.description, this.parseBySaving());
}

@Override
public String toString() {
return String.format("[D]%s (by: %s)", super.toString(), this.getBy());
}
}
9 changes: 6 additions & 3 deletions src/main/java/duke/tasks/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public String getEnd() {

@Override
public String getStatusIcon() {
return "[E]" + super.getStatusIcon();
return super.getStatusIcon();
}

@Override
public String getDescription() {
return super.getDescription() + " (from: " + this.getStart() +
" to: " + this.getEnd() + ")";
return super.getDescription();
}

public String parseStartSaving() {
Expand All @@ -50,4 +49,8 @@ public String saveString() {
return String.format("E|%s|%s|%s|%s", super.saveString(), super.description,
this.parseStartSaving(), this.parseEndSaving());
}

public String toString() {
return String.format("[E]%s (from: %s to: %s)", super.toString(), this.getStart(), this.getEnd());
}
}
5 changes: 5 additions & 0 deletions src/main/java/duke/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public String saveString() {
return "0";
}
}

@Override
public String toString() {
return String.format("%s %s", this.getStatusIcon(), this.getDescription());
}
}
7 changes: 6 additions & 1 deletion src/main/java/duke/tasks/ToDos.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ public ToDos(String description) {

@Override
public String getStatusIcon() {
return "[T]" + super.getStatusIcon();
return super.getStatusIcon();
}

@Override
public String saveString() {
return String.format("T|%s|%s", super.saveString(), super.description);
}

@Override
public String toString() {
return String.format("[T]%s", super.toString());
}
}
21 changes: 21 additions & 0 deletions src/test/java/seedu/duke/DeadlineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.duke;

import duke.tasks.Deadline;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class DeadlineTest {
@Test
public void testFetchingDescription() {
Deadline deadline = new Deadline("return book", "2022-12-12 2330");
assertEquals("[D][ ] return book (by: Dec 12 2022 2330)", deadline.toString());
}

@Test
public void testMarking(){
Deadline deadline = new Deadline("return book", "2022-12-12 2330");
deadline.mark();
assertEquals("[D][X] return book (by: Dec 12 2022 2330)", deadline.toString());
}
}
22 changes: 22 additions & 0 deletions src/test/java/seedu/duke/ToDoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package seedu.duke;

import duke.tasks.ToDos;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ToDoTest {
@Test
public void testFetchingDescription() {
ToDos toDoTask = new ToDos("return book");
assertEquals("[T][ ] return book", toDoTask.toString());
}

@Test
public void testMarking(){
ToDos toDoTask = new ToDos("return book");
toDoTask.mark();
assertEquals("[T][X] return book", toDoTask.toString());
}

}

0 comments on commit 45d6446

Please sign in to comment.