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 tests to test behaviour of ToDo, Deadline, Event, Parser class
- Loading branch information
1 parent
96b1804
commit f36ad8f
Showing
7 changed files
with
194 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import java.io.IOException; | ||
|
||
public class Duke { | ||
|
||
private Ui ui; | ||
|
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,37 @@ | ||
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 { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
LocalDateTime atLocalDate = LocalDateTime.parse("2020-12-12 12:30", formatter); | ||
|
||
@Test | ||
public void markAsDone_success() { | ||
Deadline task = new Deadline("proj meeting", atLocalDate); | ||
assertEquals("\u2718", task.getStatusIcon()); | ||
task = task.markAsDone(); | ||
assertEquals("\u2713", task.getStatusIcon()); | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
Deadline task = new Deadline("proj meeting", atLocalDate); | ||
assertEquals("[D][" + "\u2718" + "] " + "proj meeting (by: Dec 12 2020 12:30 PM)", task.toString()); | ||
|
||
Deadline doneTask = new Deadline("proj meeting", atLocalDate, true); | ||
assertEquals("[D][" + "\u2713" + "] " + "proj meeting (by: Dec 12 2020 12:30 PM)", doneTask.toString()); | ||
} | ||
|
||
@Test | ||
public void toTxtFileformat_success() { | ||
Deadline task = new Deadline("proj meeting", atLocalDate); | ||
assertEquals("D | 0 | proj meeting | 2020-12-12 12:30", task.toTxtFileFormat()); | ||
|
||
Deadline doneTask = new Deadline("proj meeting", atLocalDate, true); | ||
assertEquals("D | 1 | proj meeting | 2020-12-12 12:30", doneTask.toTxtFileFormat()); | ||
} | ||
} |
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 @@ | ||
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 EventTest { | ||
@Test | ||
public void markAsDone_success() { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
LocalDateTime byLocalDate = LocalDateTime.parse("2020-12-12 12:30", formatter); | ||
Event task = new Event("proj meeting", byLocalDate); | ||
assertEquals("\u2718", task.getStatusIcon()); | ||
task = task.markAsDone(); | ||
assertEquals("\u2713", task.getStatusIcon()); | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
LocalDateTime byLocalDate = LocalDateTime.parse("2020-12-12 12:30", formatter); | ||
Event task = new Event("proj meeting", byLocalDate); | ||
assertEquals("[E][" + "\u2718" + "] " + "proj meeting (at: Dec 12 2020 12:30 PM)", task.toString()); | ||
|
||
Event doneTask = new Event("proj meeting", byLocalDate, true); | ||
assertEquals("[E][" + "\u2713" + "] " + "proj meeting (at: Dec 12 2020 12:30 PM)", doneTask.toString()); | ||
} | ||
|
||
@Test | ||
public void toTxtFileformat_success() { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
LocalDateTime byLocalDate = LocalDateTime.parse("2020-12-12 12:30", formatter); | ||
Event task = new Event("proj meeting", byLocalDate); | ||
assertEquals("E | 0 | proj meeting | 2020-12-12 12:30", task.toTxtFileFormat()); | ||
|
||
Event doneTask = new Event("proj meeting", byLocalDate, true); | ||
assertEquals("E | 1 | proj meeting | 2020-12-12 12:30", doneTask.toTxtFileFormat()); | ||
} | ||
} |
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,64 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ParserTest { | ||
@Test | ||
public void isInteger_stringInteger_success() { | ||
assertEquals(true, Parser.isInteger("2")); | ||
} | ||
|
||
@Test | ||
public void isValidFormat_stringInputDate_valid() { | ||
assertEquals(true, Parser.isValidFormat("2020-10-10 12:30")); | ||
} | ||
|
||
@Test | ||
public void isValidFormat_stringInputDate_invalid() { | ||
assertEquals(false, Parser.isValidFormat("10th august")); | ||
|
||
} | ||
|
||
@Test | ||
public void parse_oneWordCommand_success() throws DukeException { | ||
assertEquals(true, Parser.parse("list") instanceof ListCommand); | ||
assertEquals(true, Parser.parse("bye") instanceof ExitCommand); | ||
} | ||
|
||
@Test | ||
public void parse_doneCommand_success() throws DukeException { | ||
assertEquals(true, Parser.parse("done 1") instanceof DoneCommand); | ||
assertEquals(true, Parser.parse("done 3") instanceof DoneCommand); | ||
} | ||
|
||
@Test | ||
public void parse_InvalidDoneCommand_exceptionThrown() { | ||
try { | ||
assertEquals(true, Parser.parse("done 0") instanceof DoneCommand); | ||
} catch (DukeException e) { | ||
assertEquals("Please enter a valid task number.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void parse_deleteCommand_success() throws DukeException { | ||
assertEquals(true, Parser.parse("delete 1") instanceof DeleteCommand); | ||
assertEquals(true, Parser.parse("delete 3") instanceof DeleteCommand); | ||
} | ||
|
||
@Test | ||
public void parse_addCommand_success() throws DukeException { | ||
assertEquals(true, Parser.parse("todo study") instanceof AddCommand); | ||
assertEquals(true, Parser.parse("deadline work /by 2020-12-12 12:30") instanceof AddCommand); | ||
assertEquals(true, Parser.parse("event proj /at 2020-12-12 12:30") instanceof AddCommand); | ||
} | ||
|
||
@Test | ||
public void parse_invalidCommands_exceptionThrown() { | ||
try { | ||
assertEquals(true, Parser.parse("abcd") instanceof Command); | ||
} catch (DukeException e) { | ||
assertEquals("☹ ERROR: Invalid command provided. Please try again.", 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,21 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TaskListTest { | ||
|
||
@Test | ||
public void doneTask_intTaskNumber_success() { | ||
List<Task> tmp = new ArrayList<>(); | ||
ToDo task = new ToDo("testing"); | ||
tmp.add(task); | ||
TaskList tasks = new TaskList(tmp); | ||
|
||
assertEquals(false, tasks.getTask(1).isDone); | ||
tasks.doneTask(1); | ||
assertEquals(true, tasks.getTask(1).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,32 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ToDoTest { | ||
@Test | ||
public void markAsDone_success() { | ||
ToDo task = new ToDo("testing"); | ||
assertEquals("\u2718", task.getStatusIcon()); | ||
task = task.markAsDone(); | ||
assertEquals("\u2713", task.getStatusIcon()); | ||
} | ||
|
||
@Test | ||
public void toString_success() { | ||
ToDo task = new ToDo("study at home"); | ||
assertEquals("[T][" + "\u2718" + "] " + "study at home", task.toString()); | ||
|
||
ToDo doneTask = new ToDo("study at home", true); | ||
assertEquals("[T][" + "\u2713" + "] " + "study at home", doneTask.toString()); | ||
} | ||
|
||
@Test | ||
public void toTxtFileformat_success() { | ||
ToDo task = new ToDo("study at home"); | ||
assertEquals("T | 0 | study at home", task.toTxtFileFormat()); | ||
|
||
ToDo doneTask = new ToDo("study at home", true); | ||
assertEquals("T | 1 | study at home", doneTask.toTxtFileFormat()); | ||
} | ||
|
||
} |