Skip to content

Commit

Permalink
Merge pull request #244 from kwangthiag/sortcmdtest
Browse files Browse the repository at this point in the history
Add Tests for Sort Commands and the Sort function in models
  • Loading branch information
licongshen12 authored Nov 9, 2023
2 parents 391da1b + b82bd52 commit 9a48623
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void sortByName(boolean isAscending) {
* Sorts Patient List by priority in order of {@code isAscending}
* @param isAscending
*/
public void sortByBirthday(boolean isAscending) {
private void sortByBirthday(boolean isAscending) {
if (isAscending) {
internalList.sort(
Comparator.comparing(Person::getBirthdate));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.logic.commands.appointmentcommands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalAppointments.getTypicalAddressBook;

import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;


public class SortCommandTest {
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
@Test
public void execute_sortList_success() {
Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel.sortAppointmentList(true, "time");

assertCommandSuccess(new SortCommand(true, "time"),
model, String.format(SortCommand.MESSAGE_SUCCESS, "ascending", "time"), expectedModel);
}
@Test
public void equals() {
SortCommand sortFirstCommand = new SortCommand(true, "time");
SortCommand sortSecondCommand = new SortCommand(false, "priority");

// same object -> returns true
assertTrue(sortFirstCommand.equals(sortFirstCommand));

// same values -> returns true
SortCommand sortFirstCommandCopy = new SortCommand(true, "time");
assertTrue(sortFirstCommand.equals(sortFirstCommandCopy));

// different types -> returns false
assertFalse(sortFirstCommand.equals(1));

// null -> returns false
assertFalse(sortFirstCommand.equals(null));

// different appointment -> returns false
assertFalse(sortFirstCommand.equals(sortSecondCommand));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package seedu.address.logic.commands.personcommands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;


public class SortPatientCommandTest {
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@Test
public void execute_sortList_success() {
Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
boolean isAscending = false;
expectedModel.sortPatientList(isAscending, "name");

assertCommandSuccess(new SortPatientCommand(isAscending, "name"),
model, String.format(SortPatientCommand.MESSAGE_SUCCESS,
"descending", "name"), expectedModel);
}
@Test
public void equals() {
SortPatientCommand sortPatientFirstCommand = new SortPatientCommand(true, "name");
SortPatientCommand sortPatientSecondCommand = new SortPatientCommand(false, "birthday");

// same object -> returns true
assertTrue(sortPatientFirstCommand.equals(sortPatientFirstCommand));

// same values -> returns true
SortPatientCommand sortPatientFirstCommandCopy = new SortPatientCommand(true, "name");
assertTrue(sortPatientFirstCommand.equals(sortPatientFirstCommandCopy));

// different types -> returns false
assertFalse(sortPatientFirstCommand.equals(1));

// null -> returns false
assertFalse(sortPatientFirstCommand.equals(null));

// different appointment -> returns false
assertFalse(sortPatientFirstCommand.equals(sortPatientSecondCommand));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalAppointments.APPOINTMENT1;
import static seedu.address.testutil.TypicalAppointments.APPOINTMENT2;
import static seedu.address.testutil.TypicalAppointments.APPOINTMENT3;
import static seedu.address.testutil.TypicalAppointments.APPOINTMENT4;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -169,4 +171,61 @@ public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationEx
public void toStringMethod() {
assertEquals(uniqueAppointmentList.asUnmodifiableObservableList().toString(), uniqueAppointmentList.toString());
}

@Test
public void sort_ascendingByTime_success() {
uniqueAppointmentList.add(APPOINTMENT1);
uniqueAppointmentList.add(APPOINTMENT2);
uniqueAppointmentList.add(APPOINTMENT3);
uniqueAppointmentList.add(APPOINTMENT4);
UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList();
expectedUniqueAppointmentList.add(APPOINTMENT3);
expectedUniqueAppointmentList.add(APPOINTMENT4);
expectedUniqueAppointmentList.add(APPOINTMENT2);
expectedUniqueAppointmentList.add(APPOINTMENT1);
uniqueAppointmentList.sort(true, "time");
assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList);
}
@Test
public void sort_descendingByNameWithLowercase_success() {
uniqueAppointmentList.add(APPOINTMENT1);
uniqueAppointmentList.add(APPOINTMENT2);
uniqueAppointmentList.add(APPOINTMENT3);
uniqueAppointmentList.add(APPOINTMENT4);
UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList();
expectedUniqueAppointmentList.add(APPOINTMENT1);
expectedUniqueAppointmentList.add(APPOINTMENT2);
expectedUniqueAppointmentList.add(APPOINTMENT4);
expectedUniqueAppointmentList.add(APPOINTMENT3);
uniqueAppointmentList.sort(false, "time");
assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList);
}
@Test
public void sort_ascendingByPriority_success() {
uniqueAppointmentList.add(APPOINTMENT1);
uniqueAppointmentList.add(APPOINTMENT2);
uniqueAppointmentList.add(APPOINTMENT3);
uniqueAppointmentList.add(APPOINTMENT4);
UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList();
expectedUniqueAppointmentList.add(APPOINTMENT2);
expectedUniqueAppointmentList.add(APPOINTMENT3);
expectedUniqueAppointmentList.add(APPOINTMENT1);
expectedUniqueAppointmentList.add(APPOINTMENT4);
uniqueAppointmentList.sort(true, "priority");
assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList);
}
@Test
public void sort_descendingByBirthday_success() {
uniqueAppointmentList.add(APPOINTMENT1);
uniqueAppointmentList.add(APPOINTMENT2);
uniqueAppointmentList.add(APPOINTMENT3);
uniqueAppointmentList.add(APPOINTMENT4);
UniqueAppointmentList expectedUniqueAppointmentList = new UniqueAppointmentList();
expectedUniqueAppointmentList.add(APPOINTMENT1);
expectedUniqueAppointmentList.add(APPOINTMENT4);
expectedUniqueAppointmentList.add(APPOINTMENT3);
expectedUniqueAppointmentList.add(APPOINTMENT2);
uniqueAppointmentList.sort(false, "priority");
assertEquals(expectedUniqueAppointmentList, uniqueAppointmentList);
}
}
62 changes: 62 additions & 0 deletions src/test/java/seedu/address/model/person/UniquePersonListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FEVER;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;
import static seedu.address.testutil.TypicalPersons.BOB;
import static seedu.address.testutil.TypicalPersons.CARL;
import static seedu.address.testutil.TypicalPersons.DANIEL;
import static seedu.address.testutil.TypicalPersons.LOWERCASE_BENJAMIN;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -172,4 +176,62 @@ public void asUnmodifiableObservableList_modifyList_throwsUnsupportedOperationEx
public void toStringMethod() {
assertEquals(uniquePersonList.asUnmodifiableObservableList().toString(), uniquePersonList.toString());
}

@Test
public void sort_ascendingByName_success() {
uniquePersonList.add(CARL);
uniquePersonList.add(ALICE);
uniquePersonList.add(BOB);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(ALICE);
expectedUniquePersonList.add(BOB);
expectedUniquePersonList.add(CARL);
uniquePersonList.sort(true, "name");
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void sort_descendingByNameWithLowercase_success() {
uniquePersonList.add(CARL);
uniquePersonList.add(ALICE);
uniquePersonList.add(BENSON);
uniquePersonList.add(LOWERCASE_BENJAMIN);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(CARL);
expectedUniquePersonList.add(BENSON);
expectedUniquePersonList.add(LOWERCASE_BENJAMIN);
expectedUniquePersonList.add(ALICE);
uniquePersonList.sort(false, "name");
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void sort_ascendingByBirthday_success() {
uniquePersonList.add(ALICE);
uniquePersonList.add(BENSON);
uniquePersonList.add(CARL);
uniquePersonList.add(DANIEL);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(CARL);
expectedUniquePersonList.add(ALICE);
expectedUniquePersonList.add(BENSON);
expectedUniquePersonList.add(DANIEL);
uniquePersonList.sort(true, "birthday");
assertEquals(expectedUniquePersonList, uniquePersonList);
}

@Test
public void sort_descendingByBirthday_success() {
uniquePersonList.add(ALICE);
uniquePersonList.add(BENSON);
uniquePersonList.add(CARL);
uniquePersonList.add(DANIEL);
UniquePersonList expectedUniquePersonList = new UniquePersonList();
expectedUniquePersonList.add(DANIEL);
expectedUniquePersonList.add(BENSON);
expectedUniquePersonList.add(ALICE);
expectedUniquePersonList.add(CARL);
uniquePersonList.sort(false, "birthday");
assertEquals(expectedUniquePersonList, uniquePersonList);
}
}
6 changes: 6 additions & 0 deletions src/test/java/seedu/address/testutil/TypicalPersons.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class TypicalPersons {
.withEmail("[email protected]").withPhone("98765432")
.withBirthdate("2001/10/20")
.withTags("owesMoney", "friends").build();
public static final Person LOWERCASE_BENJAMIN = new PersonBuilder().withName("benjamin Monk")
.withGender("MALE")
.withAddress("311, Clementi Ave 2, #02-25")
.withEmail("[email protected]").withPhone("98765432")
.withBirthdate("2001/10/16")
.withTags("cancer", "diabetes").build();
public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withGender("MALE")
.withPhone("95352563").withEmail("[email protected]").withBirthdate("1987/01/02")
.withAddress("wall street").withTags("malaria").build();
Expand Down

0 comments on commit 9a48623

Please sign in to comment.