forked from nus-cs2103-AY2223S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JUnit tests for Storage.java, TaskList.java
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |