From 659e296c04aa9bf30985150cf1a7a7cb0eb52a41 Mon Sep 17 00:00:00 2001 From: Vision-2000 <122250743+Vision-2000@users.noreply.github.com> Date: Wed, 20 Mar 2024 00:42:52 +0800 Subject: [PATCH] Modify validation of names and related tests --- src/main/java/seedu/address/model/patient/Name.java | 5 +++-- src/test/java/seedu/address/model/patient/NameTest.java | 9 ++++----- .../java/seedu/address/model/patient/PatientTest.java | 5 ----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/seedu/address/model/patient/Name.java b/src/main/java/seedu/address/model/patient/Name.java index eace75acabf..4a43f152925 100644 --- a/src/main/java/seedu/address/model/patient/Name.java +++ b/src/main/java/seedu/address/model/patient/Name.java @@ -10,13 +10,14 @@ public class Name { public static final String MESSAGE_CONSTRAINTS = - "Names should only contain alphanumeric characters and spaces, and it should not be blank"; + "Names should not be blank, and can only contain letters or a special character (space, " + + "slash \nor dash) surrounded by letters."; /* * The first character of the address must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ - public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String VALIDATION_REGEX = "[A-Za-z](([ -/\\\\][A-Za-z])|[A-Za-z])*"; public final String fullName; diff --git a/src/test/java/seedu/address/model/patient/NameTest.java b/src/test/java/seedu/address/model/patient/NameTest.java index 9903bc9234e..1e848b17545 100644 --- a/src/test/java/seedu/address/model/patient/NameTest.java +++ b/src/test/java/seedu/address/model/patient/NameTest.java @@ -27,15 +27,14 @@ public void isValidName() { // invalid name assertFalse(Name.isValidName("")); // empty string assertFalse(Name.isValidName(" ")); // spaces only - assertFalse(Name.isValidName("^")); // only non-alphanumeric characters - assertFalse(Name.isValidName("peter*")); // contains non-alphanumeric characters + assertFalse(Name.isValidName("^")); // only non-alphabets + assertFalse(Name.isValidName("peter*")); // contains disallowed character // valid name assertTrue(Name.isValidName("peter jack")); // alphabets only - assertTrue(Name.isValidName("12345")); // numbers only - assertTrue(Name.isValidName("peter the 2nd")); // alphanumeric characters + assertTrue(Name.isValidName("peter-jack")); // - between alphabets assertTrue(Name.isValidName("Capital Tan")); // with capital letters - assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names + assertTrue(Name.isValidName("David Roger Jackson Ray Jr The Almighty")); // long names } @Test diff --git a/src/test/java/seedu/address/model/patient/PatientTest.java b/src/test/java/seedu/address/model/patient/PatientTest.java index bc84a17e14d..b3947cc100a 100644 --- a/src/test/java/seedu/address/model/patient/PatientTest.java +++ b/src/test/java/seedu/address/model/patient/PatientTest.java @@ -38,11 +38,6 @@ public void isSamePerson() { // name differs in case, all other attributes same -> returns false Patient editedBob = new PatientBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build(); assertFalse(BOB.isSamePatient(editedBob)); - - // name has trailing spaces, all other attributes same -> returns false - String nameWithTrailingSpaces = VALID_NAME_BOB + " "; - editedBob = new PatientBuilder(BOB).withName(nameWithTrailingSpaces).build(); - assertFalse(BOB.isSamePatient(editedBob)); } @Test