From 9ec9d45a9b2a0c679a2ed9055cd6224b603a7cf1 Mon Sep 17 00:00:00 2001 From: Sheeepen Date: Mon, 13 Nov 2023 11:02:28 +0800 Subject: [PATCH 1/4] Add EPs for Risk Level test --- .../model/risklevel/RiskLevelTest.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/address/model/risklevel/RiskLevelTest.java b/src/test/java/seedu/address/model/risklevel/RiskLevelTest.java index cd6c8949919..6a08537e412 100644 --- a/src/test/java/seedu/address/model/risklevel/RiskLevelTest.java +++ b/src/test/java/seedu/address/model/risklevel/RiskLevelTest.java @@ -1,6 +1,8 @@ package seedu.address.model.risklevel; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; @@ -15,14 +17,35 @@ public void constructor_null_throwsNullPointerException() { @Test public void constructor_invalidTagName_throwsIllegalArgumentException() { - String invalidTagName = ""; - assertThrows(IllegalArgumentException.class, () -> new RiskLevel(invalidTagName)); + // EP: empty strings + assertThrows(IllegalArgumentException.class, () -> new RiskLevel("")); + assertThrows(IllegalArgumentException.class, () -> new RiskLevel(" ")); + + // EP: not valid string + assertThrows(IllegalArgumentException.class, () -> new RiskLevel("oogabooga")); } @Test - public void isValidTagName() { + public void isValidRiskLevel() { // null tag name assertThrows(NullPointerException.class, () -> RiskLevel.isValidRiskLevel(null)); + + // EP: empty strings + assertFalse(RiskLevel.isValidRiskLevel("")); + assertFalse(RiskLevel.isValidRiskLevel(" ")); + + // EP: not valid string + assertFalse(RiskLevel.isValidRiskLevel("heehaa")); + + // EP: Invalid due to upper case + assertFalse(RiskLevel.isValidRiskLevel("HIGH")); + assertFalse(RiskLevel.isValidRiskLevel("meDium")); + assertFalse(RiskLevel.isValidRiskLevel("LoW")); + + // EP: Valid strings + assertTrue(RiskLevel.isValidRiskLevel("high")); + assertTrue(RiskLevel.isValidRiskLevel("medium")); + assertTrue(RiskLevel.isValidRiskLevel("low")); } @Test From 8c3cbaa187379af0aabdb7b56049f14f2d267b1a Mon Sep 17 00:00:00 2001 From: Sheeepen Date: Mon, 13 Nov 2023 11:29:14 +0800 Subject: [PATCH 2/4] Update EPs, refactor getTags method --- docs/tutorials/AddRemark.md | 2 +- .../java/seedu/address/logic/Messages.java | 2 +- .../address/logic/commands/EditCommand.java | 2 +- .../address/logic/commands/NoteCommand.java | 2 +- .../seedu/address/model/student/Student.java | 2 +- .../address/storage/JsonAdaptedStudent.java | 2 +- .../java/seedu/address/ui/StudentCard.java | 2 +- .../address/model/student/AddressTest.java | 28 +++++++++++++------ .../seedu/address/model/student/NameTest.java | 27 ++++++++++++------ .../seedu/address/model/student/NoteTest.java | 17 ++++++++--- .../address/model/student/PhoneTest.java | 23 +++++++++++---- .../address/model/student/StudentTest.java | 4 +-- .../storage/JsonAdaptedStudentTest.java | 2 +- .../address/testutil/StudentBuilder.java | 2 +- .../seedu/address/testutil/StudentUtil.java | 2 +- 15 files changed, 81 insertions(+), 38 deletions(-) diff --git a/docs/tutorials/AddRemark.md b/docs/tutorials/AddRemark.md index ddf0eb5b2a1..c1e3ca77e94 100644 --- a/docs/tutorials/AddRemark.md +++ b/docs/tutorials/AddRemark.md @@ -344,7 +344,7 @@ save it with `Model#setPerson()`. Person personToEdit = lastShownList.get(index.getZeroBased()); Person editedPerson = new Person( personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), - personToEdit.getAddress(), remark, personToEdit.getTags()); + personToEdit.getAddress(), remark, personToEdit.getRiskLevel()); model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 849b55e8811..0e3c3e46036 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -49,7 +49,7 @@ public static String format(Student student) { .append("; Address: ") .append(student.getAddress()) .append("; Risk Level: "); - student.getTags().forEach(builder::append); + student.getRiskLevel().forEach(builder::append); return builder.toString(); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 0b4b1ca17be..8166f89c7d3 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -84,7 +84,7 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes Name updatedName = studentToEdit.getName(); Phone updatedPhone = editStudentDescriptor.getPhone().orElse(studentToEdit.getPhone()); Address updatedAddress = editStudentDescriptor.getAddress().orElse(studentToEdit.getAddress()); - Set sameTags = studentToEdit.getTags(); // tags cannot be edited by edit command + Set sameTags = studentToEdit.getRiskLevel(); // tags cannot be edited by edit command Note updatedNote = studentToEdit.getNote(); return new Student(updatedName, updatedPhone, updatedAddress, sameTags, updatedNote); diff --git a/src/main/java/seedu/address/logic/commands/NoteCommand.java b/src/main/java/seedu/address/logic/commands/NoteCommand.java index f4c11dd8100..df9a66580ea 100644 --- a/src/main/java/seedu/address/logic/commands/NoteCommand.java +++ b/src/main/java/seedu/address/logic/commands/NoteCommand.java @@ -54,7 +54,7 @@ public CommandResult execute(Model model) throws CommandException { Student studentToEdit = lastShownList.get(index.getZeroBased()); Student editedStudent = new Student(studentToEdit.getName(), studentToEdit.getPhone(), - studentToEdit.getAddress(), studentToEdit.getTags(), note); + studentToEdit.getAddress(), studentToEdit.getRiskLevel(), note); model.setStudent(studentToEdit, editedStudent); model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS); diff --git a/src/main/java/seedu/address/model/student/Student.java b/src/main/java/seedu/address/model/student/Student.java index 24f5a9868c4..8848c11cb56 100644 --- a/src/main/java/seedu/address/model/student/Student.java +++ b/src/main/java/seedu/address/model/student/Student.java @@ -55,7 +55,7 @@ public Address getAddress() { * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. */ - public Set getTags() { + public Set getRiskLevel() { return Collections.unmodifiableSet(riskLevel); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java index 1dee66ab247..16468d43903 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedStudent.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedStudent.java @@ -55,7 +55,7 @@ public JsonAdaptedStudent(Student source) { name = source.getName().value; phone = source.getPhone().value; address = source.getAddress().value; - tags.addAll(source.getTags().stream() + tags.addAll(source.getRiskLevel().stream() .map(JsonAdaptedRiskLevel::new) .collect(Collectors.toList())); note = source.getNote().value; diff --git a/src/main/java/seedu/address/ui/StudentCard.java b/src/main/java/seedu/address/ui/StudentCard.java index 062a238be45..32b036f77b2 100644 --- a/src/main/java/seedu/address/ui/StudentCard.java +++ b/src/main/java/seedu/address/ui/StudentCard.java @@ -54,7 +54,7 @@ public StudentCard(Student student, int displayedIndex, CommandExecutor showNote phone.setText(student.getPhone().value); address.setText(student.getAddress().value); - student.getTags().forEach(tag -> { + student.getRiskLevel().forEach(tag -> { Label tagLabel = new Label(tag.riskLevel); tagLabel.getStyleClass().add(getTagStyleClass(tag.riskLevel)); tags.getChildren().add(tagLabel); diff --git a/src/test/java/seedu/address/model/student/AddressTest.java b/src/test/java/seedu/address/model/student/AddressTest.java index a9e8f9aca3f..8cc029720f6 100644 --- a/src/test/java/seedu/address/model/student/AddressTest.java +++ b/src/test/java/seedu/address/model/student/AddressTest.java @@ -24,18 +24,30 @@ public void isValidAddress() { String twoHundredCharAddress = "Krung Thep Mahanakhon Amon Rattanakosin Mahinthara Ayuthaya Mahadilok Phop " + "Noppharat Ratchathani Burirom Udomratchaniwet Mahasathan Amon Piman Awatan Sathit Sakkathattiya " + "Witsanukam Prasit aka Bangkok"; - // null address + + + // Invalid addresses + + // EP: null address assertThrows(NullPointerException.class, () -> Address.isValidAddress(null)); - // invalid addresses + + // EP: empty strings (0 characters or blank space) assertFalse(Address.isValidAddress("")); // empty string - assertFalse(Address.isValidAddress(" ")); // spaces only - assertFalse(Address.isValidAddress(twoHundredCharAddress + "a")); // more than 200 characters + assertFalse(Address.isValidAddress(" ")); // blank space + + // EP: exceed 200 characters + assertFalse(Address.isValidAddress(twoHundredCharAddress + "a")); // 201 characters + + + // Valid addresses + + // EP: exactly one character + assertTrue(Address.isValidAddress("-")); + + // EP: exactly 200 characters + assertTrue(Address.isValidAddress(twoHundredCharAddress)); - // valid addresses - assertTrue(Address.isValidAddress("Blk 456, Den Road, #01-355")); - assertTrue(Address.isValidAddress("-")); // one character - assertTrue(Address.isValidAddress(twoHundredCharAddress)); // exactly 200 characters } @Test diff --git a/src/test/java/seedu/address/model/student/NameTest.java b/src/test/java/seedu/address/model/student/NameTest.java index 5fd457f3556..1aa316907f9 100644 --- a/src/test/java/seedu/address/model/student/NameTest.java +++ b/src/test/java/seedu/address/model/student/NameTest.java @@ -23,23 +23,34 @@ public void constructor_invalidName_throwsIllegalArgumentException() { public void isValidName() { String hundredCharName = "Ali Ben Ching Dover Elephant Fishballs Ginormous Hugh Indiana Jelly Krispy " + "Lambasted Mamamia Nutella"; - // null name + + // EP: null name assertThrows(NullPointerException.class, () -> Name.isValidName(null)); - // invalid name + // invalid names + // EP: empty strings assertFalse(Name.isValidName("")); // empty string assertFalse(Name.isValidName(" ")); // spaces only + + // EP : non-alphabetical characters assertFalse(Name.isValidName("^")); // only non-alphabetical characters assertFalse(Name.isValidName("peter*")); // contains non-alphabetical characters assertFalse(Name.isValidName("12345")); // numbers only assertFalse(Name.isValidName("peter the 2nd")); // contains numbers - assertFalse(Name.isValidName(hundredCharName + "a")); // more than 100 characters - // valid name - assertTrue(Name.isValidName("A")); // single alphabet only - assertTrue(Name.isValidName("peter jack")); // alphabets only - assertTrue(Name.isValidName("Capital Tan")); // with capital letters - assertTrue(Name.isValidName(hundredCharName)); // exactly 100 characters + // EP: more than 100 characters + assertFalse(Name.isValidName(hundredCharName + "a")); // 101 characters + + + // valid names + // EP: one character alphabet only + assertTrue(Name.isValidName("a")); + + // EP: Alphabetical characters with capital letters + assertTrue(Name.isValidName("Capital Tan")); + + // EP: 100 alphabetical characters + assertTrue(Name.isValidName(hundredCharName)); } @Test diff --git a/src/test/java/seedu/address/model/student/NoteTest.java b/src/test/java/seedu/address/model/student/NoteTest.java index b7595f0ecb0..4e8cb261ea5 100644 --- a/src/test/java/seedu/address/model/student/NoteTest.java +++ b/src/test/java/seedu/address/model/student/NoteTest.java @@ -33,17 +33,26 @@ public void isValidNote() { + "bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrs" + "tuvwxyzabcdefghijklmnopqrstuvwxyzabcdef"; - // null note + // EP: null note assertThrows(NullPointerException.class, () -> Note.isValidNote(null)); // invalid notes - assertFalse(Note.isValidNote(fiveHundredCharNote + "a")); // more than 500 characters + // EP: more than 500 characters + assertFalse(Note.isValidNote(fiveHundredCharNote + "a")); //501 characters - // valid note numbers + // valid notes + // EP: 0 characters or empty strings assertTrue(Note.isValidNote("")); // empty string - assertTrue(Note.isValidNote("Likes dogs.")); + assertTrue(Note.isValidNote(" ")); // blank space + + // EP: Exactly 1 character assertTrue(Note.isValidNote("a")); // 1 character + + // EP: Exactly 500 characters assertTrue(Note.isValidNote(fiveHundredCharNote)); // exactly 500 characters + + // EP: With special characters + assertTrue(Note.isValidNote("The 3rd session was very ****fire****")); } @Test diff --git a/src/test/java/seedu/address/model/student/PhoneTest.java b/src/test/java/seedu/address/model/student/PhoneTest.java index 937ddbbc28a..b4266418750 100644 --- a/src/test/java/seedu/address/model/student/PhoneTest.java +++ b/src/test/java/seedu/address/model/student/PhoneTest.java @@ -21,21 +21,32 @@ public void constructor_invalidPhone_throwsIllegalArgumentException() { @Test public void isValidPhone() { - // null phone number + // EP: null phone number assertThrows(NullPointerException.class, () -> Phone.isValidPhone(null)); // invalid phone numbers + // EP: empty strings assertFalse(Phone.isValidPhone("")); // empty string assertFalse(Phone.isValidPhone(" ")); // spaces only - assertFalse(Phone.isValidPhone("91")); // less than 3 numbers - assertFalse(Phone.isValidPhone("phone")); // non-numeric - assertFalse(Phone.isValidPhone("9011p041")); // alphabets within digits + + // EP: non-numeric strings + assertFalse(Phone.isValidPhone("Stephens")); // contains alphabetical characters + assertFalse(Phone.isValidPhone("!@#$%^&*")); // contains special characters + + // EP: 7 characters + assertFalse(Phone.isValidPhone("1234567")); // 7 characters exactly + + // EP: 9 characters + assertFalse(Phone.isValidPhone("123456789")); // 9 characters exactly + + // EP: spaces between digits assertFalse(Phone.isValidPhone("9312 1534")); // spaces within digits - assertFalse(Phone.isValidPhone("124293842033123")); // long phone numbers + // valid phone numbers + // EP: 8 characters assertTrue(Phone.isValidPhone("91141523")); // exactly 8 numbers - assertTrue(Phone.isValidPhone("93121534")); + assertTrue(Phone.isValidPhone("12345678")); // any 8 } @Test diff --git a/src/test/java/seedu/address/model/student/StudentTest.java b/src/test/java/seedu/address/model/student/StudentTest.java index f9dbc9be8ac..895b101702f 100644 --- a/src/test/java/seedu/address/model/student/StudentTest.java +++ b/src/test/java/seedu/address/model/student/StudentTest.java @@ -20,7 +20,7 @@ public class StudentTest { @Test public void asObservableList_modifyList_throwsUnsupportedOperationException() { Student student = new StudentBuilder().build(); - assertThrows(UnsupportedOperationException.class, () -> student.getTags().remove(0)); + assertThrows(UnsupportedOperationException.class, () -> student.getRiskLevel().remove(0)); } @Test @@ -88,7 +88,7 @@ public void equals() { @Test public void toStringMethod() { String expected = Student.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone() - + ", address=" + ALICE.getAddress() + ", risk level=" + ALICE.getTags() + + ", address=" + ALICE.getAddress() + ", risk level=" + ALICE.getRiskLevel() + ", note=" + ALICE.getNote() + "}"; assertEquals(expected, ALICE.toString()); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java b/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java index 3152dee3314..6998c062743 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedStudentTest.java @@ -26,7 +26,7 @@ public class JsonAdaptedStudentTest { private static final String VALID_NAME = BENNY.getName().toString(); private static final String VALID_PHONE = BENNY.getPhone().toString(); private static final String VALID_ADDRESS = BENNY.getAddress().toString(); - private static final List VALID_TAGS = BENNY.getTags().stream() + private static final List VALID_TAGS = BENNY.getRiskLevel().stream() .map(JsonAdaptedRiskLevel::new) .collect(Collectors.toList()); private static final String VALID_NOTE = BENNY.getNote().toString(); diff --git a/src/test/java/seedu/address/testutil/StudentBuilder.java b/src/test/java/seedu/address/testutil/StudentBuilder.java index c19aecfcaab..906359210e7 100644 --- a/src/test/java/seedu/address/testutil/StudentBuilder.java +++ b/src/test/java/seedu/address/testutil/StudentBuilder.java @@ -45,7 +45,7 @@ public StudentBuilder(Student studentToCopy) { name = studentToCopy.getName(); phone = studentToCopy.getPhone(); address = studentToCopy.getAddress(); - riskLevel = new HashSet<>(studentToCopy.getTags()); + riskLevel = new HashSet<>(studentToCopy.getRiskLevel()); note = studentToCopy.getNote(); } diff --git a/src/test/java/seedu/address/testutil/StudentUtil.java b/src/test/java/seedu/address/testutil/StudentUtil.java index 6ff43144749..202ca82631a 100644 --- a/src/test/java/seedu/address/testutil/StudentUtil.java +++ b/src/test/java/seedu/address/testutil/StudentUtil.java @@ -29,7 +29,7 @@ public static String getStudentDetails(Student student) { sb.append(PREFIX_NAME + student.getName().value + " "); sb.append(PREFIX_PHONE + student.getPhone().value + " "); sb.append(PREFIX_ADDRESS + student.getAddress().value + " "); - student.getTags().stream().forEach( + student.getRiskLevel().stream().forEach( s -> sb.append(PREFIX_RISK_LEVEL + s.riskLevel + " ") ); return sb.toString(); From 61d9a5e1b320a541b493af6fd7fcd4de8b86ba34 Mon Sep 17 00:00:00 2001 From: Sheeepen Date: Mon, 13 Nov 2023 12:06:56 +0800 Subject: [PATCH 3/4] Reorganise, add comments for tests --- .../model/student/UniqueStudentListTest.java | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/test/java/seedu/address/model/student/UniqueStudentListTest.java b/src/test/java/seedu/address/model/student/UniqueStudentListTest.java index 0b4c3a934fc..92a8c892ffb 100644 --- a/src/test/java/seedu/address/model/student/UniqueStudentListTest.java +++ b/src/test/java/seedu/address/model/student/UniqueStudentListTest.java @@ -23,22 +23,27 @@ public class UniqueStudentListTest { private final UniqueStudentList uniqueStudentList = new UniqueStudentList(); + // Tests for contains method + // null object @Test public void contains_nullStudent_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.contains(null)); } + // student not in list @Test public void contains_studentNotInList_returnsFalse() { assertFalse(uniqueStudentList.contains(ALICE)); } + // exact student in list @Test public void contains_studentInList_returnsTrue() { uniqueStudentList.add(ALICE); assertTrue(uniqueStudentList.contains(ALICE)); } + // student with same name in list @Test public void contains_studentWithSameIdentityFieldsInList_returnsTrue() { uniqueStudentList.add(ALICE); @@ -47,17 +52,31 @@ public void contains_studentWithSameIdentityFieldsInList_returnsTrue() { assertTrue(uniqueStudentList.contains(editedAlice)); } + + // Tests for add method + // null object @Test public void add_nullStudent_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.add(null)); } + // duplicate student, throws error @Test public void add_duplicateStudent_throwsDuplicateStudentException() { uniqueStudentList.add(ALICE); assertThrows(DuplicateStudentException.class, () -> uniqueStudentList.add(ALICE)); } + // different student name + @Test + public void add_uniqueStudent_success() { + uniqueStudentList.add(ALICE); + Student newStudent = new StudentBuilder(ALICE).withName("Bobby Low").build(); + uniqueStudentList.add(newStudent); + } + + // Tests for setStudent method + // null objects @Test public void setStudent_nullTargetStudent_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.setStudent(null, ALICE)); @@ -68,11 +87,13 @@ public void setStudent_nullEditedStudent_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.setStudent(ALICE, null)); } + // student does not exist (list is currently empty) @Test public void setStudent_targetStudentNotInList_throwsStudentNotFoundException() { assertThrows(StudentNotFoundException.class, () -> uniqueStudentList.setStudent(ALICE, ALICE)); } + // student can be found in list -> success @Test public void setStudent_editedStudentIsSameStudent_success() { uniqueStudentList.add(ALICE); @@ -82,6 +103,7 @@ public void setStudent_editedStudentIsSameStudent_success() { assertEquals(expectedUniqueStudentList, uniqueStudentList); } + @Test public void setStudent_editedStudentHasSameIdentity_success() { uniqueStudentList.add(ALICE); @@ -102,6 +124,7 @@ public void setStudent_editedStudentHasDifferentIdentity_success() { assertEquals(expectedUniqueStudentList, uniqueStudentList); } + // Edit student to have same name will not work @Test public void setStudent_editedStudentHasNonUniqueIdentity_throwsDuplicateStudentException() { uniqueStudentList.add(ALICE); @@ -109,16 +132,21 @@ public void setStudent_editedStudentHasNonUniqueIdentity_throwsDuplicateStudentE assertThrows(DuplicateStudentException.class, () -> uniqueStudentList.setStudent(ALICE, BOB)); } + + // Tests for remove method + // null object @Test public void remove_nullStudent_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.remove(null)); } + // Student does not exist @Test public void remove_studentDoesNotExist_throwsStudentNotFoundException() { assertThrows(StudentNotFoundException.class, () -> uniqueStudentList.remove(ALICE)); } + // Success case @Test public void remove_existingStudent_removesStudent() { uniqueStudentList.add(ALICE); @@ -127,11 +155,20 @@ public void remove_existingStudent_removesStudent() { assertEquals(expectedUniqueStudentList, uniqueStudentList); } + + // Tests for setStudents method, different from setStudent method + // null objects @Test public void setStudents_nullUniqueStudentList_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueStudentList.setStudents((UniqueStudentList) null)); } + @Test + public void setStudents_nullList_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueStudentList.setStudents((List) null)); + } + + // Success cases @Test public void setStudents_uniqueStudentList_replacesOwnListWithProvidedUniqueStudentList() { uniqueStudentList.add(ALICE); @@ -141,10 +178,6 @@ public void setStudents_uniqueStudentList_replacesOwnListWithProvidedUniqueStude assertEquals(expectedUniqueStudentList, uniqueStudentList); } - @Test - public void setStudents_nullList_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueStudentList.setStudents((List) null)); - } @Test public void setStudents_list_replacesOwnListWithProvidedList() { @@ -156,12 +189,14 @@ public void setStudents_list_replacesOwnListWithProvidedList() { assertEquals(expectedUniqueStudentList, uniqueStudentList); } + // Duplicate list -> throws error @Test public void setStudents_listWithDuplicateStudents_throwsDuplicateStudentException() { List listWithDuplicateStudents = Arrays.asList(ALICE, ALICE); assertThrows(DuplicateStudentException.class, () -> uniqueStudentList.setStudents(listWithDuplicateStudents)); } + // UnmodifiableObservableList cannot be modified @Test public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { assertThrows(UnsupportedOperationException.class, () From 1154e5533ae75732468087ce162445ae02eaf20a Mon Sep 17 00:00:00 2001 From: Sheeepen Date: Mon, 13 Nov 2023 13:20:39 +0800 Subject: [PATCH 4/4] Add comments and EPs for tests --- .../model/appointment/Description.java | 2 +- .../appointment/UniqueAppointmentList.java | 3 ++ .../seedu/address/model/student/Name.java | 2 +- .../address/model/appointment/DateTest.java | 31 +++++++++++++++++-- .../model/appointment/DescriptionTest.java | 22 +++++++------ .../address/model/appointment/TimeTest.java | 19 +++++++++--- .../UniqueAppointmentListTest.java | 10 ++++++ .../model/student/UniqueStudentListTest.java | 1 + 8 files changed, 72 insertions(+), 18 deletions(-) diff --git a/src/main/java/seedu/address/model/appointment/Description.java b/src/main/java/seedu/address/model/appointment/Description.java index 62b8b23b84d..e53f25dd275 100644 --- a/src/main/java/seedu/address/model/appointment/Description.java +++ b/src/main/java/seedu/address/model/appointment/Description.java @@ -10,7 +10,7 @@ public class Description { public static final String MESSAGE_CONSTRAINTS = "Description should have a minimum length of 1 character and maximum length of 100 characters"; - public static final String VALIDATION_REGEX = ".{1,100}"; + public static final String VALIDATION_REGEX = "^(?!\\s*$).{1,100}$"; public final String value; /** diff --git a/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java b/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java index 65310165025..a521ec45009 100644 --- a/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java +++ b/src/main/java/seedu/address/model/appointment/UniqueAppointmentList.java @@ -145,6 +145,9 @@ private boolean appointmentsAreUnique(List appointments) { return true; } + /** + * Returns true if {@code appointments} do not overlap with each other. + */ private boolean appointmentsDoNotOverlap(List appointments) { for (int i = 0; i < appointments.size() - 1; i++) { for (int j = i + 1; j < appointments.size(); j++) { diff --git a/src/main/java/seedu/address/model/student/Name.java b/src/main/java/seedu/address/model/student/Name.java index 87690c68752..9279bab27af 100644 --- a/src/main/java/seedu/address/model/student/Name.java +++ b/src/main/java/seedu/address/model/student/Name.java @@ -13,7 +13,7 @@ public class Name { + " have a maximum of 100 characters, and should not be blank"; /* - * The first character of the address must not be a whitespace, + * The first character of the name must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ public static final String VALIDATION_REGEX = "^[A-Za-z][A-Za-z ]{0,99}$"; diff --git a/src/test/java/seedu/address/model/appointment/DateTest.java b/src/test/java/seedu/address/model/appointment/DateTest.java index 7dedfd10a15..1e52e6ff460 100644 --- a/src/test/java/seedu/address/model/appointment/DateTest.java +++ b/src/test/java/seedu/address/model/appointment/DateTest.java @@ -22,19 +22,44 @@ public void constructor_invalidDate_throwsIllegalArgumentException() { @Test public void isValidDate() { // valid Date + // EP: follows yyyy-MM-dd format assertTrue(Date.isValidDate("2023-10-14")); assertTrue(Date.isValidDate("2023-11-14")); assertTrue(Date.isValidDate("2023-10-31")); - // invalid Date + // invalid Date: does not follow yyyy-MM-dd format + // EP: extra characters assertFalse(Date.isValidDate("2023-10-14 15:30")); // includes time - assertFalse(Date.isValidDate("15:30")); // only time, no date assertFalse(Date.isValidDate("2023-10-14 15:")); // incomplete assertFalse(Date.isValidDate("2023-10-14 15:301")); // extra digit + + // EP: too little characters + assertFalse(Date.isValidDate("15:30")); // only time, no date + + // EP: non-numerical characters assertFalse(Date.isValidDate("2023-10-14 15:AM")); // contains non-digit + + // EP: not using dashes + assertFalse(Date.isValidDate("2023:10:14")); // contains ":" + assertFalse(Date.isValidDate("2023/10/14")); // contains "/" + + // invalid Date: out of bounds date and month + + // EP: out of bounds for date and month assertFalse(Date.isValidDate("2023-13-14")); // month 13 assertFalse(Date.isValidDate("2023-10-32")); // day 32 - assertFalse(Date.isValidDate("1999-10-14")); // year 1999 + assertFalse(Date.isValidDate("1999-10-14")); // year 1999, in the past + assertFalse(Date.isValidDate("8000-10-14")); // year 8000, too far in the future, must be within a year + + + // February special cases + + // EP: february max 28 days on non-leap year + assertFalse(Date.isValidDate("2023-02-29")); // non-leap year + assertTrue(Date.isValidDate("2023-02-28")); + + // EP: february 29th day on leap year + assertTrue(Date.isValidDate("2024-02-29")); } @Test diff --git a/src/test/java/seedu/address/model/appointment/DescriptionTest.java b/src/test/java/seedu/address/model/appointment/DescriptionTest.java index cc032583843..10aa4ea910e 100644 --- a/src/test/java/seedu/address/model/appointment/DescriptionTest.java +++ b/src/test/java/seedu/address/model/appointment/DescriptionTest.java @@ -21,22 +21,26 @@ public void constructor_invalidDescription_throwsIllegalArgumentException() { @Test public void isValidDescription() { - // null description + String hundredCharDescription = + "2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKzV4nSsD7iU0lFyRwC2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKz"; + + // EP: null description assertThrows(NullPointerException.class, () -> new Description(null)); // invalid descriptions + // EP: empty string assertFalse(Description.isValidDescription("")); // empty string - assertFalse(Description.isValidDescription( - "2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKzV4nSsD7iU0lFyRwC2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKz1") - ); // 101 characters + assertFalse(Description.isValidDescription(" ")); // empty string + + // EP: more than 100 characters + assertFalse(Description.isValidDescription(hundredCharDescription + "a")); // 101 characters // valid descriptions + // EP: 1 character assertTrue(Description.isValidDescription("a")); // exactly 1 character - assertTrue(Description.isValidDescription("test description")); - assertTrue(Description.isValidDescription("this is a very very long description")); // long descriptions - assertTrue(Description.isValidDescription( - "2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKzV4nSsD7iU0lFyRwC2jT#L8p!@o9QYdG*cZr$uAqXtW%vI3hN6fE5bJ1mKz") - ); // exactly 100 characters + + // EP: 100 characters, including special characters + assertTrue(Description.isValidDescription(hundredCharDescription)); // exactly 100 characters } @Test diff --git a/src/test/java/seedu/address/model/appointment/TimeTest.java b/src/test/java/seedu/address/model/appointment/TimeTest.java index 84d85234742..978d0fc903e 100644 --- a/src/test/java/seedu/address/model/appointment/TimeTest.java +++ b/src/test/java/seedu/address/model/appointment/TimeTest.java @@ -26,12 +26,23 @@ public void isValidTime() { assertTrue(Time.isValidTime("12:10")); assertTrue(Time.isValidTime("00:00")); - // invalid Time + // invalid Time: does not follow HH:mm format + // EP: extra characters assertFalse(Time.isValidTime("2023-10-14 15:30")); // includes date - assertFalse(Time.isValidTime("15:")); // incomplete assertFalse(Time.isValidTime("15:301")); // extra digit - assertFalse(Time.isValidTime("15:AM")); // contains non-digit - assertFalse(Time.isValidTime("25:00")); // hour 25 + + // EP: too little characters + assertFalse(Time.isValidTime("15:")); // incomplete + + // EP: non-numerical characters + assertFalse(Time.isValidTime("15:AM")); // contains alphabetical characters + assertFalse(Time.isValidTime("15:##")); // contains special characters + + // EP: outside of 00:00 to 24:00 + assertFalse(Time.isValidTime("25:00")); + assertFalse(Time.isValidTime("24:01")); + + // EP: outside of xx:00 to xx:59 assertFalse(Time.isValidTime("15:60")); // 60 minutes } diff --git a/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java b/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java index d6005e4d65e..05280c0ef97 100644 --- a/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java +++ b/src/test/java/seedu/address/model/appointment/UniqueAppointmentListTest.java @@ -24,11 +24,15 @@ public class UniqueAppointmentListTest { private final UniqueAppointmentList uniqueAppointmentList = new UniqueAppointmentList(); + // Test for contains method + + // null object @Test public void contains_nullAppointment_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueAppointmentList.contains(null)); } + // appointment not in list @Test public void contains_appointmentNotInList_returnsFalse() { assertFalse(uniqueAppointmentList.contains(ALICE_APPOINTMENT)); @@ -49,6 +53,8 @@ public void contains_appointmentWithSameFieldsInList_returnsTrue() { assertTrue(uniqueAppointmentList.contains(editedAlex)); } + // Tests for add method + @Test public void add_nullAppointment_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueAppointmentList.add(null)); @@ -60,6 +66,8 @@ public void add_duplicateAppointment_throwsDuplicateAppointmentException() { assertThrows(DuplicateAppointmentException.class, () -> uniqueAppointmentList.add(ALICE_APPOINTMENT)); } + // Tests for remove method + @Test public void remove_nullAppointment_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> uniqueAppointmentList.remove(null)); @@ -78,6 +86,7 @@ public void remove_existingAppointment_removesAppointment() { assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList); } + // Tests for removeRelatedAppointments method @Test public void removeRelatedAppointments_existingAppointment_removesAppointment() { uniqueAppointmentList.add(ALICE_APPOINTMENT); @@ -95,6 +104,7 @@ public void removeRelatedAppointments_existingAppointment_removesAllAppointments assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList); } + // UnmodifiableObservableList cannot be modified @Test public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationException() { assertThrows(UnsupportedOperationException.class, () diff --git a/src/test/java/seedu/address/model/student/UniqueStudentListTest.java b/src/test/java/seedu/address/model/student/UniqueStudentListTest.java index 92a8c892ffb..bcd727a9bb4 100644 --- a/src/test/java/seedu/address/model/student/UniqueStudentListTest.java +++ b/src/test/java/seedu/address/model/student/UniqueStudentListTest.java @@ -24,6 +24,7 @@ public class UniqueStudentListTest { private final UniqueStudentList uniqueStudentList = new UniqueStudentList(); // Tests for contains method + // null object @Test public void contains_nullStudent_throwsNullPointerException() {