Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify validation of names and related tests #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this case being removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're disallowing numbers. If you mean that it should be moved to a negative test, I could do that

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
4 changes: 0 additions & 4 deletions src/test/java/seedu/address/model/patient/PatientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public void isSamePatient() {
Patient editedBob = new PatientBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
assertFalse(BOB.isSamePatient(editedBob));

// different phone number, all other attributes same -> returns false
editedBob = new PatientBuilder(BOB).withPhone(VALID_PHONE_AMY).build();
assertFalse(BOB.isSamePatient(editedBob));

// different phone number and different name, all other attributes same -> returns false
editedBob = new PatientBuilder(BOB).withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY).build();
assertFalse(BOB.isSamePatient(editedBob));
Expand Down
Loading