Skip to content

Commit

Permalink
Fix failing test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
erv-teo committed Mar 30, 2024
1 parent 69e9b55 commit ff45099
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, ic, dob, admissionDate, ward, tags, remark);
return CollectionUtil.isAnyNonNull(name, ic, dob, admissionDate, ward, tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -253,9 +253,9 @@ public boolean equals(Object other) {
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("tags", tags)
.add("ic", ic)
.add("dob", dob)
.add("ic", ic)
.add("tags", tags)
.add("admissionDate", admissionDate)
.add("ward", ward)
.add("remark", remark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_IC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_WARD;

Expand Down Expand Up @@ -34,7 +35,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DOB, PREFIX_WARD, PREFIX_IC,
PREFIX_ADMISSION_DATE, PREFIX_TAG);
PREFIX_ADMISSION_DATE, PREFIX_TAG, PREFIX_REMARK);

Index index;

Expand Down Expand Up @@ -67,6 +68,10 @@ public EditCommand parse(String args) throws ParseException {
editPersonDescriptor.setWard(ParserUtil.parseWard(argMultimap.getValue(PREFIX_WARD).get()));
}

if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editPersonDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}

if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.person.Dob;
import seedu.address.model.person.Ic;
import seedu.address.model.person.Name;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Ward;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -141,4 +142,14 @@ public static Ward parseWard(String ward) throws ParseException {
return new Ward(trimmedWard);
}

