Skip to content

Commit

Permalink
Merge pull request #273 from Sheeepen/add-Tests
Browse files Browse the repository at this point in the history
Include test case comments
  • Loading branch information
darrentfy authored Nov 13, 2023
2 parents 2ef114a + 1154e55 commit 1da36c7
Show file tree
Hide file tree
Showing 24 changed files with 218 additions and 63 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/AddRemark.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RiskLevel> sameTags = studentToEdit.getTags(); // tags cannot be edited by edit command
Set<RiskLevel> sameTags = studentToEdit.getRiskLevel(); // tags cannot be edited by edit command
Note updatedNote = studentToEdit.getNote();

return new Student(updatedName, updatedPhone, updatedAddress, sameTags, updatedNote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/student/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Address getAddress() {
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<RiskLevel> getTags() {
public Set<RiskLevel> getRiskLevel() {
return Collections.unmodifiableSet(riskLevel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/StudentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
29 changes: 26 additions & 3 deletions src/test/java/seedu/address/model/risklevel/RiskLevelTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
28 changes: 20 additions & 8 deletions src/test/java/seedu/address/model/student/AddressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions src/test/java/seedu/address/model/student/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1da36c7

Please sign in to comment.