From 1ce4421f80d3ed2390528e9495202cca18105c28 Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 05:45:38 +0800 Subject: [PATCH 1/7] Revamp Find Command --- .../address/logic/commands/FindCommand.java | 16 +- .../address/logic/commands/FindOrCommand.java | 43 ++++ .../logic/parser/AddressBookParser.java | 5 + .../logic/parser/FindCommandParser.java | 28 ++- .../logic/parser/FindOrCommandParser.java | 54 +++++ .../address/model/person/FindOrPredicate.java | 52 +++++ .../address/model/person/FindPredicate.java | 47 +++++ .../address/ui/BirthdayReminderCard.java | 3 +- .../logic/commands/FindCommandTest.java | 128 ++++++++++-- .../logic/commands/FindOrCommandTest.java | 186 ++++++++++++++++++ .../logic/parser/AddressBookParserTest.java | 50 +++-- .../logic/parser/FindCommandParserTest.java | 23 ++- .../logic/parser/FindOrCommandParserTest.java | 38 ++++ 13 files changed, 615 insertions(+), 58 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/FindOrCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/FindOrCommandParser.java create mode 100644 src/main/java/seedu/address/model/person/FindOrPredicate.java create mode 100644 src/main/java/seedu/address/model/person/FindPredicate.java create mode 100644 src/test/java/seedu/address/logic/commands/FindOrCommandTest.java create mode 100644 src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index d6b19b0a0de..5e1cec6c25b 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -1,10 +1,12 @@ package seedu.address.logic.commands; + import static java.util.Objects.requireNonNull; import seedu.address.commons.core.Messages; import seedu.address.model.Model; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.FindPredicate; + /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -19,16 +21,16 @@ public class FindCommand extends Command { + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " alice bob charlie"; - private final NameContainsKeywordsPredicate predicate; + private final FindPredicate findPredicate; - public FindCommand(NameContainsKeywordsPredicate predicate) { - this.predicate = predicate; + public FindCommand(FindPredicate findPredicate) { + this.findPredicate = findPredicate; } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredPersonList(predicate); + model.updateFilteredPersonList(findPredicate); return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); } @@ -36,7 +38,7 @@ public CommandResult execute(Model model) { @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof FindCommand // instanceof handles nulls - && predicate.equals(((FindCommand) other).predicate)); // state check + || ((other instanceof FindCommand) // instanceof handles nulls + && findPredicate.equals(((FindCommand) other).findPredicate)); // state check } } diff --git a/src/main/java/seedu/address/logic/commands/FindOrCommand.java b/src/main/java/seedu/address/logic/commands/FindOrCommand.java new file mode 100644 index 00000000000..be24a0d551b --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/FindOrCommand.java @@ -0,0 +1,43 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.core.Messages; +import seedu.address.model.Model; +import seedu.address.model.person.FindOrPredicate; + + +/** + * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Keyword matching is case insensitive. + */ +public class FindOrCommand extends Command { + + public static final String COMMAND_WORD = "findOr"; + + 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"; + + private final FindOrPredicate findOrPredicate; + + public FindOrCommand(FindOrPredicate findOrPredicate) { + this.findOrPredicate = findOrPredicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredPersonList(findOrPredicate); + return new CommandResult( + String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || ((other instanceof FindOrCommand) // instanceof handles nulls + && findOrPredicate.equals(((FindOrCommand) other).findOrPredicate)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 72c95e69e8a..7f62697b0ca 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -14,6 +14,7 @@ import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.FindOrCommand; import seedu.address.logic.commands.FindTagCaseInsensitiveCommand; import seedu.address.logic.commands.FindTagCaseSensitiveCommand; import seedu.address.logic.commands.HelpCommand; @@ -73,6 +74,10 @@ public Command parseCommand(String userInput) throws ParseException { case FindCommand.COMMAND_WORD: return new FindCommandParser().parse(arguments); + + case FindOrCommand.COMMAND_WORD: + return new FindOrCommandParser().parse(arguments); + case ListCommand.COMMAND_WORD: return new ListCommand(); diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 4fb71f23103..b3ee54fab89 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -1,12 +1,17 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import seedu.address.logic.commands.FindCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.FindPredicate; +import seedu.address.model.person.Name; +import seedu.address.model.tag.Tag; /** * Parses input arguments and creates a new FindCommand object @@ -25,9 +30,22 @@ public FindCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); } - String[] nameKeywords = trimmedArgs.split("\\s+"); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TAG); + List nameStringList = argMultimap.getAllValues(PREFIX_NAME); + List tagStringList = argMultimap.getAllValues(PREFIX_TAG); + + List nameKeywords; + List tagList; + try { + nameKeywords = nameStringList.stream().map(Name::new).collect(Collectors.toList()); + tagList = tagStringList.stream().map(Tag::new).collect(Collectors.toList()); + } catch (IllegalArgumentException e) { + throw new ParseException(e.getMessage()); + } - return new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } + FindPredicate findpredicate = new FindPredicate(nameKeywords, tagList); + return new FindCommand(findpredicate); + } } diff --git a/src/main/java/seedu/address/logic/parser/FindOrCommandParser.java b/src/main/java/seedu/address/logic/parser/FindOrCommandParser.java new file mode 100644 index 00000000000..8f53d0d1d1f --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/FindOrCommandParser.java @@ -0,0 +1,54 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; + +import java.util.List; +import java.util.stream.Collectors; + +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.FindOrCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.FindOrPredicate; +import seedu.address.model.person.Name; +import seedu.address.model.tag.Tag; + +/** + * Parses input arguments and creates a new FindCommand object + */ +public class FindOrCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FindOrCommand + * and returns a FindOrCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public FindOrCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + } + + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TAG); + List nameStringList = argMultimap.getAllValues(PREFIX_NAME); + List tagStringList = argMultimap.getAllValues(PREFIX_TAG); + + List nameKeywords; + List tagList; + try { + nameKeywords = nameStringList.stream().map(Name::new).collect(Collectors.toList()); + tagList = tagStringList.stream().map(Tag::new).collect(Collectors.toList()); + } catch (IllegalArgumentException e) { + throw new ParseException(e.getMessage()); + } + + FindOrPredicate findOrPredicate = new FindOrPredicate(nameKeywords, tagList); + return new FindOrCommand(findOrPredicate); + } + +} + diff --git a/src/main/java/seedu/address/model/person/FindOrPredicate.java b/src/main/java/seedu/address/model/person/FindOrPredicate.java new file mode 100644 index 00000000000..7d6ad898b66 --- /dev/null +++ b/src/main/java/seedu/address/model/person/FindOrPredicate.java @@ -0,0 +1,52 @@ +package seedu.address.model.person; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; +import seedu.address.model.tag.Tag; + +/** + * Tests that a {@code Person}'s {@code Name} OR {@code Tag} matches all of the tags given. + */ +public class FindOrPredicate implements Predicate { + + private final List nameList; + private final List tagList; + + /** + * Creates a FindOrPredicate + * + * @param nameList refers to the list of Names to be searched for + * @param tagList refers to the list of Tags to be searched for + */ + public FindOrPredicate(List nameList, List tagList) { + this.nameList = nameList; + this.tagList = tagList; + } + + @Override + public boolean test(Person person) { + Tag[] arrayTags = new Tag[person.getTags().toArray().length]; + if (!nameList.isEmpty()) { + return nameList.stream() + .anyMatch(name -> StringUtil.containsWordIgnoreCase(person.getName().fullName, name.fullName) + || tagList.stream() + .anyMatch(tag -> Arrays.stream(person.getTags().toArray(arrayTags)) + .anyMatch(personTag -> personTag.compareTag(tag, false)))); + } else { + return tagList.stream() + .anyMatch(tag -> Arrays.stream(person.getTags().toArray(arrayTags)) + .anyMatch(personTag -> personTag.compareTag(tag, false))); + } + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof FindOrPredicate) // instanceof handles nulls + && (nameList.equals(((FindOrPredicate) other).nameList) + && tagList.equals(((FindOrPredicate) other).tagList)); // state check + } +} diff --git a/src/main/java/seedu/address/model/person/FindPredicate.java b/src/main/java/seedu/address/model/person/FindPredicate.java new file mode 100644 index 00000000000..0e2ab7aff80 --- /dev/null +++ b/src/main/java/seedu/address/model/person/FindPredicate.java @@ -0,0 +1,47 @@ +package seedu.address.model.person; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; +import seedu.address.model.tag.Tag; + + +/** + * Tests that a {@code Person}'s {@code Name} AND {@code Tag} matches all of the tags given. + */ +public class FindPredicate implements Predicate { + + private final List nameList; + private final List tagList; + + /** + * Creates a FindPredicate + * + * @param nameList refers to the list of Names to be searched for + * @param tagList refers to the list of Tags to be searched for + */ + public FindPredicate(List nameList, List tagList) { + this.nameList = nameList; + this.tagList = tagList; + } + + @Override + public boolean test(Person person) { + Tag[] arrayTags = new Tag[person.getTags().toArray().length]; + return nameList.stream() + .allMatch(name -> StringUtil.containsWordIgnoreCase(person.getName().fullName, name.fullName)) + && tagList.stream() + .allMatch(tag -> Arrays.stream(person.getTags().toArray(arrayTags)) + .anyMatch(personTag-> personTag.compareTag(tag, false))); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof FindPredicate) // instanceof handles nulls + && (nameList.equals(((FindPredicate) other).nameList) + && tagList.equals(((FindPredicate) other).tagList)); // state check + } +} diff --git a/src/main/java/seedu/address/ui/BirthdayReminderCard.java b/src/main/java/seedu/address/ui/BirthdayReminderCard.java index db90beb6b9d..665180a5caf 100644 --- a/src/main/java/seedu/address/ui/BirthdayReminderCard.java +++ b/src/main/java/seedu/address/ui/BirthdayReminderCard.java @@ -9,6 +9,7 @@ import seedu.address.model.person.Birthday; import seedu.address.model.person.Person; + public class BirthdayReminderCard extends UiPart { private static final String FXML = "BirthdayReminderListCard.fxml"; @@ -41,7 +42,7 @@ public BirthdayReminderCard(Person person) { phone.setText(person.getPhoneNumber()); Optional possibleBirthday = person.getBirthday(); assert possibleBirthday.isPresent(); - birthday.setText(possibleBirthday.map(Birthday::display).get()); + birthday.setText(possibleBirthday.map(Birthday::display).orElse("")); } @Override diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index 9b15db28bbb..f6abb962d86 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -3,22 +3,32 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.CARL; +import static seedu.address.testutil.TypicalPersons.DANIEL; import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.FIONA; +import static seedu.address.testutil.TypicalPersons.GEORGE; +import static seedu.address.testutil.TypicalPersons.HANNAH; +import static seedu.address.testutil.TypicalPersons.HANNAH_NO_BIRTHDAY; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.util.Arrays; import java.util.Collections; - -import org.junit.jupiter.api.Test; +import java.util.List; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.person.FindPredicate; +import seedu.address.model.person.Name; import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.tag.Tag; + /** * Contains integration tests (interaction with the Model) for {@code FindCommand}. @@ -29,10 +39,12 @@ public class FindCommandTest { @Test public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); + List firstNameList = List.of(new Name(CARL.getFullName())); + List firstTagList = List.of(new Tag("football"), new Tag("friends")); + List secondNameList = List.of(new Name(ELLE.getFullName())); + List secondTagList = List.of(new Tag("colleagues")); + FindPredicate firstPredicate = new FindPredicate(firstNameList, firstTagList); + FindPredicate secondPredicate = new FindPredicate(secondNameList, secondTagList); FindCommand findFirstCommand = new FindCommand(firstPredicate); FindCommand findSecondCommand = new FindCommand(secondPredicate); @@ -55,23 +67,111 @@ public void equals() { } @Test - public void execute_zeroKeywords_noPersonFound() { + public void execute_nonExistentName_noPersonFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); - NameContainsKeywordsPredicate predicate = preparePredicate(" "); - FindCommand command = new FindCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); + List firstNameList = List.of(new Name("zeke")); + List firstTagList = List.of(); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Collections.emptyList(), model.getFilteredPersonList()); } @Test - public void execute_multipleKeywords_multiplePersonsFound() { + public void execute_oneExistentName_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(new Name("benson")); + List firstTagList = List.of(); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(BENSON), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentName_twoPersonsFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); + List firstNameList = List.of(new Name("hannah")); + List firstTagList = List.of(); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(HANNAH, HANNAH_NO_BIRTHDAY), model.getFilteredPersonList()); + } + + @Test + public void execute_twoExistentName_noPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + List firstNameList = List.of(new Name("alice"), new Name("benson")); + List firstTagList = List.of(); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test + public void execute_nonExistentTag_noPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("Chef")); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentTag_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("football")); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(GEORGE), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentTag_multiplePersonsFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("friends")); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); + } + + @Test + public void execute_multipleExistentTag_multiplePersonsFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("friends"), new Tag("owesMoney")); + FindPredicate findPredicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(BENSON, DANIEL), model.getFilteredPersonList()); + } + + @Test + public void execute_nameAndTag_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(new Name("benson")); + List firstTagList = List.of(new Tag("friends")); + FindPredicate predicate = new FindPredicate(firstNameList, firstTagList); FindCommand command = new FindCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList()); + assertEquals(Arrays.asList(BENSON), model.getFilteredPersonList()); } /** diff --git a/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java new file mode 100644 index 00000000000..8baf3163c16 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java @@ -0,0 +1,186 @@ +package seedu.address.logic.commands; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; +import static seedu.address.testutil.TypicalPersons.CARL; +import static seedu.address.testutil.TypicalPersons.DANIEL; +import static seedu.address.testutil.TypicalPersons.ELLE; +import static seedu.address.testutil.TypicalPersons.GEORGE; +import static seedu.address.testutil.TypicalPersons.HANNAH; +import static seedu.address.testutil.TypicalPersons.HANNAH_NO_BIRTHDAY; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.FindOrPredicate; +import seedu.address.model.person.FindPredicate; +import seedu.address.model.person.Name; +import seedu.address.model.tag.Tag; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + + +public class FindOrCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void equals() { + List firstNameList = List.of(new Name(CARL.getFullName())); + List firstTagList = List.of(new Tag("football"), new Tag("friends")); + List secondNameList = List.of(new Name(ELLE.getFullName())); + List secondTagList = List.of(new Tag("colleagues")); + FindOrPredicate firstPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrPredicate secondPredicate = new FindOrPredicate(secondNameList, secondTagList); + + FindOrCommand findFirstCommand = new FindOrCommand(firstPredicate); + FindOrCommand findSecondCommand = new FindOrCommand(secondPredicate); + + // same object -> returns true + assertTrue(findFirstCommand.equals(findFirstCommand)); + + // same values -> returns true + FindOrCommand findFirstCommandCopy = new FindOrCommand(firstPredicate); + assertTrue(findFirstCommand.equals(findFirstCommandCopy)); + + // different types -> returns false + assertFalse(findFirstCommand.equals(1)); + + // null -> returns false + assertFalse(findFirstCommand.equals(null)); + + // different person -> returns false + assertFalse(findFirstCommand.equals(findSecondCommand)); + } + + @Test + public void execute_nonExistentName_noPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + List firstNameList = List.of(new Name("zeke")); + List firstTagList = List.of(); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentName_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(new Name("benson")); + List firstTagList = List.of(); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(BENSON), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentName_twoPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); + List firstNameList = List.of(new Name("hannah")); + List firstTagList = List.of(); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(HANNAH, HANNAH_NO_BIRTHDAY), model.getFilteredPersonList()); + } + + @Test + public void execute_twoExistentName_noPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); + List firstNameList = List.of(new Name("alice"), new Name("benson")); + List firstTagList = List.of(); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON), model.getFilteredPersonList()); + } + + @Test + public void execute_nonExistentTag_noPersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("Chef")); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentTag_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("football")); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(GEORGE), model.getFilteredPersonList()); + } + + @Test + public void execute_oneExistentTag_multiplePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("friends")); + FindOrPredicate findOrPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findOrPredicate); + expectedModel.updateFilteredPersonList(findOrPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); + } + + @Test + public void execute_multipleExistentTag_multiplePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); + List firstNameList = List.of(); + List firstTagList = List.of(new Tag("friends"), new Tag("owesMoney")); + FindOrPredicate findPredicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(findPredicate); + expectedModel.updateFilteredPersonList(findPredicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON, DANIEL), model.getFilteredPersonList()); + } + + @Test + public void execute_nameAndTag_onePersonsFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(new Name("best")); + List firstTagList = List.of(new Tag("football")); + FindPredicate predicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(GEORGE), model.getFilteredPersonList()); + } + + @Test + public void execute_namesAndTags_multiplePersonsFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 4); + List firstNameList = List.of(new Name("cARl"), new Name("benson")); + List firstTagList = List.of(new Tag("friends")); + FindOrPredicate predicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL), model.getFilteredPersonList()); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 45b8749c00b..d4241147a09 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -1,23 +1,6 @@ package seedu.address.logic.parser; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.commons.util.EditUtil.EditPersonDescriptor; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; -import static seedu.address.logic.commands.DeleteMultipleCommand.INDEX_SPLITTER; -import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalIndexes.INDEX_EIGHTH_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - import org.junit.jupiter.api.Test; - import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.DeleteCommand; @@ -32,7 +15,8 @@ import seedu.address.logic.commands.TagCommand; import seedu.address.logic.commands.UntagCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.FindPredicate; +import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.PersonTagsContainsCaseInsensitiveTagsPredicate; import seedu.address.model.person.PersonTagsContainsCaseSensitiveTagsPredicate; @@ -41,6 +25,24 @@ import seedu.address.testutil.PersonBuilder; import seedu.address.testutil.PersonUtil; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.commons.util.EditUtil.EditPersonDescriptor; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.DeleteMultipleCommand.INDEX_SPLITTER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalIndexes.INDEX_EIGHTH_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; + public class AddressBookParserTest { private final AddressBookParser parser = new AddressBookParser(); @@ -108,10 +110,16 @@ public void parseCommand_exit() throws Exception { @Test public void parseCommand_find() throws Exception { - List keywords = Arrays.asList("foo", "bar", "baz"); + List nameStringList = List.of("Alan", "Bob", "Chris"); + List tagStringList = List.of("football", "friends"); + List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); + List tagList = List.of(new Tag("football"), new Tag("friends")); + FindPredicate findPredicate = new FindPredicate(nameList, tagList); FindCommand command = (FindCommand) parser.parseCommand( - FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords)), command); + FindCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindCommand(findPredicate), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 70f4f0e79c4..a5ce3882551 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -1,16 +1,17 @@ package seedu.address.logic.parser; +import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.FindCommand; +import seedu.address.model.person.FindPredicate; +import seedu.address.model.person.Name; +import seedu.address.model.tag.Tag; + +import java.util.List; + import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import java.util.Arrays; - -import org.junit.jupiter.api.Test; - -import seedu.address.logic.commands.FindCommand; -import seedu.address.model.person.NameContainsKeywordsPredicate; - public class FindCommandParserTest { private FindCommandParser parser = new FindCommandParser(); @@ -23,12 +24,14 @@ public void parse_emptyArg_throwsParseException() { @Test public void parse_validArgs_returnsFindCommand() { // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice"), new Name("Bob")); + List tagList = List.of(new Tag("friends"), new Tag("colleagues")); FindCommand expectedFindCommand = - new FindCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); - assertParseSuccess(parser, "Alice Bob", expectedFindCommand); + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice n/Bob t/friends t/colleagues", expectedFindCommand); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand); + assertParseSuccess(parser, " \n n/Alice \n \t n/Bob \t t/friends t/colleagues", expectedFindCommand); } } diff --git a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java new file mode 100644 index 00000000000..218b67dccf5 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java @@ -0,0 +1,38 @@ +package seedu.address.logic.parser; + +import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.FindOrCommand; +import seedu.address.model.person.FindOrPredicate; +import seedu.address.model.person.Name; +import seedu.address.model.tag.Tag; + +import java.util.List; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +public class FindOrCommandParserTest { + + private FindOrCommandParser parser = new FindOrCommandParser(); + + @Test + public void parse_emptyArg_throwsParseException() { + assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); + } + + @Test + public void parse_validArgs_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice"), new Name("Bob")); + List tagList = List.of(new Tag("friends"), new Tag("colleagues")); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice n/Bob t/friends t/colleagues", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t n/Bob \t t/friends t/colleagues", expectedFindOrCommand); + } + +} From 1af94b54e13dd9be9ca7a97dcbeb387be8358562 Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 12:34:38 +0800 Subject: [PATCH 2/7] Fix checkstyle and add testcases for FindCommandTest as well as FindOrCommandTest --- .../logic/commands/FindCommandTest.java | 16 +++++++- .../logic/commands/FindOrCommandTest.java | 27 ++++++++++---- .../logic/parser/AddressBookParserTest.java | 37 ++++++++++--------- .../logic/parser/FindCommandParserTest.java | 13 ++++--- .../logic/parser/FindOrCommandParserTest.java | 12 +++--- 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index f6abb962d86..891b3aebadc 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -3,8 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.TypicalPersons.ALICE; @@ -21,6 +19,8 @@ import java.util.Collections; import java.util.List; +import org.junit.jupiter.api.Test; + import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -174,6 +174,18 @@ public void execute_nameAndTag_onePersonFound() { assertEquals(Arrays.asList(BENSON), model.getFilteredPersonList()); } + @Test + public void execute_nameAndTagCaseInsensitive_onePersonFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 1); + List firstNameList = List.of(new Name("bEnSon")); + List firstTagList = List.of(new Tag("fRiENds")); + FindPredicate predicate = new FindPredicate(firstNameList, firstTagList); + FindCommand command = new FindCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(BENSON), model.getFilteredPersonList()); + } + /** * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. */ diff --git a/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java index 8baf3163c16..3ff85893c72 100644 --- a/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java @@ -1,7 +1,5 @@ package seedu.address.logic.commands; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -17,6 +15,12 @@ import static seedu.address.testutil.TypicalPersons.HANNAH_NO_BIRTHDAY; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; + import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -25,11 +29,6 @@ import seedu.address.model.person.Name; import seedu.address.model.tag.Tag; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - - public class FindOrCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); @@ -175,7 +174,7 @@ public void execute_nameAndTag_onePersonsFound() { @Test public void execute_namesAndTags_multiplePersonsFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 4); - List firstNameList = List.of(new Name("cARl"), new Name("benson")); + List firstNameList = List.of(new Name("carl"), new Name("benson")); List firstTagList = List.of(new Tag("friends")); FindOrPredicate predicate = new FindOrPredicate(firstNameList, firstTagList); FindOrCommand command = new FindOrCommand(predicate); @@ -183,4 +182,16 @@ public void execute_namesAndTags_multiplePersonsFound() { assertCommandSuccess(command, model, expectedMessage, expectedModel); assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL), model.getFilteredPersonList()); } + + @Test + public void execute_namesAndTagsCaseInsensitive_multiplePersonsFound() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 4); + List firstNameList = List.of(new Name("cArL"), new Name("bEnsOn")); + List firstTagList = List.of(new Tag("friENDs")); + FindOrPredicate predicate = new FindOrPredicate(firstNameList, firstTagList); + FindOrCommand command = new FindOrCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, BENSON, CARL, DANIEL), model.getFilteredPersonList()); + } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index d4241147a09..8a8ec5dfb27 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -1,6 +1,25 @@ package seedu.address.logic.parser; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.commons.util.EditUtil.EditPersonDescriptor; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.DeleteMultipleCommand.INDEX_SPLITTER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalIndexes.INDEX_EIGHTH_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + import org.junit.jupiter.api.Test; + import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.DeleteCommand; @@ -25,24 +44,6 @@ import seedu.address.testutil.PersonBuilder; import seedu.address.testutil.PersonUtil; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.commons.util.EditUtil.EditPersonDescriptor; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; -import static seedu.address.logic.commands.DeleteMultipleCommand.INDEX_SPLITTER; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalIndexes.INDEX_EIGHTH_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; - public class AddressBookParserTest { private final AddressBookParser parser = new AddressBookParser(); diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index a5ce3882551..6cb0f065d00 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -1,17 +1,18 @@ package seedu.address.logic.parser; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import java.util.List; + import org.junit.jupiter.api.Test; + import seedu.address.logic.commands.FindCommand; import seedu.address.model.person.FindPredicate; import seedu.address.model.person.Name; import seedu.address.model.tag.Tag; -import java.util.List; - -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; - public class FindCommandParserTest { private FindCommandParser parser = new FindCommandParser(); diff --git a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java index 218b67dccf5..16c17b4487a 100644 --- a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java @@ -1,17 +1,19 @@ package seedu.address.logic.parser; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import java.util.List; + import org.junit.jupiter.api.Test; + import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.FindOrCommand; import seedu.address.model.person.FindOrPredicate; import seedu.address.model.person.Name; import seedu.address.model.tag.Tag; -import java.util.List; - -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; public class FindOrCommandParserTest { From 9b2f2005aa095ab709d90e06fa1668ad387c2a7c Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 12:51:35 +0800 Subject: [PATCH 3/7] Add testcases to AddressBookParserTest --- .../logic/parser/AddressBookParserTest.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 8a8ec5dfb27..404121054d5 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -27,6 +27,7 @@ import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.FindOrCommand; import seedu.address.logic.commands.FindTagCaseInsensitiveCommand; import seedu.address.logic.commands.FindTagCaseSensitiveCommand; import seedu.address.logic.commands.HelpCommand; @@ -34,6 +35,7 @@ import seedu.address.logic.commands.TagCommand; import seedu.address.logic.commands.UntagCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.FindOrPredicate; import seedu.address.model.person.FindPredicate; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -109,6 +111,34 @@ public void parseCommand_exit() throws Exception { assertTrue(parser.parseCommand(ExitCommand.COMMAND_WORD + " 3") instanceof ExitCommand); } + @Test + public void parseCommand_findOnlyNames() throws Exception { + List nameStringList = List.of("Alan", "Bob", "Chris"); + List tagStringList = List.of(); + List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); + List tagList = List.of(); + FindPredicate findPredicate = new FindPredicate(nameList, tagList); + FindCommand command = (FindCommand) parser.parseCommand( + FindCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindCommand(findPredicate), command); + } + + @Test + public void parseCommand_findOnlyTags() throws Exception { + List nameStringList = List.of(); + List tagStringList = List.of("football", "friends"); + List nameList = List.of(); + List tagList = List.of(new Tag("football"), new Tag("friends")); + FindPredicate findPredicate = new FindPredicate(nameList, tagList); + FindCommand command = (FindCommand) parser.parseCommand( + FindCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindCommand(findPredicate), command); + } + @Test public void parseCommand_find() throws Exception { List nameStringList = List.of("Alan", "Bob", "Chris"); @@ -123,6 +153,48 @@ public void parseCommand_find() throws Exception { assertEquals(new FindCommand(findPredicate), command); } + @Test + public void parseCommand_findOrOnlyNames() throws Exception { + List nameStringList = List.of("Alan", "Bob", "Chris"); + List tagStringList = List.of(); + List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); + List tagList = List.of(); + FindOrPredicate findOrPredicate = new FindOrPredicate(nameList, tagList); + FindOrCommand command = (FindOrCommand) parser.parseCommand( + FindOrCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindOrCommand(findOrPredicate), command); + } + + @Test + public void parseCommand_findOrOnlyTags() throws Exception { + List nameStringList = List.of(); + List tagStringList = List.of("football", "friends"); + List nameList = List.of(); + List tagList = List.of(new Tag("football"), new Tag("friends")); + FindOrPredicate findOrPredicate = new FindOrPredicate(nameList, tagList); + FindOrCommand command = (FindOrCommand) parser.parseCommand( + FindOrCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindOrCommand(findOrPredicate), command); + } + + @Test + public void parseCommand_findOr() throws Exception { + List nameStringList = List.of("Alan", "Bob", "Chris"); + List tagStringList = List.of("football", "friends"); + List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); + List tagList = List.of(new Tag("football"), new Tag("friends")); + FindOrPredicate findOrPredicate = new FindOrPredicate(nameList, tagList); + FindOrCommand command = (FindOrCommand) parser.parseCommand( + FindOrCommand.COMMAND_WORD + " " + nameStringList.stream().map(x -> PREFIX_NAME + x) + .collect(Collectors.joining(" ")) + + " " + tagStringList.stream().map(x -> PREFIX_TAG + x).collect(Collectors.joining(" "))); + assertEquals(new FindOrCommand(findOrPredicate), command); + } + @Test public void parseCommand_findTag() throws Exception { List keywords = Arrays.asList("foo", "bar", "baz"); From 1a960310fb1447ac88c6fcdd94096874e8f097ed Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 13:06:28 +0800 Subject: [PATCH 4/7] Add testcases to FindCommandParserTest and FindOrCommandParserTest --- .../logic/parser/FindCommandParserTest.java | 67 ++++++++++++++++++- .../logic/parser/FindOrCommandParserTest.java | 67 ++++++++++++++++++- 2 files changed, 132 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 6cb0f065d00..bcbf3d35c47 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -23,7 +23,72 @@ public void parse_emptyArg_throwsParseException() { } @Test - public void parse_validArgs_returnsFindCommand() { + public void parse_oneName_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice")); + List tagList = List.of(); + FindCommand expectedFindCommand = + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t \t", expectedFindCommand); + } + + @Test + public void parse_multipleNames_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice"), new Name("Bob")); + List tagList = List.of(); + FindCommand expectedFindCommand = + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice n/Bob", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t n/Bob \t", expectedFindCommand); + } + + @Test + public void parse_oneTag_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(); + List tagList = List.of(new Tag("friends")); + FindCommand expectedFindCommand = + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " t/friends", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n \n \t \t t/friends", expectedFindCommand); + } + + @Test + public void parse_multipleTags_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(); + List tagList = List.of(new Tag("friends"), new Tag("colleagues")); + FindCommand expectedFindCommand = + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " t/friends t/colleagues", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n \n \t t/friends \t t/colleagues", expectedFindCommand); + } + + @Test + public void parse_oneNamesAndTag_returnsFindCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice")); + List tagList = List.of(new Tag("friends")); + FindCommand expectedFindCommand = + new FindCommand(new FindPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice t/friends", expectedFindCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t \t t/friends", expectedFindCommand); + } + + @Test + public void parse_multipleNamesAndTags_returnsFindCommand() { // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); diff --git a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java index 16c17b4487a..bb1c553cb82 100644 --- a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java @@ -25,7 +25,72 @@ public void parse_emptyArg_throwsParseException() { } @Test - public void parse_validArgs_returnsFindCommand() { + public void parse_oneName_returnsFindOrCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice")); + List tagList = List.of(); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t \t", expectedFindOrCommand); + } + + @Test + public void parse_multipleNames_returnsFindOrCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice"), new Name("Bob")); + List tagList = List.of(); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice n/Bob", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t n/Bob \t", expectedFindOrCommand); + } + + @Test + public void parse_oneTag_returnsFindOrCommand() { + // no leading and trailing whitespaces + List nameList = List.of(); + List tagList = List.of(new Tag("friends")); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " t/friends", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n \n \t \t t/friends", expectedFindOrCommand); + } + + @Test + public void parse_multipleTags_returnsFindOrCommand() { + // no leading and trailing whitespaces + List nameList = List.of(); + List tagList = List.of(new Tag("friends"), new Tag("colleagues")); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " t/friends t/colleagues", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n t/friends \n \t \t t/colleagues", expectedFindOrCommand); + } + + @Test + public void parse_oneNameAndTag_returnsFindOrCommand() { + // no leading and trailing whitespaces + List nameList = List.of(new Name("Alice")); + List tagList = List.of(new Tag("friends")); + FindOrCommand expectedFindOrCommand = + new FindOrCommand(new FindOrPredicate(nameList, tagList)); + assertParseSuccess(parser, " n/Alice t/friends", expectedFindOrCommand); + + // multiple whitespaces between keywords + assertParseSuccess(parser, " \n n/Alice \n \t \t t/friends", expectedFindOrCommand); + } + + @Test + public void parse_multipleNamesAndTags_returnsFindOrCommand() { // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); From c308185928ba4c3b6f1c0c7002ee67a5187ad2ca Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 13:08:19 +0800 Subject: [PATCH 5/7] Minor changes --- .../seedu/address/logic/parser/FindCommandParserTest.java | 8 +------- .../address/logic/parser/FindOrCommandParserTest.java | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index bcbf3d35c47..f97eebfdde9 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -24,7 +24,6 @@ public void parse_emptyArg_throwsParseException() { @Test public void parse_oneName_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice")); List tagList = List.of(); FindCommand expectedFindCommand = @@ -37,7 +36,6 @@ public void parse_oneName_returnsFindCommand() { @Test public void parse_multipleNames_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(); FindCommand expectedFindCommand = @@ -50,12 +48,11 @@ public void parse_multipleNames_returnsFindCommand() { @Test public void parse_oneTag_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(); List tagList = List.of(new Tag("friends")); FindCommand expectedFindCommand = new FindCommand(new FindPredicate(nameList, tagList)); - assertParseSuccess(parser, " t/friends", expectedFindCommand); + assertParseSuccess(parser, " t/friends", expectedFindCommand); // multiple whitespaces between keywords assertParseSuccess(parser, " \n \n \t \t t/friends", expectedFindCommand); @@ -63,7 +60,6 @@ public void parse_oneTag_returnsFindCommand() { @Test public void parse_multipleTags_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); FindCommand expectedFindCommand = @@ -76,7 +72,6 @@ public void parse_multipleTags_returnsFindCommand() { @Test public void parse_oneNamesAndTag_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice")); List tagList = List.of(new Tag("friends")); FindCommand expectedFindCommand = @@ -89,7 +84,6 @@ public void parse_oneNamesAndTag_returnsFindCommand() { @Test public void parse_multipleNamesAndTags_returnsFindCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); FindCommand expectedFindCommand = diff --git a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java index bb1c553cb82..34a8e67188b 100644 --- a/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindOrCommandParserTest.java @@ -26,7 +26,6 @@ public void parse_emptyArg_throwsParseException() { @Test public void parse_oneName_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice")); List tagList = List.of(); FindOrCommand expectedFindOrCommand = @@ -39,7 +38,6 @@ public void parse_oneName_returnsFindOrCommand() { @Test public void parse_multipleNames_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(); FindOrCommand expectedFindOrCommand = @@ -52,7 +50,6 @@ public void parse_multipleNames_returnsFindOrCommand() { @Test public void parse_oneTag_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(); List tagList = List.of(new Tag("friends")); FindOrCommand expectedFindOrCommand = @@ -65,7 +62,6 @@ public void parse_oneTag_returnsFindOrCommand() { @Test public void parse_multipleTags_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); FindOrCommand expectedFindOrCommand = @@ -78,7 +74,6 @@ public void parse_multipleTags_returnsFindOrCommand() { @Test public void parse_oneNameAndTag_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice")); List tagList = List.of(new Tag("friends")); FindOrCommand expectedFindOrCommand = @@ -91,7 +86,6 @@ public void parse_oneNameAndTag_returnsFindOrCommand() { @Test public void parse_multipleNamesAndTags_returnsFindOrCommand() { - // no leading and trailing whitespaces List nameList = List.of(new Name("Alice"), new Name("Bob")); List tagList = List.of(new Tag("friends"), new Tag("colleagues")); FindOrCommand expectedFindOrCommand = From fdd3f0ea698deeab94131b01e2e05ffe39f45c6f Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 15:09:07 +0800 Subject: [PATCH 6/7] Fix naming convention and description --- .../java/seedu/address/logic/commands/FindCommand.java | 8 ++++---- .../java/seedu/address/logic/commands/FindOrCommand.java | 8 ++++---- .../java/seedu/address/model/person/FindOrPredicate.java | 6 +++--- .../java/seedu/address/model/person/FindPredicate.java | 2 +- .../seedu/address/logic/commands/FindOrCommandTest.java | 2 +- .../seedu/address/logic/parser/AddressBookParserTest.java | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index 5e1cec6c25b..e60dbbbc51a 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -9,17 +9,17 @@ /** - * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Finds and lists all persons in address book whose details contain ALL of the argument keywords provided. * Keyword matching is case insensitive. */ public class FindCommand extends Command { public static final String COMMAND_WORD = "find"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain ALL 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/[name] ... t/[tag] ...\n" + + "Example: " + COMMAND_WORD + " n/alice n/bob t/friends t/colleagues"; private final FindPredicate findPredicate; diff --git a/src/main/java/seedu/address/logic/commands/FindOrCommand.java b/src/main/java/seedu/address/logic/commands/FindOrCommand.java index be24a0d551b..64e90cea738 100644 --- a/src/main/java/seedu/address/logic/commands/FindOrCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindOrCommand.java @@ -8,17 +8,17 @@ /** - * Finds and lists all persons in address book whose name contains any of the argument keywords. + * Finds and lists all persons in address book whose name contains ANY of the argument keywords provided. * Keyword matching is case insensitive. */ public class FindOrCommand extends Command { public static final String COMMAND_WORD = "findOr"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of " + 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/[name] ... t/[tag] ...\n" + + "Example: " + COMMAND_WORD + " n/alice n/bob t/friends t/colleagues"; private final FindOrPredicate findOrPredicate; diff --git a/src/main/java/seedu/address/model/person/FindOrPredicate.java b/src/main/java/seedu/address/model/person/FindOrPredicate.java index 7d6ad898b66..909b9df5981 100644 --- a/src/main/java/seedu/address/model/person/FindOrPredicate.java +++ b/src/main/java/seedu/address/model/person/FindOrPredicate.java @@ -8,7 +8,7 @@ import seedu.address.model.tag.Tag; /** - * Tests that a {@code Person}'s {@code Name} OR {@code Tag} matches all of the tags given. + * Tests that a {@code Person}'s {@code Name} OR {@code Tag} matches ANY of the tags given. */ public class FindOrPredicate implements Predicate { @@ -31,10 +31,10 @@ public boolean test(Person person) { Tag[] arrayTags = new Tag[person.getTags().toArray().length]; if (!nameList.isEmpty()) { return nameList.stream() - .anyMatch(name -> StringUtil.containsWordIgnoreCase(person.getName().fullName, name.fullName) + .anyMatch(name -> StringUtil.containsWordIgnoreCase(person.getName().fullName, name.fullName)) || tagList.stream() .anyMatch(tag -> Arrays.stream(person.getTags().toArray(arrayTags)) - .anyMatch(personTag -> personTag.compareTag(tag, false)))); + .anyMatch(personTag -> personTag.compareTag(tag, false))); } else { return tagList.stream() .anyMatch(tag -> Arrays.stream(person.getTags().toArray(arrayTags)) diff --git a/src/main/java/seedu/address/model/person/FindPredicate.java b/src/main/java/seedu/address/model/person/FindPredicate.java index 0e2ab7aff80..ebc56d9effd 100644 --- a/src/main/java/seedu/address/model/person/FindPredicate.java +++ b/src/main/java/seedu/address/model/person/FindPredicate.java @@ -9,7 +9,7 @@ /** - * Tests that a {@code Person}'s {@code Name} AND {@code Tag} matches all of the tags given. + * Tests that a {@code Person}'s {@code Name} AND {@code Tag} matches ALL of the tags given. */ public class FindPredicate implements Predicate { diff --git a/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java index 3ff85893c72..33fb7d2f180 100644 --- a/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindOrCommandTest.java @@ -100,7 +100,7 @@ public void execute_oneExistentName_twoPersonFound() { } @Test - public void execute_twoExistentName_noPersonFound() { + public void execute_twoExistentName_twoPersonFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); List firstNameList = List.of(new Name("alice"), new Name("benson")); List firstTagList = List.of(); diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 404121054d5..f82646f87a2 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -140,7 +140,7 @@ public void parseCommand_findOnlyTags() throws Exception { } @Test - public void parseCommand_find() throws Exception { + public void parseCommand_findNamesAndTags() throws Exception { List nameStringList = List.of("Alan", "Bob", "Chris"); List tagStringList = List.of("football", "friends"); List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); @@ -182,7 +182,7 @@ public void parseCommand_findOrOnlyTags() throws Exception { } @Test - public void parseCommand_findOr() throws Exception { + public void parseCommand_findOrNamesAndTags() throws Exception { List nameStringList = List.of("Alan", "Bob", "Chris"); List tagStringList = List.of("football", "friends"); List nameList = List.of(new Name("Alan"), new Name("Bob"), new Name("Chris")); From 2f7235355e95072ff8ff99de14b754a664068d6d Mon Sep 17 00:00:00 2001 From: zhixuanlee Date: Thu, 21 Oct 2021 19:48:57 +0800 Subject: [PATCH 7/7] Minor fixes --- src/main/java/seedu/address/logic/parser/AddressBookParser.java | 1 - src/main/java/seedu/address/model/person/FindOrPredicate.java | 2 +- src/main/java/seedu/address/model/person/FindPredicate.java | 2 +- src/main/java/seedu/address/ui/BirthdayReminderCard.java | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 7f62697b0ca..a0a3069cc2c 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -74,7 +74,6 @@ public Command parseCommand(String userInput) throws ParseException { case FindCommand.COMMAND_WORD: return new FindCommandParser().parse(arguments); - case FindOrCommand.COMMAND_WORD: return new FindOrCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/model/person/FindOrPredicate.java b/src/main/java/seedu/address/model/person/FindOrPredicate.java index 909b9df5981..22fbc75216a 100644 --- a/src/main/java/seedu/address/model/person/FindOrPredicate.java +++ b/src/main/java/seedu/address/model/person/FindOrPredicate.java @@ -8,7 +8,7 @@ import seedu.address.model.tag.Tag; /** - * Tests that a {@code Person}'s {@code Name} OR {@code Tag} matches ANY of the tags given. + * Tests that a {@code Person}'s {@code Name} OR {@code Tag} matches ANY of the keywords given. */ public class FindOrPredicate implements Predicate { diff --git a/src/main/java/seedu/address/model/person/FindPredicate.java b/src/main/java/seedu/address/model/person/FindPredicate.java index ebc56d9effd..c188c3f2d3c 100644 --- a/src/main/java/seedu/address/model/person/FindPredicate.java +++ b/src/main/java/seedu/address/model/person/FindPredicate.java @@ -9,7 +9,7 @@ /** - * Tests that a {@code Person}'s {@code Name} AND {@code Tag} matches ALL of the tags given. + * Tests that a {@code Person}'s {@code Name} AND {@code Tag} matches ALL of the keywords given. */ public class FindPredicate implements Predicate { diff --git a/src/main/java/seedu/address/ui/BirthdayReminderCard.java b/src/main/java/seedu/address/ui/BirthdayReminderCard.java index 665180a5caf..b30f5124dec 100644 --- a/src/main/java/seedu/address/ui/BirthdayReminderCard.java +++ b/src/main/java/seedu/address/ui/BirthdayReminderCard.java @@ -9,7 +9,6 @@ import seedu.address.model.person.Birthday; import seedu.address.model.person.Person; - public class BirthdayReminderCard extends UiPart { private static final String FXML = "BirthdayReminderListCard.fxml";