forked from nus-cs2103-AY2324S1/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.
Merge pull request #5 from TyrusLye/A-Assertions
A-Assertions
- Loading branch information
Showing
7 changed files
with
191 additions
and
4 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
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
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,72 @@ | ||
package Storage; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import URBOI_PACKIN.Storage.Storage; | ||
import URBOI_PACKIN.Task; | ||
import URBOI_PACKIN.TaskTypes.Deadline; | ||
import URBOI_PACKIN.TaskTypes.Todo; | ||
import URBOI_PACKIN.TaskTypes.Event; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class StorageTest { | ||
|
||
private static final String TEST_FILE_PATH = "test_tasks.txt"; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// Delete the test file if it exists before each test | ||
File file = new File(TEST_FILE_PATH); | ||
if (file.exists()) { | ||
file.delete(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSaveAndLoadTasks() { | ||
// Create some test tasks | ||
ArrayList<Task> tasksToSave = new ArrayList<>(); | ||
tasksToSave.add(new Todo("Test Todo Task")); | ||
tasksToSave.add(new Deadline("Test Deadline Task", LocalDateTime.now())); | ||
tasksToSave.add(new Event("Test Event Task", "2023-10-23 10:00", "2023-10-23 12:00")); | ||
|
||
// Save tasks to the test file | ||
Storage.saveTasksToFile(tasksToSave); | ||
|
||
// Load tasks from the test file | ||
ArrayList<Task> loadedTasks = new ArrayList<>(); | ||
Storage.loadTasksFromFile(loadedTasks); | ||
|
||
// Assert that the loaded tasks match the saved tasks | ||
assertEquals(tasksToSave.size(), loadedTasks.size()); | ||
for (int i = 0; i < tasksToSave.size(); i++) { | ||
assertEquals(tasksToSave.get(i).toFileString(), loadedTasks.get(i).toFileString()); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void testCreateTaskFromLine() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
String line = "T | 1 | Test Todo Task"; | ||
|
||
// Use reflection to access the private method | ||
Method createTaskFromLine = Storage.class.getDeclaredMethod("createTaskFromLine", String.class); | ||
createTaskFromLine.setAccessible(true); | ||
|
||
// Call the private method to create a task | ||
Task task = (Task) createTaskFromLine.invoke(null, line); | ||
|
||
assertTrue(task instanceof Todo); | ||
assertEquals("Test Todo Task", task.getDescription()); | ||
assertEquals(true, task.isDone()); | ||
} | ||
} |
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,39 @@ | ||
package TaskTypes; | ||
import URBOI_PACKIN.TaskTypes.Deadline; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DeadlineTest { | ||
private Deadline deadline; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// Initialize a Deadline object before each test | ||
LocalDateTime date = LocalDateTime.parse("2023-10-23T14:30", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm")); | ||
deadline = new Deadline("Sample Deadline", date); | ||
} | ||
|
||
@Test | ||
public void testDeadlineConstructor() { | ||
// Check if the Deadline constructor sets the description and date correctly | ||
assertEquals("Sample Deadline", deadline.getDescription()); | ||
//assertEquals(LocalDateTime.parse("2023-10-23T14:30", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm")), deadline.getDate()); | ||
} | ||
|
||
@Test | ||
public void testDeadlineToFileString() { | ||
// Check the toFileString method for a Deadline task | ||
assertEquals("D | 0 | Sample Deadline | 2023-10-23T14:30", deadline.toFileString()); | ||
} | ||
|
||
@Test | ||
public void testDeadlineToString() { | ||
// Check the toString method for a Deadline task | ||
assertEquals("[D][ ] Sample Deadline (by: 2023-10-23T14:30)", deadline.toString()); | ||
} | ||
} |
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,35 @@ | ||
package TaskTypes; | ||
import URBOI_PACKIN.TaskTypes.Event; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
public class EventTest { | ||
private Event event; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// Initialize an Event object before each test | ||
event = new Event("Sample Event", "2023-10-23 1400", "2023-10-23 1600"); | ||
} | ||
|
||
@Test | ||
public void testEventConstructor() { | ||
// Check if the Event constructor sets the description, from, and to correctly | ||
assertEquals("Sample Event", event.getDescription()); | ||
assertEquals("2023-10-23 1400", event.getFrom()); | ||
assertEquals("2023-10-23 1600", event.getTo()); | ||
} | ||
|
||
@Test | ||
public void testEventToFileString() { | ||
// Check the toFileString method for an Event task | ||
assertEquals("E | 0 | Sample Event | 2023-10-23 1400 | 2023-10-23 1600", event.toFileString()); | ||
} | ||
|
||
@Test | ||
public void testEventToString() { | ||
// Check the toString method for an Event task | ||
assertEquals("[E][ ] Sample Event (from: 2023-10-23 1400 to: 2023-10-23 1600)", event.toString()); | ||
} | ||
} |
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,33 @@ | ||
package TaskTypes; | ||
import URBOI_PACKIN.TaskTypes.Todo; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
public class ToDoTest { | ||
private Todo todo; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// Initialize a Todo object before each test | ||
todo = new Todo("Sample Todo"); | ||
} | ||
|
||
@Test | ||
public void testTodoConstructor() { | ||
// Check if the Todo constructor sets the description correctly | ||
assertEquals("Sample Todo", todo.getDescription()); | ||
} | ||
|
||
@Test | ||
public void testTodoToFileString() { | ||
// Check the toFileString method for a Todo task | ||
assertEquals("T | 0 | Sample Todo", todo.toFileString()); | ||
} | ||
|
||
@Test | ||
public void testTodoToString() { | ||
// Check the toString method for a Todo task | ||
assertEquals("[T][ ] Sample Todo", todo.toString()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
T | 0 | thing1 | ||
T | 1 | thing2 | ||
T | 0 | thing3 | ||
D | 0 | task | 2023-10-23T14:30 | ||
T | 0 | Test Todo Task | ||
D | 0 | Test Deadline Task | 2023-10-23T23:42:41.212928 | ||
E | 0 | Test Event Task | 2023-10-23 10:00 | 2023-10-23 12:00 |