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.
- Loading branch information
Showing
9 changed files
with
291 additions
and
9 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
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,70 @@ | ||
package duck; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class ParserTest { | ||
@Test | ||
public void parse_unknownCommand_exceptionThrown() { | ||
try { | ||
Parser.parse("foo bar baz"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Im sorry, I don't know what that means.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_markInvalidIndex_exceptionThrown() { | ||
try { | ||
Parser.parse("mark abc"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Please enter a valid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_unmarkInvalidIndex_exceptionThrown() { | ||
try { | ||
Parser.parse("unmark abc"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Please enter a valid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deleteInvalidIndex_exceptionThrown() { | ||
try { | ||
Parser.parse("delete abc"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Please enter a valid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deadlineInvalidDateFormat_exceptionThrown() { | ||
// Invalid date format | ||
try { | ||
Parser.parse("deadline abc /by 01-09-2023"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Please follow the dd/mm/yyyy format.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_eventInvalidDateFormat_exceptionThrown() { | ||
// Invalid date format | ||
try { | ||
Parser.parse("event abc /from 01-09-2023 /to 01-10-2023"); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Please follow the dd/mm/yyyy format.", e.getMessage()); | ||
} | ||
} | ||
} |
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,40 @@ | ||
package duck.task; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class DeadlineTaskTest { | ||
@Test | ||
public void stringify_success() { | ||
DeadlineTask task = new DeadlineTask("return book", false, LocalDate.parse("2023-09-01")); | ||
assertEquals("D011/return book11/Sep 01 2023", task.stringify()); | ||
|
||
task = new DeadlineTask("submit application", true, LocalDate.parse("2023-10-01")); | ||
assertEquals("D118/submit application11/Oct 01 2023", task.stringify()); | ||
} | ||
|
||
@Test | ||
public void parse_success() { | ||
try { | ||
DeadlineTask task = new DeadlineTask("return book", false, LocalDate.parse("2023-09-01")); | ||
String taskString = task.stringify(); | ||
Task parsedTask = DeadlineTask.parse(taskString); | ||
assertEquals(task, parsedTask); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
DeadlineTask task = new DeadlineTask("return book", false, LocalDate.parse("2023-09-01")); | ||
assertEquals("[D][ ] return book (by: Sep 01 2023)", task.toString()); | ||
|
||
task = new DeadlineTask("submit application", true, LocalDate.parse("2023-10-01")); | ||
assertEquals("[D][X] submit application (by: Oct 01 2023)", task.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,40 @@ | ||
package duck.task; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.time.LocalDate; | ||
|
||
public class EventTaskTest { | ||
@Test | ||
public void stringify_success() { | ||
EventTask task = new EventTask("career fair", false, LocalDate.parse("2023-08-29"), LocalDate.parse("2023-08-30")); | ||
assertEquals("E011/career fair11/Aug 29 202311/Aug 30 2023", task.stringify()); | ||
|
||
task = new EventTask("TI 23", true, LocalDate.parse("2023-10-12"), LocalDate.parse("2023-10-29")); | ||
assertEquals("E15/TI 2311/Oct 12 202311/Oct 29 2023", task.stringify()); | ||
} | ||
|
||
@Test | ||
public void parse_success() { | ||
try { | ||
EventTask task = new EventTask("career fair", false, LocalDate.parse("2023-08-29"), LocalDate.parse("2023-08-30")); | ||
String taskString = task.stringify(); | ||
Task parsedTask = EventTask.parse(taskString); | ||
assertEquals(task, parsedTask); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
EventTask task = new EventTask("career fair", false, LocalDate.parse("2023-08-29"), LocalDate.parse("2023-08-30")); | ||
assertEquals("[E][ ] career fair (from: Aug 29 2023 to Aug 30 2023)", task.toString()); | ||
|
||
task = new EventTask("TI 23", true, LocalDate.parse("2023-10-12"), LocalDate.parse("2023-10-29")); | ||
assertEquals("[E][X] TI 23 (from: Oct 12 2023 to Oct 29 2023)", task.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,65 @@ | ||
package duck.task; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TaskListTest { | ||
|
||
@Test | ||
public void add_validTask_success() { | ||
TaskList taskList = new TaskList(); | ||
assertEquals(0, taskList.getTaskCount()); | ||
|
||
taskList.add(new TodoTask("test", false)); | ||
assertEquals(1, taskList.getTaskCount()); | ||
|
||
taskList.add(new TodoTask("test", false)); | ||
assertEquals(2, taskList.getTaskCount()); | ||
} | ||
|
||
@Test | ||
public void getTask_invalidIndex_exceptionThrown() { | ||
TaskList taskList = new TaskList(); | ||
try { | ||
taskList.getTask(1); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Error - invalid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void mark_invalidIndex_exceptionThrown() { | ||
TaskList taskList = new TaskList(); | ||
try { | ||
taskList.mark(1); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Error - invalid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void unmark_invalidIndex_exceptionThrown() { | ||
TaskList taskList = new TaskList(); | ||
try { | ||
taskList.mark(1); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Error - invalid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void delete_invalidIndex_exceptionThrown() { | ||
TaskList taskList = new TaskList(); | ||
try { | ||
taskList.delete(1); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Error - invalid task number.", e.getMessage()); | ||
} | ||
} | ||
} |
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,38 @@ | ||
package duck.task; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TodoTaskTest { | ||
@Test | ||
public void stringify_success() { | ||
TodoTask task = new TodoTask("do laundry", false); | ||
assertEquals("T010/do laundry", task.stringify()); | ||
|
||
task = new TodoTask("finish homework", true); | ||
assertEquals("T115/finish homework", task.stringify()); | ||
} | ||
|
||
@Test | ||
public void parse_success() { | ||
try { | ||
TodoTask task = new TodoTask("do laundry", false); | ||
String taskString = task.stringify(); | ||
Task parsedTask = TodoTask.parse(taskString); | ||
assertEquals(task, parsedTask); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
TodoTask task = new TodoTask("do laundry", false); | ||
assertEquals("[T][ ] do laundry", task.toString()); | ||
|
||
task = new TodoTask("finish homework", true); | ||
assertEquals("[T][X] finish homework", task.toString()); | ||
} | ||
} |