Skip to content

Commit

Permalink
Rectify Failing Testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed-Faizzzz committed Oct 28, 2023
1 parent 71921fb commit 6720a9a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 47 deletions.
33 changes: 23 additions & 10 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Appointment;
import seedu.address.model.person.BloodType;
import seedu.address.model.person.Condition;
import seedu.address.model.person.Doctor;
Expand Down Expand Up @@ -212,7 +213,7 @@ public static class EditPersonDescriptor {
private Set<Tag> tags;
private Condition condition;
private BloodType bloodType;
private ArrayList<Patient> patients;
private Set<Appointment> appointments;

public EditPersonDescriptor() {
}
Expand All @@ -233,15 +234,15 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setTags(toCopy.tags);
setBloodType(toCopy.bloodType);
setCondition(toCopy.condition);
setPatients(toCopy.patients);
setAppointments(toCopy.appointments);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, emergencyContact, address,
gender, ic, tags, bloodType, condition, remark, patients);
gender, ic, tags, bloodType, condition, remark, appointments);
}

public void setName(Name name) {
Expand Down Expand Up @@ -275,12 +276,6 @@ public void setEmail(Email email) {
public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}
public void setPatients(ArrayList<Patient> patients) {
this.patients = patients;
}
public Optional<ArrayList<Patient>> getPatients() {
return Optional.ofNullable(patients);
}
public void setAddress(Address address) {
this.address = address;
}
Expand Down Expand Up @@ -347,6 +342,22 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
public void setAppointments(Set<Appointment> appointments) {
this.appointments = (appointments != null) ? new HashSet<>(appointments) : null;
}
/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
public Optional<Set<Appointment>> getAppointments() {
return (appointments != null) ? Optional.of(Collections.unmodifiableSet(appointments)) : Optional.empty();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -368,7 +379,8 @@ public boolean equals(Object other) {
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(condition, otherEditPersonDescriptor.condition)
&& Objects.equals(bloodType, otherEditPersonDescriptor.bloodType)
&& Objects.equals(remark, otherEditPersonDescriptor.remark);
&& Objects.equals(remark, otherEditPersonDescriptor.remark)
&& Objects.equals(appointments, otherEditPersonDescriptor.appointments);
}

@Override
Expand All @@ -383,6 +395,7 @@ public String toString() {
.add("tags", tags)
.add("condition", condition)
.add("blood type", bloodType)
.add("appointments", appointments)
.toString();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/model/person/Doctor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package seedu.address.model.person;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

Expand All @@ -12,7 +12,7 @@
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Doctor extends Person {
private final ArrayList<Appointment> appointments = new ArrayList<Appointment>();
private final Set<Appointment> appointments = new HashSet<>();

/**
* Every field must be present and not null.
Expand All @@ -27,7 +27,7 @@ public Doctor(Name name, Phone phone, Email email, Address address, Remark remar
*
* @return An ArrayList containing the patients currently registered in the facility.
*/
public ArrayList<Appointment> getAppointments() {
public Set<Appointment> getAppointments() {
return appointments;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/person/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

Expand All @@ -18,7 +18,7 @@ public class Patient extends Person {
// Patient specific fields
private final Condition condition;
private final BloodType bloodType;
private final ArrayList<Appointment> appointments = new ArrayList<Appointment>();
private final Set<Appointment> appointments = new HashSet<>();
private final Phone emergencyContact;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ public Phone getEmergencyContact() {
*
* @return An ArrayList containing the patients currently registered in the facility.
*/
public ArrayList<Appointment> getAppointments() {
public Set<Appointment> getAppointments() {
return appointments;
}

Expand Down Expand Up @@ -126,9 +126,9 @@ public String toString() {
.add("nric", ic)
.add("condition", condition)
.add("bloodType", bloodType)
.add("appointments", appointments)
.add("tags", tags)
.toString();
}

}

25 changes: 12 additions & 13 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class CommandTestUtil {
public static final String VALID_EMAIL_DEREK = "mcdreamy@medilink.com";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";

public static final String VALID_ADDRESS_CHERYL = "123 Main Street, Anytown, USA";
public static final String VALID_ADDRESS_DEREK = "456 Elm Avenue, Somewhereville, Canada";

Expand Down Expand Up @@ -100,29 +99,29 @@ public class CommandTestUtil {
public static final String ADDRESS_DESC_DEREK = " " + PREFIX_ADDRESS + VALID_ADDRESS_DEREK;
public static final String GENDER_DESC_MALE = " " + PREFIX_GENDER + VALID_GENDER_MALE;
public static final String GENDER_DESC_FEMALE = " " + PREFIX_GENDER + VALID_GENDER_FEMALE;
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_BLOODTYPE_DESC = " " + PREFIX_BLOODTYPE + "Z+";
public static final String INVALID_CONDITION_DESC = " " + PREFIX_CONDITION + " ";
public static final String INVALID_EMERGENCY_CONTACT_DESC = " " + PREFIX_EMERGENCY_CONTACT + "+6A";
public static final String INVALID_NRIC = "A1234567G";
public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "Alien";
public static final String NRIC_DESC_AMY = " " + PREFIX_NRIC + VALID_NRIC_AMY;
public static final String NRIC_DESC_BOB = " " + PREFIX_NRIC + VALID_NRIC_BOB;
public static final String NRIC_DESC_CHERYL = " " + PREFIX_NRIC + VALID_NRIC_CHERYL;
public static final String NRIC_DESC_DEREK = " " + PREFIX_NRIC + VALID_NRIC_DEREK;
public static final String REMARK_DESC_AMY = " " + PREFIX_REMARK + VALID_REMARK_AMY;
public static final String REMARK_DESC_BOB = " " + PREFIX_REMARK + VALID_REMARK_BOB;
public static final String REMARK_DESC_CHERYL = " " + PREFIX_REMARK + VALID_REMARK_CHERYL;
public static final String CONDITION_DESC_AMY = " " + PREFIX_CONDITION + VALID_CONDITION_AMY;
public static final String CONDITION_DESC_BOB = " " + PREFIX_CONDITION + VALID_CONDITION_BOB;
public static final String BLOODTYPE_DESC_AMY = " " + PREFIX_BLOODTYPE + VALID_BLOODTYPE_AMY;
public static final String BLOODTYPE_DESC_BOB = " " + PREFIX_BLOODTYPE + VALID_BLOODTYPE_BOB;
public static final String CONDITION_DESC_AMY = " " + PREFIX_CONDITION + VALID_CONDITION_AMY;
public static final String CONDITION_DESC_BOB = " " + PREFIX_CONDITION + VALID_CONDITION_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_BLOODTYPE_DESC = " " + PREFIX_BLOODTYPE + "Z+";
public static final String INVALID_CONDITION_DESC = " " + PREFIX_CONDITION + " ";
public static final String INVALID_EMERGENCY_CONTACT_DESC = " " + PREFIX_EMERGENCY_CONTACT + "+6A";
public static final String INVALID_NRIC = "A1234567G";
public static final String INVALID_GENDER_DESC = " " + PREFIX_GENDER + "Alien";
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
public static final EditCommand.EditPersonDescriptor DESC_AMY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void toStringMethod() {
+ editPersonDescriptor.getIc().orElse(null) + ", tags="
+ editPersonDescriptor.getTags().orElse(null) + ", condition="
+ editPersonDescriptor.getCondition().orElse(null) + ", blood type="
+ editPersonDescriptor.getBloodType().orElse(null) + "}";
+ editPersonDescriptor.getBloodType().orElse(null) + ", appointments="
+ editPersonDescriptor.getCondition().orElse(null) + "}";
assertEquals(expected, editPersonDescriptor.toString());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/model/person/DoctorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void equals() {
public void toStringMethod() {
String expected = Doctor.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress() + ", remark=" + ALICE.getRemark()
+ ", gender=" + ALICE.getGender() + ", nric=" + ALICE.getIc() + ", patients=" + ALICE.getAppointments()
+ ", tags=" + ALICE.getTags() + "}";
+ ", gender=" + ALICE.getGender() + ", nric=" + ALICE.getIc()
+ ", appointments=" + ALICE.getAppointments() + ", tags=" + ALICE.getTags() + "}";
assertEquals(expected, ALICE.toString());
}
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/PatientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void toStringMethod() {
+ ", emergency contact=" + ALICE.getEmergencyContact() + ", email=" + ALICE.getEmail() + ", address="
+ ALICE.getAddress() + ", remark=" + ALICE.getRemark() + ", gender=" + ALICE.getGender() + ", nric="
+ ALICE.getIc() + ", condition=" + ALICE.getCondition() + ", bloodType=" + ALICE.getBloodType()
+ ", tags=" + ALICE.getTags() + "}";
+ ", appointments=" + ALICE.getAppointments() + ", tags=" + ALICE.getTags() + "}";
assertEquals(expected, ALICE.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.storage.JsonAdaptedPatient.MISSING_FIELD_MESSAGE_FORMAT;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalAppointment.APPOINTMENT_1;
import static seedu.address.testutil.TypicalPatient.BENSON;

import java.util.ArrayList;
Expand All @@ -21,7 +20,6 @@
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.testutil.TypicalAppointment;

public class JsonAdaptedPatientTest {
private static final String INVALID_NAME = "R@chel";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package seedu.address.testutil;

import java.util.ArrayList;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -55,7 +54,7 @@ public EditPersonDescriptorBuilder(Person person) {
descriptor.setEmergencyContact(patient.getEmergencyContact());
} else if (person instanceof Doctor) {
Doctor doctor = (Doctor) person;
descriptor.setPatients(doctor.getPatients());
descriptor.setAppointments(doctor.getAppointments());
}
}

Expand Down Expand Up @@ -139,15 +138,6 @@ public EditPersonDescriptorBuilder withTags(String... tags) {
return this;
}

/**
* Parses the {@code patients} into a {@code ArrayList<Patient>} and set it to the {@code EditPersonDescriptor}
* that we are building.
*/
public EditPersonDescriptorBuilder withPatients(ArrayList<Patient> patients) {
descriptor.setPatients(patients);
return this;
}

public EditPersonDescriptor build() {
return descriptor;
}
Expand Down

0 comments on commit 6720a9a

Please sign in to comment.