Skip to content

Commit

Permalink
Add comments and EPs for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheeepen committed Nov 13, 2023
1 parent 61d9a5e commit 1154e55
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ private boolean appointmentsAreUnique(List<Appointment> appointments) {
return true;
}

/**
* Returns true if {@code appointments} do not overlap with each other.
*/
private boolean appointmentsDoNotOverlap(List<Appointment> appointments) {
for (int i = 0; i < appointments.size() - 1; i++) {
for (int j = i + 1; j < appointments.size(); j++) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/student/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}$";
Expand Down
31 changes: 28 additions & 3 deletions src/test/java/seedu/address/model/appointment/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/test/java/seedu/address/model/appointment/DescriptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/test/java/seedu/address/model/appointment/TimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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, ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1154e55

Please sign in to comment.