forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from S-Aishvarya/branch-test-listcommands
Add test cases for listcommands
- Loading branch information
Showing
4 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/test/java/seedu/address/logic/commands/ListAlphabeticalCommandTest.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,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); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/java/seedu/address/logic/commands/ListByApptDateCommandTest.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,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()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/seedu/address/logic/commands/ListByDateCriteriaCommandTest.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,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); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/seedu/address/model/patient/ApptDateMatchesPredicateTest.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,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)); | ||
} | ||
} |