Skip to content

Commit

Permalink
Merge pull request #158 from S-Aishvarya/branch-test-listcommands
Browse files Browse the repository at this point in the history
Add test cases for listcommands
  • Loading branch information
jskimdev authored Apr 15, 2024
2 parents ac5acb6 + 34ee9a4 commit 39bf7d1
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Patient> patientList = new ArrayList<>(Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE));
List<Patient> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Patient> patientList = new ArrayList<>(
Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE));
List<Patient> 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<Patient>(model.getFilteredPatientList()));
} catch (CommandException e) {
throw new RuntimeException(e);
}
//assertCommandSuccess(command, model, expectedMessage, expectedModel);
//assertEquals(expectedPatientList, model.getFilteredPatientList());
}
}
Original file line number Diff line number Diff line change
@@ -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<Patient> patientList = new ArrayList<>(
Arrays.asList(GEORGE, CARL, DANIEL, ALICE, FIONA, BENSON, ELLE));
List<Patient> 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<Patient>(model.getFilteredPatientList()));
} catch (CommandException e) {
throw new RuntimeException(e);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 39bf7d1

Please sign in to comment.