forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/test/java/seedu/address/model/person/AppointmentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package seedu.address.model.person; | ||
|
||
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 org.junit.jupiter.api.Test; | ||
|
||
public class AppointmentTest { | ||
|
||
@Test | ||
public void equals() { | ||
Appointment firstAppointment = new Appointment("01-01-2024 12:00"); | ||
Appointment secondAppointment = new Appointment("02-02-2024 15:00"); | ||
|
||
// same object -> returns true | ||
assertTrue(firstAppointment.equals(firstAppointment)); | ||
|
||
// same values -> returns true | ||
Appointment firstAppointmentCopy = new Appointment("01-01-2024 12:00"); | ||
assertTrue(firstAppointment.equals(firstAppointmentCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstAppointment.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstAppointment.equals(null)); | ||
|
||
// different appointments -> returns false | ||
assertFalse(firstAppointment.equals(secondAppointment)); | ||
} | ||
|
||
@Test | ||
public void test_toString_returnsCorrectFormat() { | ||
Appointment appointment = new Appointment("01-01-2024 12:00"); | ||
assertEquals("01-01-2024 12:00", appointment.toString()); | ||
} | ||
|
||
@Test | ||
public void test_equalsSymmetry() { | ||
Appointment appointmentA = new Appointment("03-03-2024 09:00"); | ||
Appointment appointmentB = new Appointment("03-03-2024 09:00"); | ||
|
||
// Symmetry: a.equals(b) == b.equals(a) | ||
assertTrue(appointmentA.equals(appointmentB)); | ||
assertTrue(appointmentB.equals(appointmentA)); | ||
} | ||
|
||
@Test | ||
public void test_appointmentMatchesDateTime() { | ||
// Check if the date and time matches after construction | ||
Appointment appointment = new Appointment("15-08-2024 18:30"); | ||
assertEquals("15-08-2024 18:30", appointment.toString()); | ||
} | ||
|
||
@Test | ||
public void test_appointmentDoesNotMatchDifferentDateTime() { | ||
// Check that two different appointments are not considered equal | ||
Appointment appointment1 = new Appointment("10-01-2024 14:00"); | ||
Appointment appointment2 = new Appointment("10-02-2024 14:00"); | ||
|
||
assertFalse(appointment1.equals(appointment2)); | ||
} | ||
|
||
@Test | ||
public void test_hashCodeConsistency() { | ||
Appointment appointment = new Appointment("01-04-2024 11:30"); | ||
|
||
// Same object should return the same hashCode | ||
assertEquals(appointment.hashCode(), appointment.hashCode()); | ||
} | ||
|
||
@Test | ||
public void test_toStringMethod() { | ||
Appointment appointment = new Appointment("25-12-2024 09:00"); | ||
|
||
String expected = "25-12-2024 09:00"; | ||
assertEquals(expected, appointment.toString()); | ||
} | ||
} |