Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren159 committed Oct 19, 2023
1 parent 3a37b4b commit 1cc2453
Show file tree
Hide file tree
Showing 21 changed files with 510 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean equals(Object other) {
}

AddAppointmentCommand otherAddCommand = (AddAppointmentCommand) other;
return toAdd.equals(otherAddCommand.toAdd);
return toAdd.equals(otherAddCommand.toAdd) && index.equals(otherAddCommand.index);
}

@Override
Expand Down
63 changes: 25 additions & 38 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Age updatedAge = editPersonDescriptor.getAge().orElse(personToEdit.getAge());
BloodType updatedBloodType = editPersonDescriptor.getBloodType().orElse(personToEdit.getBloodType());
Set<Allergy> updatedAllergies = editPersonDescriptor.getAllergies().orElse(personToEdit.getAllergies());
Boolean updatedisPinned = editPersonDescriptor.getIsPinned().orElse(personToEdit.isPinned());
Boolean updatedisPinned = personToEdit.isPinned();
UniqueAppointmentList updatedAppointments = personToEdit.getAppointments();

return new Person(updatedName, updatedEmail, updatedPhone, updatedGender,
Expand Down Expand Up @@ -154,7 +154,6 @@ public static class EditPersonDescriptor {
private Age age;
private BloodType bloodType;
private Set<Allergy> allergies;
private Boolean isPinned;

public EditPersonDescriptor() {}

Expand All @@ -170,7 +169,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setAge(toCopy.age);
setBloodType(toCopy.bloodType);
setAllergies(toCopy.allergies);
setIsPinned(toCopy.isPinned);
}

/**
Expand All @@ -180,70 +178,52 @@ public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, email, phone, gender, age, bloodType, allergies);
}

public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public void setName(Name name) {
this.name = name;
}

public Optional<Name> getName() {
return Optional.ofNullable(name);
public Optional<Phone> getPhone() {
return Optional.ofNullable(phone);
}

public void setPhone(Phone phone) {
this.phone = phone;
}

public void setEmail(Email email) {
this.email = email;
}

public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

public Optional<Phone> getPhone() {
return Optional.ofNullable(phone);
}

public void setGender(Gender gender) {
this.gender = gender;

public void setEmail(Email email) {
this.email = email;
}

public Optional<Gender> getGender() {
return Optional.ofNullable(gender);
}

public void setAge(Age age) {
this.age = age;
}

public void setIsPinned(Boolean isPinned) {
this.isPinned = isPinned;
}

public Optional<Boolean> getIsPinned() {
return Optional.ofNullable(isPinned);

public void setGender(Gender gender) {
this.gender = gender;
}



public Optional<Age> getAge() {
return Optional.ofNullable(age);
}

public void setBloodType(BloodType bloodType) {
this.bloodType = bloodType;
public void setAge(Age age) {
this.age = age;
}

public Optional<BloodType> getBloodType() {
return Optional.ofNullable(bloodType);
}

/**
* Sets {@code allergies} to this object's {@code tags}.
* A defensive copy of {@code allergies} is used internally.
*/
public void setAllergies(Set<Allergy> allergies) {
this.allergies = (allergies != null) ? new HashSet<>(allergies) : null;
public void setBloodType(BloodType bloodType) {
this.bloodType = bloodType;
}

/**
Expand All @@ -255,6 +235,14 @@ public Optional<Set<Allergy>> getAllergies() {
return (allergies != null) ? Optional.of(Collections.unmodifiableSet(allergies)) : Optional.empty();
}

/**
* Sets {@code allergies} to this object's {@code tags}.
* A defensive copy of {@code allergies} is used internally.
*/
public void setAllergies(Set<Allergy> allergies) {
this.allergies = (allergies != null) ? new HashSet<>(allergies) : null;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down Expand Up @@ -286,7 +274,6 @@ public String toString() {
.add("age", age)
.add("bloodType", bloodType)
.add("allergies", allergies)
.add("isPinned", isPinned)
.toString();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public boolean equals(Object other) {
&& age.equals(otherPerson.age)
&& bloodType.equals(otherPerson.bloodType)
&& allergies.equals(otherPerson.allergies)
&& isPinned == otherPerson.isPinned;
&& isPinned == otherPerson.isPinned
&& appointments.equals(otherPerson.appointments);
}

@Override
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.appointment.Appointment;
import seedu.address.model.person.appointment.DateTime;
import seedu.address.model.person.appointment.UniqueAppointmentList;


Expand All @@ -25,7 +27,7 @@ public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Email("[email protected]"), new Phone("87438807"),
new Gender("M"), new Age(12), new BloodType("A+"), getAllergySet("Peanuts"),
true, new UniqueAppointmentList()),
true, getAppointmentList(new Appointment(new Name("Eye Exam"), new DateTime("01-01-2001 1200")))),
new Person(new Name("Bernice Yu"), new Email("[email protected]"), new Phone("99272758"),
new Gender("F"), new Age(31), new BloodType("B+"), getAllergySet("Dust", "Peanuts"),
false, new UniqueAppointmentList()),
Expand Down Expand Up @@ -53,12 +55,22 @@ public static ReadOnlyAddressBook getSampleAddressBook() {
}

/**
* Returns a tag set containing the list of strings given.
* Returns an allergy set containing the list of strings given.
*/
public static Set<Allergy> getAllergySet(String... strings) {
return Arrays.stream(strings)
.map(Allergy::new)
.collect(Collectors.toSet());
}

/**
* Returns an appointment list containing the list of appointments given.
*/
public static UniqueAppointmentList getAppointmentList(Appointment... appointments) {
UniqueAppointmentList appointmentList = new UniqueAppointmentList();
for (Appointment appointment : appointments) {
appointmentList.add(appointment);
}
return appointmentList;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
{
"persons": [ {
"name": "Valid Person",
"phone": "9482424",
"email": "[email protected]",
"address": "4th street"
}, {
"name": "Person With Invalid Phone Field",
"phone": "948asdf2424",
"email": "[email protected]",
"address": "4th street"
} ]
"persons": [
{
"name": "Valid Person",
"phone": "9482424",
"email": "[email protected]",
"gender": "M",
"age": "18",
"bloodType": "A+",
"allergies": ["Peanuts"],
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
},
{
"name": "Person With Invalid Phone Field",
"phone": "948asdf2424",
"email": "[email protected]",
"gender": "M",
"age": "18",
"bloodType": "A+",
"allergies": ["Peanuts"],
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"persons": [ {
"name": "Person with invalid name field: Ha!ns Mu@ster",
"phone": "9482424",
"email": "[email protected]",
"address": "4th street"
} ]
"persons": [
{
"name": "Person with invalid name field: Ha!ns Mu@ster",
"phone": "9482424",
"email": "[email protected]",
"gender": "M",
"age": "18",
"bloodType": "A+",
"allergies": ["Peanuts"],
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
"gender": "F",
"age": 20,
"allergies": ["Chocolate"],
"isPinned": true
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
},
{
"name": "Alice Pauline",
Expand All @@ -19,7 +25,13 @@
"gender": "F",
"age": 20,
"allergies": ["Chocolate"],
"isPinned": true
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"persons": [ {
"name": "Hans Muster",
"phone": "9482424",
"email": "invalid@email!3e",
"address": "4th street"
} ]
"persons": [
{
"name": "Hans Muster",
"phone": "9482424",
"email": "invalid@email!3e",
"gender": "M",
"age": "18",
"bloodType": "A+",
"allergies": ["Peanuts"],
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
}
]
}
Loading

0 comments on commit 1cc2453

Please sign in to comment.