Skip to content

Commit

Permalink
Add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
tingxuanp committed Oct 29, 2024
1 parent 4b1693f commit 795963a
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,49 +106,97 @@ public void parseCommand_exit() throws Exception {

@Test
public void parseCommand_findName() throws Exception {
List<String> keywords = Arrays.asList("foo", "bar", "baz");
List<String> keywords = Arrays.asList("foo");
FindNameCommand command = (FindNameCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " n/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " n/ foo");
assertEquals(new FindNameCommand(new NameContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultipleName() throws Exception {
List<String> keywords = Arrays.asList("Amy", "Bob", "Clarissa");
FindNameCommand command = (FindNameCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " n/Amy n/Bob n/Clarissa");
assertEquals(new FindNameCommand(new NameContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findAddress() throws Exception {
List<String> keywords = Arrays.asList("Jurong West Street");
FindAddressCommand command = (FindAddressCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " a/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " a/Jurong West Street");
assertEquals(new FindAddressCommand(new AddressContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultipleAddress() throws Exception {
List<String> keywords = Arrays.asList("Jurong West Street", "Tampines East");
FindAddressCommand command = (FindAddressCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " a/Jurong West Street a/Tampines East");
assertEquals(new FindAddressCommand(new AddressContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findEmail() throws Exception {
List<String> keywords = Arrays.asList("[email protected]");
FindEmailCommand command = (FindEmailCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " e/[email protected]");
assertEquals(new FindEmailCommand(new EmailContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultipleEmails() throws Exception {
List<String> keywords = Arrays.asList("[email protected]", "[email protected]");
FindEmailCommand command = (FindEmailCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " e/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " e/[email protected] e/[email protected]");
assertEquals(new FindEmailCommand(new EmailContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findPhone() throws Exception {
List<String> keywords = Arrays.asList("99394835");
FindPhoneCommand command = (FindPhoneCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " p/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " p/99394835");
assertEquals(new FindPhoneCommand(new PhoneContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultiplePhone() throws Exception {
List<String> keywords = Arrays.asList("99394835", "283384");
FindPhoneCommand command = (FindPhoneCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " p/99394835 p/283384");
assertEquals(new FindPhoneCommand(new PhoneContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findTag() throws Exception {
List<String> keywords = Arrays.asList("florist");
FindTagCommand command = (FindTagCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " t/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " t/florist");
assertEquals(new FindTagCommand(new TagContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultipleTags() throws Exception {
List<String> keywords = Arrays.asList("florist", "photographer");
FindTagCommand command = (FindTagCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " t/florist t/photographer");
assertEquals(new FindTagCommand(new TagContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findWedding() throws Exception {
List<String> keywords = Arrays.asList("Snoopy's", "wedding");
List<String> keywords = Arrays.asList("Snoopy's wedding");
FindWeddingCommand command = (FindWeddingCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " w/ Snoopy's wedding");
assertEquals(new FindWeddingCommand(new WeddingContainsKeywordsPredicate(keywords)), command);
}

@Test
public void parseCommand_findMultipleWeddings() throws Exception {
List<String> keywords = Arrays.asList("Snoopy's wedding", "Wedding 2029");
FindWeddingCommand command = (FindWeddingCommand) parser.parseCommand(
FindCommand.COMMAND_WORD + " w/" + keywords.stream().collect(Collectors.joining(" ")));
FindCommand.COMMAND_WORD + " w/Snoopy's wedding w/Wedding 2029");
assertEquals(new FindWeddingCommand(new WeddingContainsKeywordsPredicate(keywords)), command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ public void parse_missingPrefix_throwsParseException() {

@Test
public void parse_validFindNameArgs_returnsFindNameCommand() {
// no leading and trailing whitespaces
FindNameCommand expectedFindCommand =
new FindNameCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice")));
assertParseSuccess(parser, "find n/Alice", expectedFindCommand);

// search multiple names using multiple prefixes
assertParseSuccess(parser, "find n/ \n Alice \n \t \t", expectedFindCommand);
}

@Test
public void parse_validMultipleFindNameArgs_returnsFindNameCommand() {
// no leading and trailing whitespaces
FindNameCommand expectedFindCommand =
new FindNameCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")));
assertParseSuccess(parser, "find n/Alice Bob", expectedFindCommand);
assertParseSuccess(parser, "find n/Alice n/Bob", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, "find n/ \n Alice \n \t Bob \t", expectedFindCommand);
// search multiple names using multiple prefixes
assertParseSuccess(parser, "find n/ \n Alice \n \t n/ \tBob \t", expectedFindCommand);
}

@Test
Expand Down Expand Up @@ -143,6 +154,17 @@ public void parse_validFindPhoneArgs_returnsFindPhoneCommand() {
assertParseSuccess(parser, "find p/ \n91234567 \t", expectedFindCommand);
}

@Test
public void parse_validMultipleFindPhoneArgs_returnsFindPhoneCommand() {
// no leading and trailing whitespaces
FindPhoneCommand expectedFindCommand =
new FindPhoneCommand(new PhoneContainsKeywordsPredicate(Arrays.asList("91234567", "285")));
assertParseSuccess(parser, "find p/91234567 p/285", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, "find p/ \n91234567 \t p/\t 285", expectedFindCommand);
}

@Test
public void parse_missingPhoneAfterPrefix_throwsParseException() {
String input = "find p/"; // Nothing after phone prefix
Expand Down Expand Up @@ -177,6 +199,19 @@ public void parse_validFindEmailArgs_returnsFindEmailCommand() {
assertParseSuccess(parser, "find e/ \t [email protected]", expectedFindCommand);
}

@Test
public void parse_validMultipleFindEmailArgs_returnsFindEmailCommand() {
// no leading and trailing whitespaces
FindEmailCommand expectedFindCommand =
new FindEmailCommand(new EmailContainsKeywordsPredicate(Arrays.asList("[email protected]",
"[email protected]")));
assertParseSuccess(parser, "find e/[email protected] e/[email protected]", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, "find e/ \t [email protected] e/ \t [email protected]", expectedFindCommand);
}


@Test
public void parse_missingEmailAfterPrefix_throwsParseException() {
String input = "find e/"; // Nothing after email prefix
Expand Down Expand Up @@ -211,6 +246,17 @@ public void parse_validFindTagArgs_returnsFindTagCommand() {
assertParseSuccess(parser, "find t/ \t florist", expectedFindCommand);
}

@Test
public void parse_validMultipleFindTagArgs_returnsFindTagCommand() {
// no leading and trailing whitespaces
FindTagCommand expectedFindCommand =
new FindTagCommand(new TagContainsKeywordsPredicate(Arrays.asList("florist", "DJ")));
assertParseSuccess(parser, "find t/florist t/DJ", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, "find t/ \t florist t/ \t DJ", expectedFindCommand);
}

@Test
public void parse_missingTagAfterPrefix_throwsParseException() {
String input = "find t/"; // Nothing after tag prefix
Expand All @@ -237,11 +283,12 @@ public void parse_missingTagWithTrailingWhiteSpace_throwsParseException() {
public void parse_validFindWeddingArgs_returnsFindWeddingCommand() {
// no leading and trailing whitespaces
FindWeddingCommand expectedFindCommand =
new FindWeddingCommand(new WeddingContainsKeywordsPredicate(Arrays.asList("Dave's", "wedding")));
assertParseSuccess(parser, "find w/Dave's wedding", expectedFindCommand);
new FindWeddingCommand(new WeddingContainsKeywordsPredicate(Arrays.asList("Dave's wedding",
"Wedding 2")));
assertParseSuccess(parser, "find w/Dave's wedding w/Wedding 2", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, "find w/ \t Dave's wedding", expectedFindCommand);
assertParseSuccess(parser, "find w/ \t Dave's wedding w/ \t Wedding 2", expectedFindCommand);
}

@Test
Expand Down

0 comments on commit 795963a

Please sign in to comment.