Skip to content

Commit

Permalink
Modify validation of names and related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vision-2000 committed Mar 19, 2024
1 parent d55f447 commit 659e296
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/patient/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions src/test/java/seedu/address/model/patient/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/seedu/address/model/patient/PatientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 659e296

Please sign in to comment.