Skip to content

Commit

Permalink
Refine search format, add JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yyihaoc committed Oct 17, 2024
1 parent 686751b commit 7c61d93
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@ public static boolean containsSubstringIgnoreCase(String sentence, String substr

String preppedSubstring = substring.trim();
checkArgument(!preppedSubstring.isEmpty(), "Word parameter cannot be empty");
checkArgument(preppedSubstring.split("\\s+").length == 1, "Word parameter should be a single word");

String preppedSentence = sentence;
String[] wordsInPreppedSentence = preppedSentence.split("\\s+");

return Arrays.stream(wordsInPreppedSentence)
.map(String::toLowerCase)
.anyMatch(word -> word.contains(substring.toLowerCase()));
return preppedSentence.toLowerCase().contains(substring.toLowerCase());

}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class FindCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
+ "Parameters: [n/nameKeyword] [r/roleKeyword] ...\n"
+ "Example: " + COMMAND_WORD + " n/alice tan n/bob r/member n/charlie";

private final NameContainsKeywordsPredicate namePredicate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public static boolean areSomePrefixesPresent(ArgumentMultimap argumentMultimap,
return Stream.of(prefixes).anyMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

@Test
public void parse_invalidPrefix_throwsParseException() {
assertParseFailure(parser, "t/chen", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

@Test
public void parse_nonEmptyPreamble_throwsParseException() {
assertParseFailure(parser, " some random preamble",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

@Test
public void parse_emptyArgumentAfterPrefix_throwsParseException() {
assertParseFailure(parser, "n/ ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
assertParseFailure(parser, "r/member n/ ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE));
}

@Test
public void parse_validArgs_returnsFindCommand() {
// no leading and trailing whitespaces
Expand All @@ -30,7 +49,8 @@ public void parse_validArgs_returnsFindCommand() {
assertParseSuccess(parser, " n/chen n/albert r/member r/exco ", expectedFindCommand);

// multiple whitespaces between keywords
// assertParseSuccess(parser, " n/Alice ", expectedFindCommand);
assertParseSuccess(parser, " \n n/ chen \n \t n/ albert \t r/ \t member r/ \n exco \t ",
expectedFindCommand);
}

}

0 comments on commit 7c61d93

Please sign in to comment.