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
6 changed files
with
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package duke; | ||
|
||
import duke.tasks.Deadline; | ||
import duke.tasks.Task; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DeadlineTest { | ||
|
||
@Test | ||
public void testToString() { | ||
Task task = new Deadline(LocalDate.of(2023, 6, 23), "abc"); | ||
assertEquals("[D][ ] abc (by: 2023-06-23)", task.toString()); | ||
} | ||
|
||
@Test | ||
public void testTaskToString() { | ||
Task task = new Deadline(LocalDate.of(2023, 6, 23), "abc"); | ||
assertEquals("D | 0 | abc | 2023-06-23", task.tasktoString()); | ||
} | ||
|
||
@Test | ||
public void testMarkAsDone() { | ||
Task task = new Deadline(LocalDate.of(2023, 6, 23), "abc"); | ||
task.markAsDone(); | ||
assertEquals("D | 1 | abc | 2023-06-23", task.tasktoString()); | ||
} | ||
|
||
@Test | ||
public void testUnMark() { | ||
Task task = new Deadline(LocalDate.of(2023, 6, 23), "abc"); | ||
task.markAsDone(); | ||
task.unMark(); | ||
assertEquals("D | 0 | abc | 2023-06-23", task.tasktoString()); | ||
} | ||
} |
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,149 @@ | ||
package duke; | ||
|
||
import duke.tasks.Deadline; | ||
import duke.tasks.Event; | ||
import duke.tasks.Todo; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class ParserTest { | ||
@Test | ||
public void decideCommand_invalidInput_invalid() { | ||
assertEquals(Command.INVALID, Parser.decideCommand("abc 123")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_wrongByeFormat_invalid() { | ||
assertEquals(Command.INVALID, Parser.decideCommand("bye bye")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_wrongListInput_invalid() { | ||
assertEquals(Command.INVALID, Parser.decideCommand("list 123")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_eventInput_event() { | ||
assertEquals(Command.EVENT, Parser.decideCommand("event abc")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_deadlineInput_deadline() { | ||
assertEquals(Command.DEADLINE, Parser.decideCommand("deadline abc")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_todoInput_todo() { | ||
assertEquals(Command.TODO, Parser.decideCommand("todo abc")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_markInput_mark() { | ||
assertEquals(Command.MARK, Parser.decideCommand("mark abc")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_unmarkInput_unmark() { | ||
assertEquals(Command.UNMARK, Parser.decideCommand("unmark abc")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_correctListInput_list() { | ||
assertEquals(Command.LIST, Parser.decideCommand("list")); | ||
} | ||
|
||
@Test | ||
public void decideCommand_correctByeInput_bye() { | ||
assertEquals(Command.BYE, Parser.decideCommand("bye")); | ||
} | ||
|
||
@Test | ||
public void stringToTask_incorrectTaskType_exceptionThrown() { | ||
try { | ||
assertEquals(new Todo("abc").toString(), | ||
Parser.stringToTask("a | 1 | abc").toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Field 1 (Task type) is invalid", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_incorrectIsMarked_exceptionThrown() { | ||
try { | ||
assertEquals(new Todo("abc").toString(), Parser.stringToTask("T | 3 | abc").toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Field 2 (isMarked) is invalid", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_incorrectTodoFormat_exceptionThrown() { | ||
try { | ||
assertEquals(new Todo("abc").toString(), Parser.stringToTask("T | 1").toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Incorrect Format for todo task in file", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_incorrectDeadlineFormat_exceptionThrown() { | ||
try { | ||
assertEquals(new Deadline(LocalDate.of(2023, 6, 23), "abc").toString(), | ||
Parser.stringToTask("D | 0 | abc").toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Incorrect Format for deadline task in file", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_incorrectEventFormat_exceptionThrown() { | ||
try { | ||
assertEquals(new Event(LocalDate.of(2023, 6, 23), | ||
LocalDate.of(2023, 6, 24), | ||
"abc").toString(), | ||
Parser.stringToTask("E | 0 | abc | 2023-06-23").toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Incorrect Format for event task in file", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_correctTodoFormat_todoTask() { | ||
try { | ||
assertEquals(new Todo("abc").toString(), | ||
Parser.stringToTask("T | 0 | abc").toString()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_correctDeadlineFormat_deadlineTask() { | ||
try { | ||
assertEquals(new Deadline(LocalDate.of(2023, 6, 23), "abc").toString(), | ||
Parser.stringToTask("D | 0 | abc | 2023-06-23").toString()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void stringToTask_correctEventFormat_eventTask() { | ||
try { | ||
assertEquals(new Event(LocalDate.of(2023, 6, 23), | ||
LocalDate.of(2023, 6, 24), "abc").toString(), | ||
Parser.stringToTask("E | 0 | abc | 2023-06-23 | 2023-06-24").toString()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
} |
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,110 @@ | ||
package duke; | ||
|
||
import duke.tasks.Deadline; | ||
import duke.tasks.Event; | ||
import duke.tasks.Task; | ||
import duke.tasks.Todo; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TaskListTest { | ||
List<Task> list = new ArrayList<>(); | ||
Task task1 = new Todo("abc"); | ||
Task task2 = new Event(LocalDate.of(2023, 8, 16), | ||
LocalDate.of(2023, 8, 27), | ||
"read book"); | ||
Task task3 = new Deadline(LocalDate.of(2023, 5, 23), "read book"); | ||
private TaskList taskList = new TaskList(list); | ||
|
||
@BeforeEach | ||
public void init() { | ||
taskList.addTask(task1); | ||
taskList.addTask(task2); | ||
taskList.addTask(task3); | ||
} | ||
|
||
@Test | ||
public void addDeadline_wrongInputFormat_exceptionThrown() { | ||
try { | ||
taskList.addDeadline("deadline read book 2023-04-16"); | ||
Task task4 = new Deadline(LocalDate.of(2023, 4, 16), "read book"); | ||
assertEquals(task4.toString(), list.get(3).toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Input for deadline doesn't match the expected format." + | ||
"\ndeadline ... /by ...", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void addDeadline_wrongDateFormat_exceptionThrown() { | ||
try { | ||
taskList.addDeadline("deadline read book 2023-16-04"); | ||
Task task4 = new Deadline(LocalDate.of(2023, 4, 16), "read book"); | ||
assertEquals(task4.toString(), list.get(3).toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
assertEquals("Input for deadline doesn't match the expected format." + | ||
"\ndeadline ... /by ...", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void addDeadline_correctInput_taskAdded() { | ||
try { | ||
taskList.addDeadline("deadline read book /by 2023-04-16"); | ||
Task task4 = new Deadline(LocalDate.of(2023, 4, 16), "read book"); | ||
assertEquals(task4.toString(), list.get(3).toString()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void markTask_invalidNumber_exceptionThrown() { | ||
try { | ||
Task task4 = new Deadline(LocalDate.of(2023, 5, 23), "read book"); | ||
task4.markAsDone(); | ||
taskList.markTask("4"); | ||
assertEquals(task4.toString(), list.get(2).toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
assertEquals("Invalid number", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void markTask_noNumber_exceptionThrown() { | ||
try { | ||
Task task4 = new Deadline(LocalDate.of(2023, 5, 23), "read book"); | ||
task4.markAsDone(); | ||
taskList.markTask("read book"); | ||
assertEquals(task4.toString(), list.get(2).toString()); | ||
fail(); // the test should not reach this line | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
assertEquals("Please key in a number", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void markTask_validNumber_taskMarked() { | ||
try { | ||
Task task4 = new Deadline(LocalDate.of(2023, 5, 23), "read book"); | ||
task4.markAsDone(); | ||
taskList.markTask("3"); | ||
assertEquals(task4.toString(), list.get(2).toString()); | ||
} catch (Exception e) { | ||
fail(); | ||
} | ||
} | ||
} |