Skip to content

Commit

Permalink
Add Automated Text UI Testing
Browse files Browse the repository at this point in the history
Testing for Jarvis is manual right now

Use a script to add automated text UI testing
  • Loading branch information
rgonslayer committed Aug 25, 2022
1 parent 6ba56ba commit 8e417e5
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/main/java/Jarvis.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public static void main(String[] args) throws JarvisException {
Scanner inputScanner = new Scanner(System.in);

String userInput;
String introduction = "Hello! I'm Jarvis \n"
+ "What can I do for you?";
String farewell = "Bye. Hope to see you again soon!";
String introduction = "Hello. I am Jarvis \n"
+ "What can I do for you today?";
String farewell = "Goodbye, have a good day.";

List<Task> taskList = new ArrayList<>();

Expand Down Expand Up @@ -37,15 +37,15 @@ public static void main(String[] args) throws JarvisException {
if (userInput.length() > 4 && userInput.substring(0, 4).equals("mark")) {
int toMark = Integer.parseInt(userInput.substring(5)) - 1;
taskList.get(toMark).mark();
String markResponse = "Nice! I've marked this task as done:\n ";
String markResponse = "Great. I have marked this task as done:\n ";
System.out.println(markResponse + taskList.get(toMark).toString());
continue;
}
//if userinput equals unmark, check which task and unmark
if (userInput.length() > 6 && userInput.substring(0, 6).equals("unmark")) {
int toMark = Integer.parseInt(userInput.substring(7)) - 1;
taskList.get(toMark).unmark();
String markResponse = "Ok, I've marked this task as not done yet:\n ";
String markResponse = "Ok, I have marked this task as not done yet:\n ";
System.out.println(markResponse + taskList.get(toMark).toString());
continue;
}
Expand All @@ -54,7 +54,7 @@ public static void main(String[] args) throws JarvisException {
int toDelete = Integer.parseInt(userInput.substring(7)) - 1;
Task deleteTask = taskList.get(toDelete);
taskList.remove(toDelete);
String deleteResponse = "Noted. I've removed this task:\n ";
String deleteResponse = "Noted. I have removed this task:\n ";
System.out.println(deleteResponse + deleteTask.toString());
continue;
}
Expand All @@ -68,6 +68,7 @@ public static void main(String[] args) throws JarvisException {
taskList.add(new ToDo(description));
System.out.println("Got it. I've added this task:\n " + taskList.get(Task.count - 1)
+ "\nNow you have " + (Task.count) + " tasks in the list.");
continue;
}

//if userinput equals deadline add new deadline task to list
Expand All @@ -78,6 +79,7 @@ public static void main(String[] args) throws JarvisException {
taskList.add(new Deadline(description, date));
System.out.println("Got it. I've added this task:\n " + taskList.get(Task.count - 1)
+ "\nNow you have " + (Task.count) + " tasks in the list.");
continue;
}
//if userinput equals event add new event task to list
if (userInput.length() > 7 && userInput.substring(0, 5).equals("event")) {
Expand All @@ -87,11 +89,12 @@ public static void main(String[] args) throws JarvisException {
taskList.add(new Event(description, date));
System.out.println("Got it. I've added this task:\n " + taskList.get(Task.count - 1)
+ "\nNow you have " + (Task.count) + " tasks in the list.");
continue;
}
throw new JarvisException("I'm sorry, but I don't know what that means");
}

System.out.println(farewell);
System.out.print(farewell);
}
catch (JarvisException e) {
System.out.println((e.toString()));
Expand Down
58 changes: 52 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
Hello. I am Jarvis
What can I do for you today?
Got it. I've added this task:
[T][ ] borrow book
Now you have 1 tasks in the list.
Got it. I've added this task:
[D][ ] return book (by: sunday)
Now you have 2 tasks in the list.
Got it. I've added this task:
[E][ ] project meeting (at: Aug 6th 2-4pm)
Now you have 3 tasks in the list.
Got it. I've added this task:
[T][ ] join sports club
Now you have 4 tasks in the list.
Got it. I've added this task:
[T][ ] read book
Now you have 5 tasks in the list.
Here are the tasks in your list:

1. [T][ ] borrow book
2. [D][ ] return book (by: sunday)
3. [E][ ] project meeting (at: Aug 6th 2-4pm)
4. [T][ ] join sports club
5. [T][ ] read book
Great. I have marked this task as done:
[D][X] return book (by: sunday)
Great. I have marked this task as done:
[E][X] project meeting (at: Aug 6th 2-4pm)
Here are the tasks in your list:

1. [T][ ] borrow book
2. [D][X] return book (by: sunday)
3. [E][X] project meeting (at: Aug 6th 2-4pm)
4. [T][ ] join sports club
5. [T][ ] read book
Ok, I have marked this task as not done yet:
[E][ ] project meeting (at: Aug 6th 2-4pm)
Here are the tasks in your list:

1. [T][ ] borrow book
2. [D][X] return book (by: sunday)
3. [E][ ] project meeting (at: Aug 6th 2-4pm)
4. [T][ ] join sports club
5. [T][ ] read book
Noted. I have removed this task:
[E][ ] project meeting (at: Aug 6th 2-4pm)
Here are the tasks in your list:

1. [T][ ] borrow book
2. [D][X] return book (by: sunday)
3. [T][ ] join sports club
4. [T][ ] read book
Goodbye, have a good day.
14 changes: 14 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
todo borrow book
deadline return book /by sunday
event project meeting /at Aug 6th 2-4pm
todo join sports club
todo read book
list
mark 2
mark 3
list
unmark 3
list
delete 3
list
bye
4 changes: 2 additions & 2 deletions text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ then
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
java -classpath ../bin Jarvis < 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
diff -w ACTUAL.TXT EXPECTED-UNIX.TXT
if [ $? -eq 0 ]
then
echo "Test result: PASSED"
Expand Down

0 comments on commit 8e417e5

Please sign in to comment.