diff --git a/docs/README.md b/docs/README.md index 8077118eb..87c218a1c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,182 @@ # User Guide -## Features +## Feature List +1. Add Tasks + Users can add various types of tasks such as to-do, deadline, and event tasks to the task list. + Command: `add` +2. View Task List + Users can view all tasks currently in the task list. + Command: `list` +3. Mark Task as Done + Users can mark a task as done. + Command: `mark` +4. Mark Task as Undone + Users can mark a completed task as not done. + Command: `unmark` +5. Delete Task + Users can delete a task from the task list. + Command: `delete` +6. Clear Task List + Users can clear all tasks from the task list. + Command: `clear` +7. Search Tasks + Users can search for tasks containing specific keywords. + Command: `find` +8. Save Task List + Users can save the current task list to a file. + Command: `save` +9. Help + Users can view a list of supported commands for using the task manager. + Command: `help` +10. Quit Task Manager + Users can exit the task manager application. + Command: `quit` -### Feature-ABC -Description of the feature. -### Feature-XYZ -Description of the feature. +## Commands -## Usage +### `list` - enter the list mode +Example of usage: -### `Keyword` - Describe action +``` +list +``` + +Expected outcome: +``` +--------------------------------------------- +Here are your current tasks in your list: + +--------------------------------------------- +``` +### `Bye` - Quit the Qchat bot + +### list mode commads : + +### `add` - Add a task + +Adds a new task to the to-do list. + +Example of usage: + +``` +add +todo go to class +``` +Expected outcome: +``` +--------------------------------------------- +Here are your current tasks in your list: +1. [T][ ] go to class +--------------------------------------------- +``` + + +### `clear` - Clear all tasks + +Example of usage: + +``` +clear +``` +Expected outcome: +``` +list cleared +``` + +### `list` - list all current tasks + +Example of usage: + +``` +list +``` +Expected outcome: +``` +--------------------------------------------- +Here are your current tasks in your list: +--------------------------------------------- +``` +### `save` - save current tasks into a file + +Example of usage: + +``` +save +``` +Expected outcome: +``` +File exists, overwriting file +``` -Describe the action and its outcome. -Example of usage: +### `mark & unmark` - set a task as done or not done -`keyword (optional arguments)` +Example of usage: +``` +mark +1 +``` Expected outcome: +``` +I've marked this task as done:[T][x] go to class +``` -Description of the outcome. +### `quit` - quit list mode +Example of usage: + +``` +quit +``` +Expected outcome: +``` +Task change complete +``` +### `help` - get help of other commands + +Example of usage: + +``` +help +``` +Expected outcome: ``` -expected output +supported commands: add , quit , help , mark, unmark ,clear, list, delete, find ,save ``` + +### `find` - find task which contains a given keyword + +Example of usage: + +``` +find +class +``` +Expected outcome: +``` +--------------------------------------------- +Here are the matching tasks in your list: +1. [T][x] go to class +--------------------------------------------- +``` + +### `delete` - delete a task in the list + +Example of usage: + +``` +delete +1 +``` +Expected outcome: +``` +--------------------------------------------- +Here are your current tasks in your list: +--------------------------------------------- + +``` + diff --git a/ip.jar b/ip.jar new file mode 100644 index 000000000..e2d9ff2e6 Binary files /dev/null and b/ip.jar differ diff --git a/list.txt b/list.txt new file mode 100644 index 000000000..8a9a0cd20 --- /dev/null +++ b/list.txt @@ -0,0 +1,2 @@ +1|D|| | stellaris(by:Mar 01 2024) + diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..08d1269d1 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,41 @@ +/** + * The {@code Deadline} class represents a deadline item. + * comparing with todo , it has a end time + * + */ +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +public class Deadline extends Todo{ + LocalDate endtime; + String Icon="D"; + /** + * Constructs a new deadline item. + * + * @param isDone Indicates whether the deadline item is done + * @param description The description of the deadline item + * @param endtime A String indicating the end time of this deadline + */ + public Deadline(boolean isDone, String description, LocalDate endtime) { + super(isDone, description); + this.endtime = endtime; + } + + /** + * similar to the one in Todo class + * @return The string representation of the to-do item + */ + @Override + public String toString(){ + String DoneIcon = isDone? "x":" "; + return "["+Icon+"]"+"["+DoneIcon+"] "+ description + "(by:"+ formatDate(endtime)+")"; + } + + public static String formatDate(LocalDate date) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy", Locale.ENGLISH); + return date.format(formatter); + } + +} \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..1c6c3e0d9 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,32 @@ +/** + * The {@code Event} class represents a event item. + * it has a start time and an end time + * + */ +import java.time.LocalDate; +public class Event extends Deadline{ + LocalDate starttime; + String Icon="E"; + /** + * Constructs a new event item. + * + * @param isDone Indicates whether the deadline item is done + * @param description The description of the deadline item + * @param endtime A String indicating the end time of this event + * @param starttime A String indicating the start time of this event + */ + public Event(boolean isDone, String description, LocalDate endtime, LocalDate starttime) { + + super(isDone, description, endtime); + this.starttime = starttime; + } + /** + * similar to the one in Todo class + * @return The string representation of the event item + */ + @Override + public String toString(){ + String DoneIcon = this.isDone? "x":" "; + return "["+Icon+"]"+"["+DoneIcon+"]"+ " "+ this.description + "(from: "+formatDate(starttime)+ ") (to: "+formatDate(this.endtime)+")" ; + } +} \ No newline at end of file diff --git a/src/main/java/InvalidTimeForm.java b/src/main/java/InvalidTimeForm.java new file mode 100644 index 000000000..d25b18121 --- /dev/null +++ b/src/main/java/InvalidTimeForm.java @@ -0,0 +1,2 @@ +public class InvalidTimeForm extends Exception { +} diff --git a/src/main/java/ListManager.java b/src/main/java/ListManager.java new file mode 100644 index 000000000..c394f6955 --- /dev/null +++ b/src/main/java/ListManager.java @@ -0,0 +1,212 @@ +import java.io.*; +import java.time.DateTimeException; +import java.util.ArrayList; +import java.util.Scanner; +import java.time.LocalDate; +public class ListManager { + static UI ui = new UI(); + static Parser parser = new Parser(); + static Storage storage = new Storage(); + static ArrayList todolist = new ArrayList<>(); + //static boolean[] isDoneList = new boolean[MAX_LIST_LENGTH]; + static final String ALL_TASKS = "Here are your current tasks in your list:" ; + static final String MATCHED_TASKS = "Here are the matching tasks in your list:" ; + static Scanner in = new Scanner(System.in); + + + public static String AddToList(String description) throws InvalidTimeForm { + + String[] part = (description.trim()).split(" "); + String suffix = description.replace(part[0], ""); + try{ + if (part[0].startsWith("todo")) { + return (Parser.AddTodo(suffix)); + } else if (part[0].startsWith("deadline")) { + return (Parser.AddDeadline(suffix)); + } else if (part[0].startsWith("event")) { + return (Parser.AddEvent(suffix)); + } else { + System.out.println("unexpected task from , please add again"); + return ""; + } + }catch (DateTimeException e){ + System.out.println("unexpected date form , please type the date as yyyy-mm-dd format"); + return ""; + } + + } + + + static void HandleList() { + + String command = ""; + try { + todolist = storage.ReadFile(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + UI.PrintList(todolist,ALL_TASKS); + ; + + while (!command.equals("quit")) { + command = in.nextLine(); + switch (command.trim()) { + case "add": + ui.PrintListForm(); + String description = in.nextLine(); + try { + System.out.println(AddToList(description)); + } catch (InvalidTimeForm e) { + System.out.println("wrong time form, please add again"); + } + UI.PrintList(todolist,ALL_TASKS); + ; + break; + case "quit": + System.out.println("Task change complete\n"); + break; + case "help": + System.out.print("supported commands: add , quit , help , mark, unmark ,clear, list, delete, find ,save \n"); + break; + case "clear": + ClearList(); + System.out.print("list cleared\n"); + break; + case "mark": + SetDone(); + break; + case "unmark": + SetUndone(); + break; + case "list": + UI.PrintList(todolist,ALL_TASKS); + break; + case "": + break; + case "find": + SearchList(); + break; + case "delete": + Deletelist(); + break; + case "save": + try { + storage.SaveList(todolist); + } catch (IOException e) { + throw new RuntimeException(e); + } + break; + default: + System.out.println("Sorry, I can not understand this command, enter \"help\" for help\n"); + break; + } + + } + + } + + private static void SearchList() { + System.out.print("please type the key words you want to find\n"); + String description = in.nextLine(); + ArrayList temp_todolist = new ArrayList<>(); + for(Todo t:todolist){ + if(t.description.contains(description)){ + temp_todolist.add(t); + } + + } + if(temp_todolist.isEmpty()){ + System.out.print("no matched task found!\n"); + } + else{ + UI.PrintList(temp_todolist,MATCHED_TASKS); + temp_todolist.clear(); + } + + } + + + private static void Deletelist() { + + if (todolist.isEmpty()) { + System.out.println("no available tasks\n"); + return; + } + int number = in.nextInt(); + + while (number > todolist.size()) { + System.out.println("index out of bound, please retype\n"); + number = in.nextInt(); + } + todolist.remove(number - 1); + + System.out.println("task deleted\n"); + UI.PrintList(todolist,ALL_TASKS); + ; + } + + + static void ClearList() { + todolist.clear(); + } + + + private static void SetDone() { + if (todolist.isEmpty()) { + System.out.println("No available task! \n"); + return; + } + + System.out.println("please type the task number you want to set as done \n"); + UI.PrintList(todolist,ALL_TASKS); + int number = in.nextInt(); + + while (number > todolist.size()) { + System.out.println("task do not exist, pleas enter a valid task number "); + number = in.nextInt(); + } + + Todo task = todolist.get(number - 1); + + task.SetisDone(true); + + System.out.print("I've marked this task as done:"); + System.out.println(task.toString()); + + } + + + static void SetUndone() { + if (todolist.isEmpty()) { + System.out.println("No available task! \n"); + return; + } + + System.out.println("please type the task number you want to set as not done \n"); + UI.PrintList(todolist,ALL_TASKS); + + int number = in.nextInt(); + + + while (number > todolist.size()) { + System.out.println("task do not exist, pleas enter a valid task number "); + number = in.nextInt(); + } + + Todo task = todolist.get(number - 1); + + task.SetisDone(false); + + System.out.print("I've marked this task as not done:"); + System.out.println(task.toString()); + + + } +} + + + + + + + diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..922689772 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Qchat + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..5f62348b8 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,144 @@ +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.time.LocalDate; +import java.util.Locale; + +/** + * The {@code Parser} class handles the parsing of input lines and creating corresponding to-do items. + */ +public class Parser { + + public static final int BEGIN_INDEX = 7; + + /** + * Processes a saved line from the file and creates a corresponding to-do item. + * deals with 3 types and store them in todolist + * first the function decide the type ,the it extracts description , start time and end time according to the + * format + * + * @param line The saved line to be processed + * @param todolist The list of to-do items to which the created item will be added + */ + public static void ProcessSavedLine(String line, ArrayList todolist) { + String Done = "|" + "([x ])" + "|"; + + Boolean isDone; + if (line.contains("| |")) { + isDone = false; + } else if (line.contains("|x|")) { + isDone = true; + } else { + System.out.println("Unexpected format , skipping"); + return; + } + String description; + String starttime; + String endtime; + + if (line.contains("|T|")) { + String parts = line.substring(BEGIN_INDEX); + description = parts; + Todo task = new Todo(isDone, description.trim()); + todolist.add(task); + } else if (line.contains("|D|")) { + String parts = line.substring(BEGIN_INDEX); + String[] contents = parts.split("by:", 2); + description = contents[0].replace("(", ""); + endtime = contents[1].replace(")", ""); + LocalDate endDate = parseDateFile(endtime); + + Deadline task = new Deadline(isDone, description.trim(), endDate); + todolist.add(task); + } else if (line.contains("|E|")) { + String parts = line.substring(BEGIN_INDEX); + String[] contents = parts.split("from:", 2); + description = contents[0].replace("(", ""); + String[] time = contents[1].split("to:", 2); + starttime = time[0].replace("(", "").replace(")", ""); + endtime = time[1].replace("(", "").replace(")", ""); + Event task = new Event(isDone, description.trim(), parseDateFile(endtime.trim()), parseDateFile(starttime.trim()) ); + todolist.add(task); + } else { + System.out.println("Unexpected format, skipping"); + } + } + + /** + * Adds a to-do item to the list with the given description. + * + * @param description The description of the to-do item to be added + * @return A message indicating that the to-do item has been added + */ + static String AddTodo(String description) { + Todo todo = new Todo(false, description); + ListManager.todolist.add(todo); + return "Todo added\n"; + } + + /** + * Adds a deadline item to the list with the given description and end time. + * + * @param description The description of the deadline item to be added + * @return A message indicating that the deadline item has been added + * @throws InvalidTimeForm If the time format is invalid + */ + static String AddDeadline(String description) throws InvalidTimeForm { + if(!description.contains("/by")){ + throw new InvalidTimeForm(); + } + String[] part = (description.trim()).split("/by"); + + if (part.length > 2) { + throw new InvalidTimeForm(); // two or more "/by" + } + LocalDate endtime = parseDateInput(part[1].trim()); + + Deadline deadline = new Deadline(false, part[0].trim(), endtime); + ListManager.todolist.add(deadline); + return "Deadline added\n"; + } + + /** + * Adds an event item to the list with the given description, start time, and end time. + * + * @param description The description of the event item to be added + * @return A message indicating that the event item has been added + * @throws InvalidTimeForm If the time format is invalid + */ + static String AddEvent(String description) throws InvalidTimeForm { + + if(!description.contains("/from")||!description.contains("/to")){ + throw new InvalidTimeForm(); + } + if(description.indexOf("/from")>description.indexOf("/to")){ + throw new InvalidTimeForm(); + } + + String[] part = (description.trim()).split("/from"); + if (part.length > 2) { + throw new InvalidTimeForm(); + } + String EventDescription = part[0].trim(); + String[] content = (part[1].trim()).split("/to"); + + if (content.length > 2) { + throw new InvalidTimeForm(); + } + String end = content[1].trim(); + String start = content[0].trim(); + Event event = new Event(false, EventDescription,parseDateInput(end), parseDateInput(start)); + ListManager.todolist.add(event); + return "Event added\n"; + } + + public static LocalDate parseDateFile(String timeString) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd yyyy",Locale.ENGLISH); + return LocalDate.parse(timeString, formatter); + } + public static LocalDate parseDateInput(String timeString) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH); + return LocalDate.parse(timeString, formatter); + } +} diff --git a/src/main/java/Qchat.java b/src/main/java/Qchat.java new file mode 100644 index 000000000..cbcb85765 --- /dev/null +++ b/src/main/java/Qchat.java @@ -0,0 +1,48 @@ +import javax.swing.*; +import java.util.Scanner; + +public class Qchat { + static UI ui = new UI(); + static String CommandReader(){ + + Scanner in = new Scanner(System.in); + String command ; + command = in.nextLine(); + + switch (command){ + case "Bye": + ui.Goodbye(); + break; + case "list": + ListManager Listmanager = null; + ListManager.HandleList(); + break; + + + default: + echo(command); + break; + + } + return command; + + + + } + + private static void echo(String command) { + System.out.print("---------------------------------------------\n"); + System.out.print(command +"\n"); + System.out.print("---------------------------------------------\n"); + } + + public static void main(String[] args) { + + ui.Greeting(); + ListManager Listmanager = null; + ListManager.HandleList(); + ui.Goodbye(); + + } + +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..080aebd62 --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,78 @@ +import java.io.*; +import java.time.DateTimeException; +import java.util.ArrayList; + +/** + * The {@code Storage} class handles the reading and writing of to-do lists from and to a file. + */ +public class Storage { + + /** + * The list of to-do items. + */ + static ArrayList todolist = new ArrayList<>(); + + /** + * Reads the to-do list from the file "list.txt". + * will create a file if it does not exist + * it read evey line and use parser to handle it + * @return The list of to-do items read from the file + * @throws FileNotFoundException If the file "list.txt" does not exist + * @throws IndexOutOfBoundsException If the file "list.txt" is broken or not readable + */ + static ArrayList ReadFile() throws FileNotFoundException { + File file = new File("list.txt"); + if (!file.exists()) { + return todolist; + } else { + FileReader fr = new FileReader(file); + BufferedReader reader = new BufferedReader(fr); + System.out.println("loading saved list from saved file"); + try { + String line; + while ((line = reader.readLine()) != null) { // Process every line + + try{ + Parser.ProcessSavedLine(line, todolist); + } + catch (IndexOutOfBoundsException e){ + System.out.println(e.getMessage()); + System.out.println("unexpected format , skipping"); + }catch (DateTimeException e){ + System.out.println("unexpected format , skipping"); + } + + } + } catch (IOException e) { + System.out.println(e.getMessage()); + } + return todolist; + } + } + + /** + * Saves the list of to-do items to the file "list.txt". + * will overwrite existing file + * @param todolist The list of to-do items to be saved + * @throws IOException If an I/O error occurs while writing to the file + */ + static void SaveList(ArrayList todolist) throws IOException { + File file = new File("list.txt"); + + if (file.exists()) { + System.out.println("File exists, overwriting file"); + } else { + file.createNewFile(); + } + + FileWriter fw = new FileWriter("list.txt"); + for (Object t : todolist) { + if (t == null) { + continue; + } + String content = (todolist.indexOf(t) + 1) + t.toString() + "\n"; + fw.write(content.replace("[", "|").replace("]", "|")); + } + fw.close(); + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..2c8df8c50 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,61 @@ +/** + * The {@code Todo} class represents a to-do item. + * the super class of all types of tasks + */ +public class Todo { + + /** + * Indicates whether the to-do item is done or not. + */ + public Boolean isDone; + + /** + * The description of the to-do item. + */ + public String description; + + /** + * The icon representing the to-do item, defaulting to "T". + */ + String Icon = "T"; + + /** + * Constructs a new to-do item. + * + * @param isDone Indicates whether the todo item is done + * @param description The description of the todo item + */ + public Todo(boolean isDone, String description) { + this.isDone = isDone; + this.description = description; + } + + /** + * Sets the completion status of the to-do item. + * + * @param isDone Indicates whether the to-do item is done + */ + public void SetisDone(boolean isDone) { + this.isDone = isDone; + } + + /** + * Sets the description of the to-do item. + * + * @param description The description of the to-do item + */ + public void SetDescription(String description) { + this.description = description; + } + + /**this toString method add prefix with brackets to indicate the type and status of the tasks + * Returns the string representation of the to-do item. + * + * @return The string representation of the to-do item + */ + @Override + public String toString() { + String DoneIcon = isDone ? "x" : " "; + return "[" + Icon + "]" + "[" + DoneIcon + "] " + description; + } +} \ No newline at end of file diff --git a/src/main/java/UI.java b/src/main/java/UI.java new file mode 100644 index 000000000..52b959cd4 --- /dev/null +++ b/src/main/java/UI.java @@ -0,0 +1,76 @@ +import java.util.ArrayList; + +/** + * The {@code UI} class handles user interface interactions and displays messages. + */ +public class UI { + + /** + * A welcome greeting message displayed when the program starts. + */ + static final String WELCOME_GREETING = new String( + "Qchat, A truly humanized intelligent voice assistant\n" + + "knows better about life and better about you\n" + + "What can I do for you?\n" + + "you can enter 'help' for help\n"+ + "----------------------------------------------------------------\n"); + + /** + * A goodbye message displayed when the program ends. + */ + static final String GOODBYE_GREETING = new String( + "--------------------------------------------------------\n" + + "goodbye\n" + "Qchat, your life-long trusted companion\n"); + + /** + * The format of the list command. + */ + private static final String LIST_FORM = + "please enter in one of the following forms:\n" + + "todo 'description'\n" + + "deadline 'description' /by \"yyyy-MM-dd\" \n" + + "event 'description' /from \"yyyy-MM-dd\" /to \"yyyy-MM-dd\" \n"; + + /** + * Displays the welcome greeting message. + */ + public void Greeting() { + System.out.print(WELCOME_GREETING); + } + + /** + * Displays the goodbye message. + */ + public void Goodbye() { + System.out.print(GOODBYE_GREETING); + } + + /** + * Displays the list command format. + */ + public void PrintListForm() { + System.out.println(LIST_FORM); + } + + /** + * Prints the list of items along with their sequence number and description of printed items + * if used for print every to-do in the list, description would be "Here are your current tasks in your list:" + * if used for print matching tasks ,description would be "Here are the matching tasks in your list:" + * + * @param todolist The list of items to print + * @param description The description of the list + */ + public static void PrintList(ArrayList todolist, String description) { + int i = 1; + System.out.print("---------------------------------------------\n"); + System.out.println(description); + for (Object t : todolist) { + if (t == null) { + continue; + } + System.out.printf("%d. " + t.toString() + "\n", i); + i++; + } + System.out.print("---------------------------------------------\n"); + } +} diff --git a/src/main/java/text-ui-test/EXPECTED.TXT b/src/main/java/text-ui-test/EXPECTED.TXT new file mode 100644 index 000000000..657e74f6e --- /dev/null +++ b/src/main/java/text-ui-test/EXPECTED.TXT @@ -0,0 +1,7 @@ +Hello from + ____ _ +| _ \ _ _| | _____ +| | | | | | | |/ / _ \ +| |_| | |_| | < __/ +|____/ \__,_|_|\_\___| + diff --git a/src/main/java/text-ui-test/input.txt b/src/main/java/text-ui-test/input.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/java/text-ui-test/runtest.bat b/src/main/java/text-ui-test/runtest.bat new file mode 100644 index 000000000..087374464 --- /dev/null +++ b/src/main/java/text-ui-test/runtest.bat @@ -0,0 +1,21 @@ +@ECHO OFF + +REM create bin directory if it doesn't exist +if not exist ..\bin mkdir ..\bin + +REM delete output from previous run +if exist ACTUAL.TXT del ACTUAL.TXT + +REM compile the code into the bin folder +javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +IF ERRORLEVEL 1 ( + echo ********** BUILD FAILURE ********** + exit /b 1 +) +REM no error here, errorlevel == 0 + +REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT +java -classpath ..\bin Duke < input.txt > ACTUAL.TXT + +REM compare the output to the expected output +FC ACTUAL.TXT EXPECTED.TXT diff --git a/src/main/java/text-ui-test/runtest.sh b/src/main/java/text-ui-test/runtest.sh new file mode 100644 index 000000000..c9ec87003 --- /dev/null +++ b/src/main/java/text-ui-test/runtest.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# create bin directory if it doesn't exist +if [ ! -d "../bin" ] +then + mkdir ../bin +fi + +# delete output from previous run +if [ -e "./ACTUAL.TXT" ] +then + rm ACTUAL.TXT +fi + +# compile the code into the bin folder, terminates if error occurred +if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java +then + echo "********** BUILD FAILURE **********" + exit 1 +fi + +# run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT +java -classpath ../bin Duke < input.txt > ACTUAL.TXT + +# convert to UNIX format +cp EXPECTED.TXT EXPECTED-UNIX.TXT +dos2unix ACTUAL.TXT EXPECTED-UNIX.TXT + +# compare the output to the expected output +diff ACTUAL.TXT EXPECTED-UNIX.TXT +if [ $? -eq 0 ] +then + echo "Test result: PASSED" + exit 0 +else + echo "Test result: FAILED" + exit 1 +fi \ No newline at end of file diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..18067e5e3 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,7 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +Qchat ,A truly humanized intelligent voice assistant +knows better about life and better about you +What can I do for you? +---------------------------------------------------------------- +--------------------------------------------- +Here are your current tasks in your list: +--------------------------------------------- diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..4e55d0655 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,7 @@ +list +add +todo stellaris + + + + diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..89bbcccba 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -6,8 +6,9 @@ if not exist ..\bin mkdir ..\bin REM delete output from previous run if exist ACTUAL.TXT del ACTUAL.TXT -REM compile the code into the bin folder javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java +REM compile the code into the bin folder + IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 @@ -15,7 +16,7 @@ IF ERRORLEVEL 1 ( REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Qchat < ./input.txt > ./ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT