Skip to content

Commit

Permalink
Merge pull request #54 from CS2103AUG2016-T11-C3/update-junit-test
Browse files Browse the repository at this point in the history
Merge update-junit-test branch
  • Loading branch information
zhijietan94 committed Oct 18, 2016
2 parents e61506b + c32254a commit b31620f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 73 deletions.
3 changes: 0 additions & 3 deletions .settings/org.eclipse.buildship.core.prefs
@@ -1,6 +1,3 @@
=\=\=\=\=\=\=
<<<<<<<=.merge_file_a03816
>>>>>>>=.merge_file_a08680
build.commands=org.eclipse.jdt.core.javabuilder
connection.arguments=
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
Expand Down
90 changes: 45 additions & 45 deletions src/main/java/seedu/address/logic/parser/Parser.java
Expand Up @@ -31,21 +31,21 @@ public class Parser {
+ "( d/(?<description>[^/]+)){0,1}"
+ "( date/(?<date>[^/]+)){0,1}"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags

private static final Pattern EDIT_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("(?<index>[\\d]+)"
+ "( (?<name>[^/]+)){0,1}"
+ "( d/(?<description>[^/]+)){0,1}"
+ "( date/(?<date>[^/]+)){0,1}"
+ "(?<tagArguments>(?: t/[^/]+)*)"); // variable number of tags
// private static final Pattern USA_DATE_FORMAT =
// Pattern.compile("(?<MM>(0?[1-9]|1[012]))"
// + "\\."
// + "(?<DD>(0?[1-9]|[12][0-9]|3[01]))"
// + "\\."
// + "(?<YY>\\d{2})");

// private static final Pattern USA_DATE_FORMAT =
// Pattern.compile("(?<MM>(0?[1-9]|1[012]))"
// + "\\."
// + "(?<DD>(0?[1-9]|[12][0-9]|3[01]))"
// + "\\."
// + "(?<YY>\\d{2})");

public Parser() {}

/**
Expand All @@ -72,10 +72,10 @@ public Command parseCommand(String userInput) {

case DeleteCommand.COMMAND_WORD:
return prepareDelete(arguments);

case EditCommand.COMMAND_WORD:
return prepareEdit(arguments);

case ClearCommand.COMMAND_WORD:
return new ClearCommand();

Expand Down Expand Up @@ -104,47 +104,47 @@ public Command parseCommand(String userInput) {
*/
private Command prepareAdd(String args){
final Matcher matcher = PERSON_DATA_ARGS_FORMAT.matcher(args.trim());

// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

try {
List<java.util.Date> dateList = nattyParse(matcher);
List<java.util.Date> dateList = nattyParse(matcher);

return new AddCommand(
matcher.group("name"),
matcher.group("description"),
dateList,
getTagsFromArgs(matcher.group("tagArguments"))
);
);
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
}
}

private List<java.util.Date> nattyParse(final Matcher matcher) throws IllegalValueException {
TimeZone tz = TimeZone.getDefault();
com.joestelmach.natty.Parser natty = new com.joestelmach.natty.Parser(tz);
List<java.util.Date> dateList;
// NPE could be thrown here -> floating task no date no time
// natty.parse() can return null too
if (matcher.group("date") == null){
// return empty list
dateList = new ArrayList <java.util.Date> ();
}
else if (natty.parse(matcher.group("date")).isEmpty()){
throw new IllegalValueException(seedu.address.model.person.Date.MESSAGE_DATE_CONSTRAINTS);
}
else {
dateList = natty.parse(matcher.group("date")).get(0).getDates();
}
return dateList;
}
private List<java.util.Date> nattyParse(final Matcher matcher) throws IllegalValueException {

TimeZone tz = TimeZone.getDefault();
com.joestelmach.natty.Parser natty = new com.joestelmach.natty.Parser(tz);
List<java.util.Date> dateList;

// NPE could be thrown here -> floating task no date no time
// natty.parse() can return null too
if (matcher.group("date") == null){
// return empty list
dateList = new ArrayList <java.util.Date> ();
}
else if (natty.parse(matcher.group("date")).isEmpty()){
throw new IllegalValueException(seedu.address.model.person.Date.MESSAGE_DATE_CONSTRAINTS);
}
else {
dateList = natty.parse(matcher.group("date")).get(0).getDates();
}

return dateList;
}

