diff --git a/src/test/java/seedu/address/logic/commands/ListAlphabeticalCommandTest.java b/src/test/java/seedu/address/logic/commands/ListAlphabeticalCommandTest.java new file mode 100755 index 00000000000..d8bd33ef6cc --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ListAlphabeticalCommandTest.java @@ -0,0 +1,55 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.CommandTestUtil.showPatientAtIndex; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PATIENT; +import static seedu.address.testutil.TypicalPatients.ALICE; +import static seedu.address.testutil.TypicalPatients.BENSON; +import static seedu.address.testutil.TypicalPatients.CARL; +import static seedu.address.testutil.TypicalPatients.DANIEL; +import static seedu.address.testutil.TypicalPatients.ELLE; +import static seedu.address.testutil.TypicalPatients.FIONA; +import static seedu.address.testutil.TypicalPatients.GEORGE; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.PatientList; +import seedu.address.model.UserPrefs; +import seedu.address.model.patient.Patient; + + + +/** + * Contains integration tests (interaction with the Model) and unit tests for ListAlphabeticalCommand. + */ +public class ListAlphabeticalCommandTest { + private Model model; + private Model expectedModel; + + @BeforeEach + public void setUp() { + List patientList = new ArrayList<>(Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE)); + List expectedPatientList = + new ArrayList<>(Arrays.asList(ALICE, BENSON, CARL, DANIEL, ELLE, FIONA, GEORGE)); + PatientList patients = new PatientList(); + patients.setPatients(patientList); + model = new ModelManager(patients, new UserPrefs()); + PatientList expectedPatients = new PatientList(); + expectedPatients.setPatients(expectedPatientList); + expectedModel = new ModelManager(expectedPatients, new UserPrefs()); + } + + @Test + void testExecute() { + showPatientAtIndex(model, INDEX_FIRST_PATIENT); + assertCommandSuccess(new ListAlphabeticalCommand(), model, + ListAlphabeticalCommand.MESSAGE_SUCCESS, expectedModel); + } +} diff --git a/src/test/java/seedu/address/logic/commands/ListByApptDateCommandTest.java b/src/test/java/seedu/address/logic/commands/ListByApptDateCommandTest.java new file mode 100755 index 00000000000..3a37513101e --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ListByApptDateCommandTest.java @@ -0,0 +1,61 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.TypicalPatients.ALICE; +import static seedu.address.testutil.TypicalPatients.BENSON; +import static seedu.address.testutil.TypicalPatients.CARL; +import static seedu.address.testutil.TypicalPatients.DANIEL; +import static seedu.address.testutil.TypicalPatients.ELLE; +import static seedu.address.testutil.TypicalPatients.FIONA; +import static seedu.address.testutil.TypicalPatients.GEORGE; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.PatientList; +import seedu.address.model.UserPrefs; +import seedu.address.model.patient.Patient; + + +/** + * Contains integration tests (interaction with the Model) and unit tests for ListCommand. + */ +public class ListByApptDateCommandTest { + + private Model model; + private Model expectedModel; + + + @Test + void testExecute() { + List patientList = new ArrayList<>( + Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE)); + List expectedPatientList = new ArrayList<>( + Arrays.asList(BENSON, DANIEL, ELLE, GEORGE, ALICE, CARL, FIONA)); + PatientList patients = new PatientList(); + patients.setPatients(patientList); + model = new ModelManager(patients, new UserPrefs()); + PatientList expectedPatients = new PatientList(); + expectedPatients.setPatients(expectedPatientList); + expectedModel = new ModelManager(expectedPatients, new UserPrefs()); + + //String expectedMessage = String.format(ListByApptDateCommand.MESSAGE_SUCCESS, 0); + ListByApptDateCommand command = new ListByApptDateCommand(); + //model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS); + try { + CommandResult commandResult = command.execute(model); + assertEquals(commandResult, new CommandResult(ListByApptDateCommand.MESSAGE_SUCCESS)); + //assertEquals(expectedPatientList, new ArrayList(model.getFilteredPatientList())); + } catch (CommandException e) { + throw new RuntimeException(e); + } + //assertCommandSuccess(command, model, expectedMessage, expectedModel); + //assertEquals(expectedPatientList, model.getFilteredPatientList()); + } +} diff --git a/src/test/java/seedu/address/logic/commands/ListByDateCriteriaCommandTest.java b/src/test/java/seedu/address/logic/commands/ListByDateCriteriaCommandTest.java new file mode 100755 index 00000000000..bd5458ff59f --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ListByDateCriteriaCommandTest.java @@ -0,0 +1,65 @@ +package seedu.address.logic.commands; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.TypicalPatients.ALICE; +import static seedu.address.testutil.TypicalPatients.BENSON; +import static seedu.address.testutil.TypicalPatients.CARL; +import static seedu.address.testutil.TypicalPatients.DANIEL; +import static seedu.address.testutil.TypicalPatients.ELLE; +import static seedu.address.testutil.TypicalPatients.FIONA; +import static seedu.address.testutil.TypicalPatients.GEORGE; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.PatientList; +import seedu.address.model.UserPrefs; +import seedu.address.model.patient.ApptDateMatchesPredicate; +import seedu.address.model.patient.Patient; + + +/** + * Contains integration tests (interaction with the Model) and unit tests for ListCommand. + */ +public class ListByDateCriteriaCommandTest { + private Model model; + private Model expectedModel; + + @Test + void testExecute() { + List patientList = new ArrayList<>( + Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE)); + List expectedPatientList = new ArrayList<>( + Arrays.asList(BENSON, DANIEL, ELLE, GEORGE, ALICE, CARL, FIONA)); + PatientList patients = new PatientList(); + patients.setPatients(patientList); + model = new ModelManager(patients, new UserPrefs()); + PatientList expectedPatients = new PatientList(); + expectedPatients.setPatients(expectedPatientList); + expectedModel = new ModelManager(expectedPatients, new UserPrefs()); + + try { + LocalDate apptDate = ParserUtil.parseAppointment("27/2/2025").appointment; + ApptDateMatchesPredicate predicate = new ApptDateMatchesPredicate(apptDate); + ListByDateCriteriaCommand command = new ListByDateCriteriaCommand(predicate); + CommandResult commandResult = null; + commandResult = command.execute(model); + assertEquals(commandResult, new CommandResult(ListByDateCriteriaCommand.MESSAGE_SUCCESS)); + //assertEquals(expectedPatientList, new ArrayList(model.getFilteredPatientList())); + } catch (CommandException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/test/java/seedu/address/model/patient/ApptDateMatchesPredicateTest.java b/src/test/java/seedu/address/model/patient/ApptDateMatchesPredicateTest.java new file mode 100755 index 00000000000..97841612276 --- /dev/null +++ b/src/test/java/seedu/address/model/patient/ApptDateMatchesPredicateTest.java @@ -0,0 +1,60 @@ +package seedu.address.model.patient; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.LocalDate; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; + + +class ApptDateMatchesPredicateTest { + + + @Test + void testEquals() { + String firstApptDate = "01/02/2024"; + LocalDate firstAppt = null; + String firstApptDate2 = "01/02/2024"; + LocalDate firstAppt2 = null; + + String secondApptDate = "2024-2-1"; + LocalDate secondAppt = null; + try { + firstAppt = ParserUtil.parseAppointment(firstApptDate).appointment; + firstAppt2 = ParserUtil.parseAppointment(firstApptDate2).appointment; + secondAppt = ParserUtil.parseAppointment(secondApptDate).appointment; + } catch (ParseException e) { + throw new RuntimeException(e); + } + + ApptDateMatchesPredicate firstPredicate = new ApptDateMatchesPredicate(firstAppt); + ApptDateMatchesPredicate firstPredicate2 = new ApptDateMatchesPredicate(firstAppt2); + ApptDateMatchesPredicate secondPredicate = new ApptDateMatchesPredicate(secondAppt); + assertTrue(firstPredicate.equals(firstPredicate2)); + assertTrue(firstPredicate.equals(secondPredicate)); + assertTrue(firstPredicate2.equals(secondPredicate)); + } + + @Test + void testNotEquals() { + String firstApptDate = "01/02/2024"; + LocalDate firstAppt = null; + + String secondApptDate = "01/01/2024"; + LocalDate secondAppt = null; + try { + firstAppt = ParserUtil.parseAppointment(firstApptDate).appointment; + secondAppt = ParserUtil.parseAppointment(secondApptDate).appointment; + } catch (ParseException e) { + throw new RuntimeException(e); + } + + ApptDateMatchesPredicate firstPredicate = new ApptDateMatchesPredicate(firstAppt); + ApptDateMatchesPredicate secondPredicate = new ApptDateMatchesPredicate(secondAppt); + assertFalse(firstPredicate.equals(secondPredicate)); + } +}