/**
* Parses a {@code String remark} into a {@code Remark}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Remark parseRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"dob": "20/02/2000",
"ic": "A1234567B",
"admissionDate": "01/03/2024",
"ward":"A1"
"ward":"A1",
"remark":""
}, {
"name": "Alice Pauline",
"dob": "20/02/2000",
"ic": "A1234567B",
"admissionDate": "01/03/2024",
"ward":"A1"
"ward":"A1",
"remark":""
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,54 @@
"ic": "A1234567B",
"admissionDate": "01/03/2024",
"ward":"A1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "Benson Meier",
"tags" : [ "Dementia", "FallRisk" ],
"dob": "20/02/2001",
"ic": "A2345678B",
"admissionDate": "01/02/2024",
"ward": "B1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "Carl Kurz",
"tags" : [ ],
"dob": "20/02/2002",
"ic": "A3456789B",
"admissionDate": "05/03/2024",
"ward": "C1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "Daniel Meier",
"tags" : [ "HearingImpaired" ],
"dob": "20/02/2003",
"ic": "A5678901B",
"admissionDate": "10/03/2024",
"ward": "D1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "Elle Meyer",
"tags" : [ ],
"dob": "20/02/2004",
"ic": "A4756976B",
"admissionDate": "05/02/2024",
"ward": "E1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "Fiona Kunz",
"tags" : [ ],
"dob": "20/02/2006",
"ic": "A5739485B",
"admissionDate": "11/03/2024",
"ward": "F1",
"remark":"This is a remark"
"remark":"This is a remark."
}, {
"name" : "George Best",
"tags" : [ ],
"dob": "20/05/2000",
"ic": "A0987654B",
"admissionDate": "16/03/2024",
"ward": "G1",
"remark":"This is a remark"
"remark":"This is a remark."
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CommandTestUtil {
public static final String VALID_WARD_AMY = "A1";
public static final String VALID_WARD_BOB = "B1";
public static final String VALID_REMARK_AMY = "";
public static final String VALID_REMARK_BOB = "This is a remark.";
public static final String VALID_REMARK_BOB = "Some remark.";

// description + value
public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public void equals() {
public void toStringMethod() {
EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();
String expected = EditPersonDescriptor.class.getCanonicalName() + "{name="
+ editPersonDescriptor.getName().orElse(null) + ", tags="
+ editPersonDescriptor.getDob().orElse(null) + ", ic="
+ editPersonDescriptor.getTags().orElse(null) + ", dob="
+ editPersonDescriptor.getDob().orElse(null) + ", ic="
+ editPersonDescriptor.getName().orElse(null) + ", tags="
+ editPersonDescriptor.getIc().orElse(null) + ", admissionDate="
+ editPersonDescriptor.getAdmissionDate().orElse(null) + ", ward="
+ editPersonDescriptor.getWard().orElse(null) + "}";
+ editPersonDescriptor.getWard().orElse(null) + ", remark="
+ editPersonDescriptor.getRemark().orElse(null) + "}";
assertEquals(expected, editPersonDescriptor.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.testutil.TypicalPersons.AMY;
import static seedu.address.testutil.TypicalPersons.BOB;

import org.junit.jupiter.api.Test;

Expand All @@ -46,20 +45,20 @@ public class AddCommandParserTest {

@Test
public void parse_allFieldsPresent_success() {
Person expectedPerson = new PersonBuilder(BOB).withTags(VALID_TAG_DIABETES).build();
Person expectedPerson = new PersonBuilder(AMY).withTags(VALID_TAG_DIABETES).build();

// whitespace only preamble
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + TAG_DESC_DIABETES + DOB_DESC_BOB + IC_DESC_BOB
+ ADMISSION_DATE_DESC_BOB + WARD_DESC_BOB, new AddCommand(expectedPerson));
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_AMY + TAG_DESC_DIABETES + DOB_DESC_AMY + IC_DESC_AMY
+ ADMISSION_DATE_DESC_AMY + WARD_DESC_AMY, new AddCommand(expectedPerson));


// multiple tags - all accepted
Person expectedPersonMultipleTags = new PersonBuilder(BOB).withTags(VALID_TAG_DIABETES, VALID_TAG_FALL_RISK)
Person expectedPersonMultipleTags = new PersonBuilder(AMY).withTags(VALID_TAG_DIABETES, VALID_TAG_FALL_RISK)
.build();
assertParseSuccess(parser,
NAME_DESC_BOB + TAG_DESC_FALL_RISK + TAG_DESC_DIABETES
+ DOB_DESC_BOB + IC_DESC_BOB
+ ADMISSION_DATE_DESC_BOB + WARD_DESC_BOB,
NAME_DESC_AMY + TAG_DESC_FALL_RISK + TAG_DESC_DIABETES
+ DOB_DESC_AMY + IC_DESC_AMY
+ ADMISSION_DATE_DESC_AMY + WARD_DESC_AMY,
new AddCommand(expectedPersonMultipleTags));
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public void toStringMethod() {
+ ", dob=" + ALICE.getDob()
+ ", ic=" + ALICE.getIc()
+ ", admissionDate=" + ALICE.getAdmissionDate()
+ ", ward=" + ALICE.getWard() + "}";
+ ", ward=" + ALICE.getWard()
+ ", remark=" + ALICE.getRemark() + "}";
assertEquals(expected, ALICE.toString());
}
}
2 changes: 2 additions & 0 deletions src/test/java/seedu/address/testutil/PersonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public static String getEditPersonDescriptorDetails(EditPersonDescriptor descrip
tags.forEach(s -> sb.append(PREFIX_TAG).append(s.tagName).append(" "));
}
}
descriptor.getRemark().ifPresent(remark -> sb.append(PREFIX_REMARK)
.append(remark.value).append(" "));
return sb.toString();
}
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TypicalPersons {
public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB)
.withTags(VALID_TAG_DIABETES, VALID_TAG_FALL_RISK)
.withDob(VALID_DOB_BOB).withIc(VALID_IC_BOB).withAdmissionDate(VALID_ADMISSION_DATE_BOB)
.withWard(VALID_WARD_BOB).withWard(VALID_REMARK_BOB).build();
.withWard(VALID_WARD_BOB).withRemark(VALID_REMARK_BOB).build();

public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

Expand Down

0 comments on commit ff45099

Please sign in to comment.