forked from nus-cs2103-AY2021S1/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 test to Duke,Parser and TaskList
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
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
Binary file not shown.
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,19 @@ | ||
package duke; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DukeTest { | ||
@Test | ||
public void dummyTest(){ | ||
assertEquals(2, 2); | ||
} | ||
|
||
// @Test | ||
// public void dukeRun() throws IOException { | ||
// new Duke().run(); | ||
// } | ||
} |
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,77 @@ | ||
package duke; | ||
|
||
import duke.enums.Message; | ||
import duke.exception.DukeException; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class ParserTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"deadline return book /by 19/02/2020 0900", "event project meeting /at Mon 2-4pm", "todo " + | ||
"join sports club"}) | ||
public void parsingCommand_parameterizedTest_validCommandsCreated(String input) throws DukeException { | ||
Parser p = new Parser(); | ||
assert (p.parseCommand(input) != null); // successful creation | ||
} | ||
|
||
@Test | ||
public void exceptionHandling_insufficientTodoDescription_dukeExceptionReturned() { | ||
String input = "todo"; | ||
String expectedMsg = "invalid todo command: do what?"; | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> { | ||
p.parseCommand(input); | ||
}); | ||
assertEquals(expectedMsg, de.getMessage()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"tod", "blah", }) | ||
public void exceptionHanlding_unknownCommand_dukeExceptionReturned(String s) { | ||
String expectedMsg = Message.ERROR_UNKNOWN_CMD.getMsg(); | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> p.parseCommand(s)); | ||
assertEquals(de.getMessage(), expectedMsg); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"done 4 5 6", "delete 4 5 6"}) | ||
public void exceptionHandling_multipleDoneDeleteArguments_dukeExceptionReturned(String s) { | ||
String expectedMsg = Message.ERROR_DONEDELETE_ARGS.getMsg(); | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> p.parseCommand(s)); | ||
assertEquals(de.getMessage(), expectedMsg); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"deadline", "deadline a"}) | ||
public void exceptionHandling_badDeadlineFormat_dukeExceptionReturned(String s) { | ||
String expectedMsg = Message.ERROR_DEADLINE_FORMAT.getMsg(); | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> p.parseCommand(s)); | ||
assertEquals(de.getMessage(), expectedMsg); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"deadline /by xxx", "deadline /by Sunday"}) | ||
public void exceptionHandling_deadlineNoDateDescription_dukeExceptionReturned(String s) { | ||
String expectedMsg = Message.ERROR_DEADLINE_DESC.getMsg(); | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> p.parseCommand(s)); | ||
assertEquals(de.getMessage(), expectedMsg); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"event /by Sunday"}) | ||
public void exceptionHandling_badEventFormat_dukeExceptionReturned(String s) { | ||
String expectedMsg = Message.ERROR_EVENT_FORMAT.getMsg(); | ||
Parser p = new Parser(); | ||
DukeException de = assertThrows(DukeException.class, () -> p.parseCommand(s)); | ||
assertEquals(de.getMessage(), expectedMsg); | ||
} | ||
} |
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,5 @@ | ||
package duke; | ||
|
||
public class StorageTest { | ||
|
||
} |
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,42 @@ | ||
package duke; | ||
|
||
import duke.exception.DukeException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TaskListTest { | ||
|
||
|
||
public static TaskList testTaskList = new TaskList(); | ||
|
||
private static void initTest() throws DukeException { | ||
String[] parsedInput1 = {"T", "kill me now"}; | ||
String[] parsedInput2 = {"T", "i want ice cream"}; | ||
String commandTag = "T"; | ||
testTaskList.addEntry(parsedInput1, commandTag); | ||
testTaskList.addEntry(parsedInput2, commandTag); | ||
} | ||
|
||
@Test | ||
public void modifyTaskList_addEntryTodo_increaseTaskCount() throws DukeException { | ||
TaskListTest.initTest(); | ||
String[] parsedInput1 = {"T", "happy thoughts"}; | ||
assertEquals(testTaskList.addEntry(parsedInput1, "T"), | ||
"[T][✘] happy thoughts"); | ||
} | ||
|
||
@Test | ||
public void queryTaskList_getCurrentStatus_returnsString() throws DukeException { | ||
TaskListTest.initTest(); | ||
String expected = "Now you have 2 undone tasks in the list."; | ||
assertEquals(testTaskList.getCurrentStatus(), expected); | ||
} | ||
|
||
@Test | ||
public void modifyTaskList_completeTask_returnsString() throws DukeException { | ||
TaskListTest.initTest(); | ||
String expected = "[T][✓] i want ice cream"; | ||
assertEquals(testTaskList.completeTask(2), expected); | ||
} | ||
} |