Skip to content

Commit

Permalink
Update isSamePerson() equality for Person class
Browse files Browse the repository at this point in the history
The person equality check returns true if the name or the email
matches. The OR condition complicates the equality check done when
editing a person as it assumes isSamePerson() to have a transitive
relation.

Alternative 1: Improve the way the equality check is done in the edit
command to prevent the above bug. (PRs nus-cs2103-AY2122S2#68, nus-cs2103-AY2122S2#69)

Alternative 2: Simplify the equality check by removing the OR condition.
This is simpler but possibly too strict for the address book domain
i.e., increases the risk of duplicate entries for the same person
creeping into the address book

We decided to go with the alternative 2 because,
* It is important to keep the code base simple, to reduce the initial
learning curve of the students at the start of their project
* Students can introduce a more sophisticated equality check that
matches their product domain later.

Also, let's change the default name in PersonBuilder utility class.
This is because AddCommandIntegrationTest populates its model using
getTypicalPersons() which contains a person with the default name.
This test then creates another person using the default name, to be
added into the model, which is expected to pass. However, the above
update in equality causes this test to fail. Thus we need to change the
default name to a unique name that is not inside getTypicalPersons().
Also, the default email is changed for consistency in naming the
default values, it does not affect current test cases.
  • Loading branch information
aditi2313 authored Feb 25, 2022
1 parent 620a2ff commit 643112b
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;

Expand All @@ -21,13 +20,11 @@ public class PersonBuilder {
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "[email protected]";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_REMARK = "She likes aardvarks.";

private Name name;
private Phone phone;
private Email email;
private Address address;
private Remark remark;
private Set<Tag> tags;

/**
Expand All @@ -38,7 +35,6 @@ public PersonBuilder() {
phone = new Phone(DEFAULT_PHONE);
email = new Email(DEFAULT_EMAIL);
address = new Address(DEFAULT_ADDRESS);
remark = new Remark(DEFAULT_REMARK);
tags = new HashSet<>();
}

Expand All @@ -50,7 +46,6 @@ public PersonBuilder(Person personToCopy) {
phone = personToCopy.getPhone();
email = personToCopy.getEmail();
address = personToCopy.getAddress();
remark = personToCopy.getRemark();
tags = new HashSet<>(personToCopy.getTags());
}

Expand Down Expand Up @@ -94,16 +89,8 @@ public PersonBuilder withEmail(String email) {
return this;
}

/**
* Sets the {@code Remark} of the {@code Person} that we are building.
*/
public PersonBuilder withRemark(String remark) {
this.remark = new Remark(remark);
return this;
}

public Person build() {
return new Person(name, phone, email, address, remark, tags);
return new Person(name, phone, email, address, tags);
}

}

0 comments on commit 643112b

Please sign in to comment.