From 3491dd7f83f0facca654a0117a381f545a2bc799 Mon Sep 17 00:00:00 2001 From: gx-huang Date: Mon, 3 Feb 2020 01:11:32 +0800 Subject: [PATCH] A-JUnit --- data/tasks.txt | 2 +- src/main/java/Deadlines.java | 5 ++--- src/main/java/Duke.java | 2 +- src/main/java/DukeParser.java | 4 ++-- src/main/java/DukeStorage.java | 2 +- src/main/java/DukeUI.java | 5 +++-- src/main/java/Events.java | 2 +- src/main/java/Launcher.java | 1 + src/main/java/Task.java | 3 ++- src/main/java/UserText.java | 8 +++----- src/test/java/DeadlineTest.java | 20 ++++++++++++++++++++ src/test/java/ToDoTest.java | 14 ++++++++++++++ 12 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 src/test/java/DeadlineTest.java diff --git a/data/tasks.txt b/data/tasks.txt index 57453cd4fe..af0dbe9fb2 100644 --- a/data/tasks.txt +++ b/data/tasks.txt @@ -1 +1 @@ -D/dividefalse/dividethis/divide1997-08-08 +E/dividetrue/dividethis/dividethat diff --git a/src/main/java/Deadlines.java b/src/main/java/Deadlines.java index 3aad425d9d..b166b58430 100644 --- a/src/main/java/Deadlines.java +++ b/src/main/java/Deadlines.java @@ -12,15 +12,14 @@ public Deadlines(String description, Boolean isDone, String by) { } public String getDeadline() { - return this.by.toString(); + return this.by; } @Override public String toString() { LocalDate date = LocalDate.parse(by); - Format formatter = new SimpleDateFormat("MMM"); String simpleMonth = date.getMonth().toString().substring(0,3); String formattedDate = simpleMonth + " " + date.getDayOfMonth() + " " + date.getYear(); - return "[D]" + super.toString() + "(by:" + formattedDate + ")"; + return "[D]" + super.toString() + " (By: " + formattedDate + ")"; } } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 248bf05fed..ac4e7e22d6 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -24,7 +24,7 @@ public void run() { @Override public void start(Stage stage) { - Label helloWorld = new Label("Hello World!"); // Creating a new Label control + Label helloWorld = new Label("LIBERTY PRIME IS ONLINE"); // Creating a new Label control Scene scene = new Scene(helloWorld); // Setting the scene to be our Label stage.setScene(scene); // Setting the stage to show our screen diff --git a/src/main/java/DukeParser.java b/src/main/java/DukeParser.java index 5aa9ee91b0..f88bd865be 100644 --- a/src/main/java/DukeParser.java +++ b/src/main/java/DukeParser.java @@ -48,7 +48,7 @@ public UserText parseCommand() { } else if (action.equalsIgnoreCase(("todo"))) { DukeUI.showCreationMsg(); if (command_broken.length == 1) { - throw new DukeException("Ooops! The description of a ToDo cannot be empty."); + throw new DukeException("THE DESCRIPTION OF TODO CANNOT BE EMPTY"); } tasks.addInput(new ToDos(command_broken[1], false)); @@ -69,7 +69,7 @@ public UserText parseCommand() { } } else { - throw new DukeException("Ooops! I'm sorry, i don't know what it means"); + throw new DukeException("UNABLE TO COMPREHEND"); } } catch (DukeException exception) { diff --git a/src/main/java/DukeStorage.java b/src/main/java/DukeStorage.java index 2e671126f6..3084f244a8 100644 --- a/src/main/java/DukeStorage.java +++ b/src/main/java/DukeStorage.java @@ -47,7 +47,7 @@ public UserText readText() { tasks.add(task); } } catch (IOException ioException) { - + System.out.println(ioException.getMessage()); } return tasks; } diff --git a/src/main/java/DukeUI.java b/src/main/java/DukeUI.java index 0627555a2c..9052a0aa78 100644 --- a/src/main/java/DukeUI.java +++ b/src/main/java/DukeUI.java @@ -12,7 +12,6 @@ public static void showWelcomeMessage () { + "| |_____| |_| |_/ / |___| |\\ \\ | | | | | | | |\\ \\ _| |_| | | || |___\n" + "\\_____/\\___/\\____/\\____/\\_| \\_| \\_/ \\_/ \\_| \\_| \\_|\\___/\\_| |_/\\____/\n"; System.out.println(logo); - System.out.println("LIBERTY PRIME IS ONLINE"); System.out.println("DEMOCRACY IS NON NEGOTIABLE"); } @@ -32,10 +31,12 @@ public static void showCreationMsg() { } public static void showDeleteMsg() { - System.out.println("OBSTRUCTION DETECTED. PROBABILITY OF DETERENCE: 0%"); + System.out.println("OBSTRUCTION ELIMINATED"); } public static void showFindMsg() { System.out.println("TARGET FOUND"); } + + public static void showCurrentListSize(int size) {System.out.println("NOW YOU HAVE " + size + " TARGETS TO ELIMINATE");} } diff --git a/src/main/java/Events.java b/src/main/java/Events.java index b543561c92..f80bb05d84 100644 --- a/src/main/java/Events.java +++ b/src/main/java/Events.java @@ -13,6 +13,6 @@ public String getVenue() { @Override public String toString() { - return "[E]" + super.toString() + "(at:" + at + ")"; + return "[E]" + super.toString() + " (At: " + at + ")"; } } diff --git a/src/main/java/Launcher.java b/src/main/java/Launcher.java index c02bcacf3e..e3bde2269e 100644 --- a/src/main/java/Launcher.java +++ b/src/main/java/Launcher.java @@ -8,6 +8,7 @@ public static void main(String[] args) { Application.launch(Duke.class, args); Duke duke = new Duke(); duke.run(); + } } diff --git a/src/main/java/Task.java b/src/main/java/Task.java index e275201f26..a207572949 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -35,8 +35,9 @@ public boolean isDone() { return isDone; } + //returns "O" if done, "X" if not public String getStatusIcon() { - return (isDone ? "O" : "X"); //return tick or X symbols + return (isDone ? "O" : "X"); } public String getDescription() { diff --git a/src/main/java/UserText.java b/src/main/java/UserText.java index cc208ce880..f10db3d02b 100644 --- a/src/main/java/UserText.java +++ b/src/main/java/UserText.java @@ -11,12 +11,12 @@ public UserText() { public void addInput(Task s) { this.allTasks.add(s); - System.out.println("Now you have " + allTasks.size() + " tasks in the list."); + DukeUI.showCurrentListSize(allTasks.size()); } public void printTasks() { int count = 1; - System.out.println("Here is your list"); + System.out.println("HERE IS YOUR LIST"); for (Task s : allTasks) { System.out.println(count + ". " + s); count++; @@ -37,13 +37,11 @@ public void add(Task task) { public void markDone(int taskNo) { allTasks.get(taskNo - 1).markAsDone(); - System.out.println("Nice! I marked this task as done"); } public void removeTask(int taskNo) { Task tempTask = allTasks.remove(taskNo - 1); - System.out.println("Noted. I have removed this task"); System.out.println(" " + tempTask); - System.out.println("Now you have " + allTasks.size() + " tasks in the list."); + DukeUI.showCurrentListSize(allTasks.size()); } } diff --git a/src/test/java/DeadlineTest.java b/src/test/java/DeadlineTest.java new file mode 100644 index 0000000000..df6613bddf --- /dev/null +++ b/src/test/java/DeadlineTest.java @@ -0,0 +1,20 @@ + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DeadlineTest { + + @Test + public void testStringConvert() { + assertEquals("[D][X] read book (By: JAN 1 2020)", + new Deadlines("read book",false, "2020-01-01").toString()); + assertEquals("[D][O] read book (By: JAN 1 2020)", + new Deadlines("read book", true, "2020-01-01").toString()); + } + + @Test + public void testGetDeadline() { + assertEquals("2020-01-01", + new Deadlines("read book", true, "2020-01-01").getDeadline()); + } +} diff --git a/src/test/java/ToDoTest.java b/src/test/java/ToDoTest.java index e69de29bb2..5b0e00efc4 100644 --- a/src/test/java/ToDoTest.java +++ b/src/test/java/ToDoTest.java @@ -0,0 +1,14 @@ + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ToDoTest { + + @Test + public void testStringConvert() { + assertEquals("[T][X] read book", + new ToDos("read book", false).toString()); + assertEquals("[T][O] read book", + new ToDos("read book", true).toString()); + } +} \ No newline at end of file