From 852b44662fc088930ac267c59164789f2e015dff Mon Sep 17 00:00:00 2001 From: JYL27 Date: Wed, 6 Nov 2024 00:27:25 +0800 Subject: [PATCH] Fix phone number format bug --- src/main/java/seedu/address/model/person/Phone.java | 4 ++-- .../typicalPersonsEduContacts.json | 6 +++--- .../seedu/address/logic/parser/ParserUtilTest.java | 2 +- .../person/NameContainsKeywordsPredicateTest.java | 2 +- .../java/seedu/address/model/person/PhoneTest.java | 11 +++++------ .../java/seedu/address/testutil/TypicalPersons.java | 10 +++++----- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index 122faa9ddb0..e91ff206254 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -11,8 +11,8 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = - "Phone numbers should only contain numbers, and it should be at least 3 digits long"; - public static final String VALIDATION_REGEX = "\\d{3,}"; + "Phone numbers should only contain numbers, and it should be at least 8 digits long"; + public static final String VALIDATION_REGEX = "\\d{8,}"; public final String value; /** diff --git a/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json b/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json index 2c14094c707..fd79c572a7f 100644 --- a/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json +++ b/src/test/data/JsonSerializableEduContactsTest/typicalPersonsEduContacts.json @@ -53,7 +53,7 @@ }, { "studentId": "25252525", "name" : "Elle Meyer", - "phone" : "9482224", + "phone" : "94822244", "email" : "werner@example.com", "address" : "michegan ave", "course": "biomedical engineering", @@ -68,7 +68,7 @@ }, { "studentId": "98989898", "name" : "Fiona Kunz", - "phone" : "9482427", + "phone" : "94824272", "email" : "lydia@example.com", "address" : "little tokyo", "course": "Data Science", @@ -76,7 +76,7 @@ }, { "studentId": "28184003", "name" : "George Best", - "phone" : "9482442", + "phone" : "94824422", "email" : "anna@example.com", "address" : "4th street", "course": "Dentistry", diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 8de427470f2..3f01b92f364 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -21,7 +21,7 @@ public class ParserUtilTest { private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = "Rachel Walker"; - private static final String VALID_PHONE = "123456"; + private static final String VALID_PHONE = "12345678"; private static final String VALID_ADDRESS = "123 Main Street #0505"; private static final String VALID_EMAIL = "rachel@example.com"; private static final String VALID_TAG_1 = "Student"; diff --git a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java index 7251d9c3d8a..dc1917faba9 100644 --- a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java @@ -63,7 +63,7 @@ public void test_nameDoesNotContainKeywords_returnsFalse() { assertFalse(predicate.test(new PersonBuilder().withName("Alice Bob").build())); predicate = new NameContainsKeywordsPredicate(Arrays.asList("12345", "alice@email.com", "Main", "Street")); - assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345") + assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345678") .withEmail("alice@email.com").withAddress("Main Street").build())); } diff --git a/src/test/java/seedu/address/model/person/PhoneTest.java b/src/test/java/seedu/address/model/person/PhoneTest.java index deaaa5ba190..859318534d4 100644 --- a/src/test/java/seedu/address/model/person/PhoneTest.java +++ b/src/test/java/seedu/address/model/person/PhoneTest.java @@ -27,23 +27,22 @@ public void isValidPhone() { // invalid phone numbers assertFalse(Phone.isValidPhone("")); // empty string assertFalse(Phone.isValidPhone(" ")); // spaces only - assertFalse(Phone.isValidPhone("91")); // less than 3 numbers + assertFalse(Phone.isValidPhone("911")); // less than 8 numbers assertFalse(Phone.isValidPhone("phone")); // non-numeric assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits // valid phone numbers - assertTrue(Phone.isValidPhone("911")); // exactly 3 numbers - assertTrue(Phone.isValidPhone("93121534")); + assertTrue(Phone.isValidPhone("93121534")); // exactly 8 numbers assertTrue(Phone.isValidPhone("124293842033123")); // long phone numbers } @Test public void equals() { - Phone phone = new Phone("999"); + Phone phone = new Phone("99999999"); // same values -> returns true - assertTrue(phone.equals(new Phone("999"))); + assertTrue(phone.equals(new Phone("99999999"))); // same object -> returns true assertTrue(phone.equals(phone)); @@ -55,6 +54,6 @@ public void equals() { assertFalse(phone.equals(5.0f)); // different values -> returns false - assertFalse(phone.equals(new Phone("995"))); + assertFalse(phone.equals(new Phone("99599959"))); } } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 6173842e7a2..314fd8fcba5 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -75,7 +75,7 @@ public class TypicalPersons { public static final Person ELLE = new PersonBuilder() .withStudentId("25252525") .withName("Elle Meyer") - .withPhone("9482224") + .withPhone("94822244") .withEmail("werner@example.com") .withAddress("michegan ave") .withCourse("biomedical engineering") @@ -86,7 +86,7 @@ public class TypicalPersons { public static final Person FIONA = new PersonBuilder() .withStudentId("98989898") .withName("Fiona Kunz") - .withPhone("9482427") + .withPhone("94824272") .withEmail("lydia@example.com") .withAddress("little tokyo") .withCourse("Data Science") @@ -95,7 +95,7 @@ public class TypicalPersons { public static final Person GEORGE = new PersonBuilder() .withStudentId("28184003") .withName("George Best") - .withPhone("9482442") + .withPhone("94824422") .withEmail("anna@example.com") .withAddress("4th street") .withCourse("Dentistry") @@ -108,7 +108,7 @@ public class TypicalPersons { public static final Person HOON = new PersonBuilder() .withStudentId("15159888") .withName("Hoon Meier") - .withPhone("8482424") + .withPhone("84842424") .withEmail("stefan@example.com") .withAddress("little india") .withCourse("Mechanical engineering") @@ -117,7 +117,7 @@ public class TypicalPersons { public static final Person IDA = new PersonBuilder() .withStudentId("48883999") .withName("Ida Mueller") - .withPhone("8482131") + .withPhone("84842131") .withEmail("hans@example.com") .withAddress("chicago ave") .withCourse("Architecture")