Skip to content

Commit

Permalink
Add JUnit tests for Storage.java, TaskList.java
Browse files Browse the repository at this point in the history
  • Loading branch information
pwjj2000 committed Aug 27, 2022
1 parent 629f3a0 commit 8013dee
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/java/duke/StorageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duke;

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

import java.io.IOException;

import org.junit.jupiter.api.Test;

public class StorageTest {
@Test
public void loadTest() throws DukeException, IOException {
Storage storage = new Storage("data/tasks.txt");
TaskList tasks = new TaskList(storage.load());
int expectedSize = 3;
int actualSize = tasks.getTaskArrayList().size();
assertEquals(expectedSize, actualSize);
}
}
73 changes: 73 additions & 0 deletions src/test/java/duke/TaskListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package duke;

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

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.Todo;

public class TaskListTest {

@Test
public void addTest() throws DukeException {
TaskList tasks = new TaskList();
ArrayList<Task> list = tasks.getTaskArrayList();

int actualSizeZero = list.size();

assertEquals(0 , actualSizeZero);

Todo t = new Todo("go home");
Deadline d = new Deadline("cs homework", "2022-10-19");
Event e = new Event("", "2022-10-13");

tasks.add(t);
int actualSizeOne = list.size();
tasks.add(d);
int actualSizeTwo = list.size();
tasks.add(e);
int actualSizeThree = list.size();

assertEquals(1 , actualSizeOne);
assertEquals(2 , actualSizeTwo);
assertEquals(3 , actualSizeThree);

Task t1 = list.get(0);
Task t2 = list.get(1);
Task t3 = list.get(2);

assertEquals(t, t1);
assertEquals(d, t2);
assertEquals(e, t3);
}

@Test
public void deleteTest() throws DukeException {
TaskList tasks = new TaskList();
ArrayList<Task> list = tasks.getTaskArrayList();

Todo t = new Todo("go home");
Deadline d = new Deadline("cs homework", "2022-10-19");
Event e = new Event("", "2022-10-13");

tasks.add(t);
tasks.add(d);
tasks.add(e);

int actualSizeInitial = list.size();
assertEquals(3, actualSizeInitial);

tasks.delete(2); // Delete Deadline
int actualSizeEnd = list.size();
assertEquals(2, actualSizeEnd);
Task t1 = list.get(0);
Task t2 = list.get(1);
assertEquals(t, t1);
assertEquals(e, t2);
}
}

0 comments on commit 8013dee

Please sign in to comment.