Skip to content

Commit

Permalink
Redefine same person
Browse files Browse the repository at this point in the history
  • Loading branch information
nixonwidjaja committed Nov 5, 2023
1 parent 4f040cd commit 25b6f45
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
12 changes: 5 additions & 7 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,14 @@ public Set<Tag> getTags() {
}

/**
* Returns true if both persons have the same name.
* This defines a weaker notion of equality between two persons.
* Returns true if both persons are the same.
*/
public boolean isSamePerson(Person otherPerson) {
if (otherPerson == this) {
return true;
}

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

/**
Expand All @@ -138,9 +136,9 @@ public boolean equals(Object other) {

Person otherPerson = (Person) other;
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address);
&& dob.equals(otherPerson.dob)
&& address.equals(otherPerson.address)
&& (phone.equals(otherPerson.phone) || email.equals(otherPerson.email));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"name": "Alice Pauline",
"phone": "94351253",
"email": "[email protected]",
"address": "4th street",
"address": "123, Jurong West Ave 6, #08-111",
"salary": "100000",
"claimBudget": "1",
"department": "Finance",
Expand Down
16 changes: 1 addition & 15 deletions src/test/java/seedu/address/model/AddressBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.DuplicatePersonException;
import seedu.address.testutil.PersonBuilder;

public class AddressBookTest {
Expand All @@ -43,17 +40,6 @@ public void resetData_withValidReadOnlyAddressBook_replacesData() {
assertEquals(newData, addressBook);
}

@Test
public void resetData_withDuplicatePersons_throwsDuplicatePersonException() {
// Two persons with the same identity fields
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.build();
List<Person> newPersons = Arrays.asList(ALICE, editedAlice);
AddressBookStub newData = new AddressBookStub(newPersons);

assertThrows(DuplicatePersonException.class, () -> addressBook.resetData(newData));
}

@Test
public void hasPerson_nullPerson_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> addressBook.hasPerson(null));
Expand All @@ -75,7 +61,7 @@ public void hasPerson_personWithSameIdentityFieldsInAddressBook_returnsTrue() {
addressBook.addPerson(ALICE);
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
.build();
assertTrue(addressBook.hasPerson(editedAlice));
assertFalse(addressBook.hasPerson(editedAlice));
}

@Test
Expand Down
11 changes: 5 additions & 6 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public void isSamePerson() {
// null -> returns false
assertFalse(ALICE.isSamePerson(null));

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

// different name, all other attributes same -> returns false
editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build();
Expand Down Expand Up @@ -72,13 +71,13 @@ public void equals() {
Person editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different phone -> returns false
// different phone -> returns true
editedAlice = new PersonBuilder(ALICE).withPhone(VALID_PHONE_BOB).build();
assertFalse(ALICE.equals(editedAlice));
assertTrue(ALICE.equals(editedAlice));

// different email -> returns false
// different email -> returns true
editedAlice = new PersonBuilder(ALICE).withEmail(VALID_EMAIL_BOB).build();
assertFalse(ALICE.equals(editedAlice));
assertTrue(ALICE.equals(editedAlice));

// different address -> returns false
editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void contains_personInList_returnsTrue() {
@Test
public void contains_personWithSameIdentityFieldsInList_returnsTrue() {
uniquePersonList.add(ALICE);
Person editedAlice = new PersonBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND)
Person editedAlice = new PersonBuilder(ALICE).withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND)
.build();
assertTrue(uniquePersonList.contains(editedAlice));
}
Expand Down

0 comments on commit 25b6f45

Please sign in to comment.