Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W5.4][T14-A4]Melanie Ng #910

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Format: `list`
## Finding all persons containing any keyword in their name: `find`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title should be changed since the functionality of find has been expanded.

Finds persons whose names contain any of the given keywords.<br>
Format: `find KEYWORD [MORE_KEYWORDS]`
Finds person with their recorded phone number. <br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing line 42 rather than writing this line out will make your function description clearer

Format: `find 11111111`

> The search is case sensitive, the order of the keywords does not matter, only the name is searched,
and persons matching at least one keyword will be returned (i.e. `OR` search).
Expand Down
8 changes: 7 additions & 1 deletion src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String>
final List<ReadOnlyPerson> matchedPersons = new ArrayList<>();
for (ReadOnlyPerson person : addressBook.getAllPersons()) {
final Set<String> wordsInName = new HashSet<>(person.getName().getWordsInName());
if (!Collections.disjoint(wordsInName, keywords)) {
final Set<String> numInPhone = new HashSet<>(person.getPhone().getNumInPhone());
if (!Collections.disjoint(numInPhone, keywords)) {
matchedPersons.add(person);
}
else if (!Collections.disjoint(wordsInName, keywords)) {
matchedPersons.add(person);
}

}
return matchedPersons;
}


}
10 changes: 10 additions & 0 deletions src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import seedu.addressbook.data.exception.IllegalValueException;

import java.util.Arrays;
import java.util.List;

/**
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)}
Expand Down Expand Up @@ -36,6 +39,13 @@ public static boolean isValidPhone(String test) {
return test.matches(PHONE_VALIDATION_REGEX);
}

/**
* Retrieves a listing of every number in the name, in order.
*/
public List<String> getNumInPhone() {
return Arrays.asList(value);
}

@Override
public String toString() {
return value;
Expand Down
27 changes: 25 additions & 2 deletions test/java/seedu/addressbook/logic/LogicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,28 +433,50 @@ public void execute_find_isCaseSensitive() throws Exception {
assertCommandBehavior("find KEY",
Command.getMessageForPersonListShownSummary(expectedList),
expectedAB,
true,
true,
expectedList);
}

@Test
@Test
public void execute_find_matchesIfAnyKeywordPresent() throws Exception {
TestDataHelper helper = new TestDataHelper();
Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla");
Person pTarget2 = helper.generatePersonWithName("bla rAnDoM bla bceofeia");
Person p1 = helper.generatePersonWithName("key key");
Person p2 = helper.generatePersonWithName("KEy sduauo");
Person pTarget3 = helper.generatePersonWithName("12345678");
Person pTarget4 = helper.generatePersonWithName("87654321");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 lines create Person objects with the argument becoming the name, not the phone number.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, your test should be in a separate function because it tests a separate functionality from yours.

Person p3 = helper.generatePersonWithName("24681012");
Person p4 = helper.generatePersonWithName("12108642");

List<Person> fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2);
AddressBook expectedAB = helper.generateAddressBook(fourPersons);
List<Person> expectedList = helper.generatePersonList(pTarget1, pTarget2);
helper.addToAddressBook(addressBook, fourPersons);

List<Person> fourNum = helper.generatePersonList(p3, pTarget3, p4, pTarget4);
AddressBook expectedCD = helper.generateAddressBook(fourNum);
List<Person> expectedL = helper.generatePersonList(pTarget3, pTarget4);
helper.addToAddressBook(addressBook, fourNum);

assertCommandBehavior("find KEY rAnDoM",
Command.getMessageForPersonListShownSummary(expectedList),
expectedAB,
true,
expectedList);

assertCommandBehavior("find 12348765",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really test your functionality of finding by number? Is 12348765 the name or phone number of pTarget3/pTarget4?

Command.getMessageForPersonListShownSummary(expectedL),
expectedCD,
true,
expectedL);

// assertCommandBehavior("find 8765 4321",
// Command.getMessageForPersonListShownSummary(expectedL),
// expectedCD,
// true,
// expectedL);

}

/**
Expand Down Expand Up @@ -586,6 +608,7 @@ Person generatePersonWithName(String name) throws Exception {
new UniqueTagList(new Tag("tag"))
);
}

}

}