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

Adjust person duplicate #222

Merged
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
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public boolean equals(Object other) {
return false;
}

return fullName.equals(otherName.fullName);

return fullName.replaceAll("\\s+", "")
.equalsIgnoreCase(otherName.fullName.replaceAll("\\s+", ""));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public boolean isSamePerson(PersonDescriptor otherPerson) {
}

return otherPerson != null
&& otherPerson.getName().equals(getName());
&& otherPerson.getName().equals(getName())
&& otherPerson.getPhone().equals((getPhone()));
}

/**
Expand All @@ -84,7 +85,8 @@ public boolean isSamePerson(PersonDescriptor otherPerson) {
*/
public boolean isSamePerson(Person otherPerson) {
return otherPerson != null
&& otherPerson.getName().equals(getName());
&& otherPerson.getName().equals(getName())
&& otherPerson.getPhone().equals(getPhone());
}

/**
Expand Down
17 changes: 11 additions & 6 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ public void isSamePerson() {
// null -> returns false
assertFalse(ALICE.isSamePerson((PersonDescriptor) null));

// same name, all other attributes different -> returns true
// same name, all other attributes different -> returns False
Person editedAlice = new PersonBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB)
.withAddress(VALID_ADDRESS_BOB).withStatus(VALID_STATUS_BOB).withTags(VALID_TAG_HUSBAND).build();
assertTrue(ALICE.isSamePerson(editedAlice));
assertFalse(ALICE.isSamePerson(editedAlice));

// same name, same phone, all other attributes different -> returns true
Person editedAliceNewPhone = new PersonBuilder(ALICE).withEmail(VALID_EMAIL_BOB)
.withAddress(VALID_ADDRESS_BOB).withStatus(VALID_STATUS_BOB).withTags(VALID_TAG_HUSBAND).build();
Comment on lines -38 to +45

Choose a reason for hiding this comment

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

Thanks for updating the test cases to consider the new valid inputs!

assertTrue(ALICE.isSamePerson(editedAliceNewPhone));

// different name, all other attributes same -> returns false
editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.isSamePerson(editedAlice));

// name differs in case, all other attributes same -> returns false
// name differs in case, all other attributes same -> returns true
Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
assertFalse(BOB.isSamePerson(editedBob));
assertTrue(BOB.isSamePerson(editedBob));

// name has trailing spaces, all other attributes same -> returns false
// name has trailing spaces, all other attributes same -> returns true
String nameWithTrailingSpaces = VALID_NAME_BOB + " ";
editedBob = new PersonBuilder(BOB).withName(nameWithTrailingSpaces).build();
assertFalse(BOB.isSamePerson(editedBob));
assertTrue(BOB.isSamePerson(editedBob));
}

@Test
Expand Down