/**
* Extracts the new person's tags from the add command's tag arguments string.
Expand Down Expand Up @@ -176,34 +176,34 @@ private Command prepareDelete(String args) {

return new DeleteCommand(index.get());
}

/**
* Parses arguments in the context of the edit person command.
*
* @param args full command args string
* @return the prepared command
*/
private Command prepareEdit(String args) {

final Matcher matcher = EDIT_DATA_ARGS_FORMAT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}



try {
List<java.util.Date> dateList = nattyParse(matcher);
List<java.util.Date> dateList = nattyParse(matcher);

return new EditCommand(
Integer.parseInt(matcher.group("index")),
matcher.group("name"),
matcher.group("description"),
matcher.group("date"),
matcher.group("time"),
getTagsFromArgs(matcher.group("tagArguments"))
);
);
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
}
Expand Down
33 changes: 18 additions & 15 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -149,8 +150,6 @@ public void execute_clear() throws Exception {
@Test
public void execute_add_invalidArgsFormat() throws Exception {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE);
assertCommandBehavior(
"add wrong args wrong args", expectedMessage);
assertCommandBehavior(
"add Valid Name 12345 e/valid@email.butNoPhonePrefix a/valid, address", expectedMessage);
assertCommandBehavior(
Expand All @@ -162,13 +161,13 @@ public void execute_add_invalidArgsFormat() throws Exception {
@Test
public void execute_add_invalidPersonData() throws Exception {
assertCommandBehavior(
"add []\\[;] d/12345 date/11.11.11 time/1111", Name.MESSAGE_NAME_CONSTRAINTS);
assertCommandBehavior(
"add Valid Name d/can_be_anything date/not_valid_date time/1111", Date.MESSAGE_DATE_CONSTRAINTS);
"add []\\[;] d/12345 date/11-11-2018 1111", Name.MESSAGE_NAME_CONSTRAINTS);
assertCommandBehavior(
"add Valid Name d/can_be_anything date/11.11.11 time/5678", Time.MESSAGE_TIME_CONSTRAINTS);
"add Valid Name d/can_be_anything date/ab-cd-ef", Date.MESSAGE_DATE_CONSTRAINTS);
//TODO assertCommandBehavior(
// "add Valid Name d/can_be_anything date/11-11-2018 5678pm", Time.MESSAGE_TIME_CONSTRAINTS);
assertCommandBehavior(
"add Valid Name d/can_be_anything date/11.11.11 time/1111 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS);
"add Valid Name d/can_be_anything date/11-11-2018 1111 t/invalid_-[.tag", Tag.MESSAGE_TAG_CONSTRAINTS);

}

Expand Down Expand Up @@ -370,8 +369,10 @@ class TestDataHelper{
Task adam() throws Exception {
Name name = new Name("Adam Brown");
Description privatePhone = new Description("111111");
Date email = new Date("11.11.11");
Time privateAddress = new Time("1111");
List<java.util.Date> dateList =
(new com.joestelmach.natty.Parser(TimeZone.getDefault())).parse("11-11-2011 1111").get(0).getDates();
Date email = new Date(dateList);
Time privateAddress = new Time(dateList);
Tag tag1 = new Tag("tag1");
Tag tag2 = new Tag("tag2");
UniqueTagList tags = new UniqueTagList(tag1, tag2);
Expand All @@ -389,7 +390,7 @@ Task generatePerson(int seed) throws Exception {
return new Task(
new Name("Person " + seed),
new Description("" + Math.abs(seed)),
new Date("11.11.1" + seed),
new Date("11.11.201" + seed),
new Time("111" + seed),
new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1)))
);
Expand All @@ -403,8 +404,8 @@ String generateAddCommand(Task p) {

cmd.append(p.getName().toString());
cmd.append(" d/").append(p.getDescription());
cmd.append(" date/").append(p.getDate());
cmd.append(" time/").append(p.getTime());
cmd.append(" date/").append(p.getDate().toString().replace('.', '-'));
cmd.append(" ").append(p.getTime());

UniqueTagList tags = p.getTags();
for(Tag t: tags){
Expand Down Expand Up @@ -485,11 +486,13 @@ List<Task> generatePersonList(Task... persons) {
* Generates a Person object with given name. Other fields will have some dummy values.
*/
Task generatePersonWithName(String name) throws Exception {
List<java.util.Date> dateList =
(new com.joestelmach.natty.Parser(TimeZone.getDefault())).parse("10-11-2019 1111").get(0).getDates();
return new Task(
new Name(name),
new Description("1"),
new Date("11.11.11"),
new Time("1111"),
new Description("Describes task"),
new Date(dateList),
new Time(dateList),
new UniqueTagList(new Tag("tag"))
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/seedu/address/testutil/TestUtil.java
Expand Up @@ -67,13 +67,13 @@ private static Task[] getSamplePersonData() {
return new Task[]{
new Task(new Name("Ali Muster"), new Description("Meet for dinner"), new Date(""), new Time(""), new UniqueTagList()),
new Task(new Name("Boris Mueller"), new Description("Meet for lunch"), new Date(""), new Time(""), new UniqueTagList()),
new Task(new Name("Carl Kurz"), new Description("Meet for breakfast"), new Date("11.11.17"), new Time("2234"), new UniqueTagList()),
new Task(new Name("Daniel Meier"), new Description("Meet for lunch"), new Date("09.09.17"), new Time("2200"), new UniqueTagList()),
new Task(new Name("Elle Meyer"), new Description("Meet for lunch"), new Date("10.10.17"), new Time("2300"), new UniqueTagList()),
new Task(new Name("Fiona Kunz"), new Description("Meet for dinner"), new Date("10.10.17"), new Time("2254"), new UniqueTagList()),
new Task(new Name("Carl Kurz"), new Description("Meet for breakfast"), new Date("11.11.2017"), new Time("2234"), new UniqueTagList()),
new Task(new Name("Daniel Meier"), new Description("Meet for lunch"), new Date("09.09.2017"), new Time("2200"), new UniqueTagList()),
new Task(new Name("Elle Meyer"), new Description("Meet for lunch"), new Date("10.10.2017"), new Time("2300"), new UniqueTagList()),
new Task(new Name("Fiona Kunz"), new Description("Meet for dinner"), new Date("10.10.2017"), new Time("2254"), new UniqueTagList()),
new Task(new Name("George Best"), new Description("Meet for breakfast"), new Date(""), new Time(""), new UniqueTagList()),
new Task(new Name("Hoon Meier"), new Description("Meet for dinner"), new Date("01.01.17"), new Time("2101"), new UniqueTagList()),
new Task(new Name("Ida Mueller"), new Description("Meet for breakfast"), new Date("09.05.17"), new Time("2130"), new UniqueTagList())
new Task(new Name("Hoon Meier"), new Description("Meet for dinner"), new Date("01.01.2017"), new Time("2101"), new UniqueTagList()),
new Task(new Name("Ida Mueller"), new Description("Meet for breakfast"), new Date("09.05.2017"), new Time("2130"), new UniqueTagList())
};
} catch (IllegalValueException e) {
assert false;
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/testutil/TypicalTestTasks.java
Expand Up @@ -14,11 +14,11 @@ public class TypicalTestTasks {
public TypicalTestTasks() {
try {
one = new DatedTaskBuilder().withName("buy milk").withDescription("lots of it")
.withDate("11.11.11").withTime("1111").build();
.withDate("11.11.2017").withTime("1111").build();
two = new DatedTaskBuilder().withName("buy some milk").withDescription("not so much")
.withDate("11.11.11").withTime("1111").build();
three = new DatedTaskBuilder().withName("buy some milk").withDescription("not so much")
.withDate("12.12.12").withTime("1111").build();
.withDate("11.11.2017").withTime("1111").build();
three = new DatedTaskBuilder().withName("buy some milk").withDescription("just a little")
.withDate("12.12.2017").withTime("1111").build();



Expand Down

0 comments on commit b31620f

Please sign in to comment.