Skip to content

Commit

Permalink
Merge pull request #162 from CS2103AUG2016-W09-C3/Refactoring_EditCom…
Browse files Browse the repository at this point in the history
…mandv0.5

Made changes to naming conventions in tests - Shaun
  • Loading branch information
qiwei24 committed Nov 5, 2016
2 parents cf80298 + 331fa0d commit 9e3a791
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 80 deletions.
194 changes: 142 additions & 52 deletions src/test/java/guitests/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
package guitests;

import static org.junit.Assert.assertTrue;
import static todoit.taskbook.logic.commands.DoneCommand.MESSAGE_SUCCESS;

import org.junit.Test;

import todoit.taskbook.commons.core.Messages;
import todoit.taskbook.commons.exceptions.IllegalValueException;
import todoit.taskbook.logic.commands.EditCommand;
import todoit.taskbook.logic.commands.FindCommand;
import todoit.taskbook.logic.parser.CommandParser;
import todoit.taskbook.logic.parser.ParsedCommand;
import todoit.taskbook.model.task.DateTime;
Expand All @@ -26,136 +23,229 @@
public class EditCommandTest extends TaskBookGuiTest {

@Test
public void edit_nonDatedTask(){
// Check if edit function edits successfully (not necessary in sequence)
public void editCommand_nonDatedTask_Success(){
// Check if edit function edits non-dated task parameters successfully (not necessary in sequence)
TestTask[] listToEdit = td.getTypicalTasks();

String command = "edit 1 n/King Arthur p/high i/This is just another kind of information you would see in a task";
assertEditSuccess(command, listToEdit);

command = "edit 1 n/For camelot";
assertEditSuccess(command, listToEdit);

command = "edit 1 p/verylow";
assertEditSuccess(command, listToEdit);

command = "edit 1 i/New information";
assertEditSuccess(command, listToEdit);
}

@Test
public void edit_priorityHigh(){
// Check if edit function edits successfully (not necessary in sequence)
public void editCommand_datedTask_Success(){
// Check if edit function edits dated task parameters successfully (not necessary in sequence)
TestTask[] listToEdit = td.getTypicalTasks();
String command = "edit 1 p/h";
assertEditSuccess(command, listToEdit);
commandBox.runCommand(td.dinnerDate.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;

TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
String command = "edit 8 n/For camelot";
assertEditSuccess(command, finalList);

finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
command = "edit 8 d/tmr 9pm l/3h";
assertEditSuccess(command, finalList);

finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
command = "edit 8 r/2d";
assertEditSuccess(command, finalList);

finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
command = "edit 8 p/veryhigh";
assertEditSuccess(command, finalList);

finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
command = "edit 8 i/New information (Dated task)";
assertEditSuccess(command, finalList);
}

@Test
public void edit_invalidPriorityVeryHigh(){
// Check if edit function edits successfully (not necessary in sequence)
public void editCommand_priority_Success(){
// Check if edit function edits priority successfully (From very high to very low)
TestTask[] listToEdit = td.getTypicalTasks();
String command = "edit 2 p/superhigh";
unknownCommandFormatPriority(command);

String command = "edit 1 p/vh";
assertEditSuccess(command, listToEdit);

command = "edit 1 p/h";
assertEditSuccess(command, listToEdit);

command = "edit 1 p/m";
assertEditSuccess(command, listToEdit);

command = "edit 1 p/l";
assertEditSuccess(command, listToEdit);

command = "edit 1 p/vl";
assertEditSuccess(command, listToEdit);
}

@Test
public void edit_priorityVeryLow(){
// Check if edit function edits successfully (not necessary in sequence)
TestTask[] listToEdit = td.getTypicalTasks();
public void editCommand_invalidPriority_UnknownCommandFormat(){
// Check if edit function throws unknown command properly (priority)
String command = "edit 2 p/superhigh";
unknownCommandFormatPriority(command);

String command = "edit 1 p/vl";
assertEditSuccess(command, listToEdit);
command = "edit 2 p/hihg";
unknownCommandFormatPriority(command);

command = "edit 2 p/p/superhigh";
unknownCommandFormatPriority(command);
}

@Test
public void edit_priorityCaseSensitive(){
// Check if edit function edits successfully (not necessary in sequence)
public void editCommand_priorityCaseSensitive_Success(){
// Check if edit function is able to take in case insensitive priorities
TestTask[] listToEdit = td.getTypicalTasks();

String command = "edit 3 p/vH";
assertEditSuccess(command, listToEdit);

command = "edit 3 p/M";
assertEditSuccess(command, listToEdit);

command = "edit 3 p/VERYHIGH";
assertEditSuccess(command, listToEdit);

command = "edit 3 p/vErYlOw";
assertEditSuccess(command, listToEdit);
}

@Test
public void edit_invalidTimeIntervalRecurrence(){
// Check if edit function edits successfully (not necessary in sequence)
TestTask[] listToEdit = td.getTypicalTasks();
public void editCommand_invalidTimeIntervalRecurrence_UnknownCommandFormat(){
// Check if edit function throws unknown command properly (recurrence)
commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;
TestTask datedTaskToAdd2 = td.csFinalExam;
String command = "edit 9 r/3dayzz";
String command = "edit 8 r/3dayzz";
unknownCommandFormatTimeInterval(command);

command = "edit 8 r/ThreeDays";
unknownCommandFormatTimeInterval(command);
}

@Test
public void edit_datedTaskTimeIntervalRecurrenceDays(){
public void editCommand_datedTaskTimeIntervalRecurrenceDays_Success(){
// Check if program is able to edit all tasks in sequence
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;
TestTask datedTaskToAdd2 = td.csFinalExam;
TestTask datedTaskToAdd = td.csFinalExam;

String command = "edit 8 n/Meet Isabel p/High r/3days d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd, datedTaskToAdd2);
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);

assertEditSuccess(command, finalList);
}

@Test
public void edit_datedTaskTimeIntervalRecurrenceWeeks(){
public void editCommand_datedTaskTimeIntervalRecurrenceWeeks_Success(){
// Check if program is able to edit all tasks in sequence
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;
TestTask datedTaskToAdd2 = td.csFinalExam;

String command = "edit 8 n/Meet Isabel p/High r/6weeks d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd, datedTaskToAdd2);
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);

assertEditSuccess(command, finalList);
}

@Test
public void edit_recurrenceAndPriorityAlias(){
public void editCommand_changingTagsOnTasks_Success(){
// Check if program is able to edit all tasks in sequence
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;
TestTask datedTaskToAdd2 = td.csFinalExam;
String command = "edit 8 n/Meet KappaRoss p/vH r/6weeks d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd, datedTaskToAdd2);

String command = "edit 1 t/boss";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);

assertEditSuccess(command, finalList);
}

@Test
public void editCommand_priorityAlias_Success(){
// Check if edit function is able to take in aliases for recurrence
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;

String command = "edit 8 n/Meet KappaRoss p/vl r/6w d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
assertEditSuccess(command, finalList);

command = "edit 8 n/Meet KappaRoss p/h r/6w d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
assertEditSuccess(command, finalList);
}

@Test
public void editCommand_recurrenceAlias_Success(){
// Check if edit function is able to take in aliases for priority
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;

String command = "edit 8 n/Meet KappaRoss p/veryhigh r/6week d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
assertEditSuccess(command, finalList);

command = "edit 8 n/Meet KappaRoss p/veryhigh r/11weeks d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);
assertEditSuccess(command, finalList);
}

@Test
public void edit_invalidIndex(){
public void editCommand_invalidIndex_invalidCommand(){
// Check if program handles invalid index properly with a thrown message
String command = "edit 99 n/King Arthur's birthday i/This is just another information";
assertInvalidIndex(command);

commandBox.runCommand("clear");
String command = "edit 1 n/King Arthur's birthday i/This is just another information";

command = "edit 1 n/King Arthur's birthday i/This is just another information";
assertInvalidIndex(command);

}

@Test
public void edit_invalidEditCommandFormat(){
public void editCommand_invalidFormat_invalidEditFormat(){
// Check if program handles invalid edit format properly with a thrown message
String command = "edit";
assertInvalidEditCommandFormat(command);
}


@Test
public void edit_nonDatedTaskNotInSequence(){
// Check if program is able to edit a task in the middle of list
public void editCommand_nonDatedTaskNotInSequence_Success(){
// Check if program is able to edit a non-dated task in the middle of list with tasks not in sequence
TestTask[] listToEdit = td.getTypicalTasks();
String command = "edit 3 i/This is also an information p/high";
assertEditSuccess(command, listToEdit);
}

@Test
public void edit_datedTask(){
// Check if program is able to edit all tasks in sequence
public void editCommand_datedTaskNotInSequence_Success(){
// Check if program is able to edit a dated task in the middle of list with tasks not in sequence
TestTask[] listToEdit = td.getTypicalTasks();
commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
TestTask datedTaskToAdd = td.dinnerDate;
TestTask datedTaskToAdd2 = td.csFinalExam;

String command = "edit 8 n/Meet Isabel p/High r/6d d/01-01-2017 18:00 i/Meet up for CS2101 briefing";
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd, datedTaskToAdd2);
TestTask[] finalList = TestUtil.addTasksToList(listToEdit, datedTaskToAdd);

assertEditSuccess(command, finalList);
}

/**
* Helper methods start here
*/
private TestTask[] doEdit(String args, TestTask[] list) {
// To get different commands from the command input
String[] split = args.split("\\s+");
Expand Down
33 changes: 5 additions & 28 deletions src/test/java/guitests/RecurrenceTest.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
//@@author A0139947L
package guitests;

import static org.junit.Assert.*;

import org.junit.Test;

import todoit.taskbook.commons.exceptions.IllegalValueException;
import todoit.taskbook.model.TaskBook;
import todoit.taskbook.model.task.DateTime;
import todoit.taskbook.model.task.ReadOnlyDatedTask;
import todoit.taskbook.model.task.UniqueTaskList;
import todoit.taskbook.testutil.TestTask;
import todoit.taskbook.testutil.TestUtil;


public class RecurrenceTest extends TaskBookGuiTest {

@Test
// Updating recurrence
public void checkRecurrenceDone() {
public void recurrence_checkRecurrenceOnStartUp_Success() {
TaskBook tasks = getInitialData();
commandBox.runCommand("done 1");

commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.meetingToAttend.getAddCommand());
commandBox.runCommand("done 7");

DateTime csFinalExamToAdd = td.csFinalExam.getDateTime();
tasks.updateRecurringTasks();

assertFalse(tasks.getUniqueTaskList().getInternalList().get(6).equals(td.csFinalExam) && !td.csFinalExam.getDateTime().equals(csFinalExamToAdd));
assertRecurringSuccess(tasks);
}

@Test
// Without updating recurrence
public void checkRecurrenceFalse() {
public void recurrence_checkRecurrenceOnStartUp_Fail() {
TaskBook tasks = getInitialData();

commandBox.runCommand(td.dinnerDate.getAddCommand());
commandBox.runCommand(td.csFinalExam.getAddCommand());
commandBox.runCommand(td.meetingToAttend.getAddCommand());

commandBox.runCommand("done 7");

DateTime csFinalExamToAdd = td.csFinalExam.getDateTime();

assertFalse(!tasks.getUniqueTaskList().getInternalList().get(6).equals(td.csFinalExam) && !td.csFinalExam.getDateTime().equals(csFinalExamToAdd));
commandBox.runCommand("done 1");

assertRecurringSuccess(tasks);
}

Expand Down

0 comments on commit 9e3a791

Please sign in to comment.