diff --git a/src/main/java/seedu/address/logic/commands/FilterCommand.java b/src/main/java/seedu/address/logic/commands/FilterCommand.java index d5c5a49d3b1..0e5261f098a 100644 --- a/src/main/java/seedu/address/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/address/logic/commands/FilterCommand.java @@ -81,6 +81,7 @@ public CommandResult execute(Model model) { return new CommandResult( String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java index c65698c06c0..c31bee08484 100644 --- a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java @@ -66,6 +66,29 @@ public void execute_zeroKeywords_noPersonFound() { assertEquals(Collections.emptyList(), model.getFilteredPersonList()); } + @Test + public void executeNoKeywordsCourseFilter() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + CourseContainsKeywordsPredicate predicate = + new CourseContainsKeywordsPredicate(Collections.singletonList(" ")); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test + public void executeNoKeywordsModuleFilter() { + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); + ModuleContainsKeywordsPredicate predicate = + new ModuleContainsKeywordsPredicate(" "); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredPersonList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + } + + @Test public void execute_multipleKeywords_multiplePersonsFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); @@ -78,7 +101,8 @@ public void execute_multipleKeywords_multiplePersonsFound() { @Test public void toStringMethod_namePredicate() { - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); + NameContainsKeywordsPredicate predicate = + new NameContainsKeywordsPredicate(Arrays.asList("keyword")); FilterCommand filterCommand = new FilterCommand(predicate); String expected = FilterCommand.class.getCanonicalName() + "{namePredicate=" @@ -90,7 +114,8 @@ public void toStringMethod_namePredicate() { @Test public void toStringMethod_modulePredicate() { - ModuleContainsKeywordsPredicate modulePredicate = new ModuleContainsKeywordsPredicate("CS2103T"); + ModuleContainsKeywordsPredicate modulePredicate = + new ModuleContainsKeywordsPredicate("CS2103T"); FilterCommand filterCommand = new FilterCommand(modulePredicate); String expected = FilterCommand.class.getCanonicalName() + "{namePredicate=null, modulePredicate=" diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 4132a925e9e..1cb573fdb4a 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -15,7 +15,9 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.GuiSettings; +import seedu.address.model.person.CourseContainsKeywordsPredicate; import seedu.address.model.person.Module; +import seedu.address.model.person.ModuleContainsKeywordsPredicate; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.testutil.EduContactsBuilder; @@ -167,11 +169,21 @@ public void equals() { // different eduContacts -> returns false assertFalse(modelManager.equals(new ModelManager(differentEduContacts, userPrefs))); - // different filteredList -> returns false + // different filteredList (NameContainsKeywordsPredicate) -> returns false String[] keywords = ALICE.getName().fullName.split("\\s+"); modelManager.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); assertFalse(modelManager.equals(new ModelManager(eduContacts, userPrefs))); + // different filteredList (ModuleContainsKeywordsPredicate) -> returns false + String moduleKeyword = "CS1010"; + modelManager.updateFilteredPersonList(new ModuleContainsKeywordsPredicate(moduleKeyword)); + assertFalse(modelManager.equals(new ModelManager(eduContacts, userPrefs))); + + // different filteredList (CourseContainsKeywordsPredicate) -> return false + String courseKeyword = "Computer Science"; + modelManager.updateFilteredPersonList(new CourseContainsKeywordsPredicate(Arrays.asList(courseKeyword))); + assertFalse(modelManager.equals(new ModelManager(eduContacts, userPrefs))); + // different personToDisplay -> returns false assertFalse(modelManager.equals(new ModelManager(eduContacts, userPrefs))); diff --git a/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java new file mode 100644 index 00000000000..0b3680ee138 --- /dev/null +++ b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java @@ -0,0 +1,67 @@ +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; + +import seedu.address.testutil.PersonBuilder; + +public class ModuleContainsKeywordsPredicateTest { + + @Test + public void equals() { + String firstPredicateKeyword = "CS1010"; + String secondPredicateKeyword = "CS2030"; + + ModuleContainsKeywordsPredicate firstPredicate = + new ModuleContainsKeywordsPredicate(firstPredicateKeyword); + ModuleContainsKeywordsPredicate secondPredicate = + new ModuleContainsKeywordsPredicate(secondPredicateKeyword); + + // same object -> returns true + assertTrue(firstPredicate.equals(firstPredicate)); + + // same values -> returns true + ModuleContainsKeywordsPredicate firstPredicateCopy = + new ModuleContainsKeywordsPredicate(firstPredicateKeyword); + assertTrue(firstPredicate.equals(firstPredicateCopy)); + + // different types -> returns false + assertFalse(firstPredicate.equals(1)); + + // null -> returns false + assertFalse(firstPredicate.equals(null)); + + // different predicate -> returns false + assertFalse(firstPredicate.equals(secondPredicate)); + } + + @Test + public void test_moduleContainsKeyword_returnsTrue() { + ModuleContainsKeywordsPredicate predicate = new ModuleContainsKeywordsPredicate("CS1010"); + assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build())); + + predicate = new ModuleContainsKeywordsPredicate("cs1010"); + assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build())); + + predicate = new ModuleContainsKeywordsPredicate("1010"); + assertTrue(predicate.test(new PersonBuilder().addUngradedModule("CS1010").build())); + } + + @Test + public void test_moduleDoesNotContainKeyword_returnsFalse() { + ModuleContainsKeywordsPredicate predicate = new ModuleContainsKeywordsPredicate("CS9999"); + assertFalse(predicate.test(new PersonBuilder().addUngradedModule("CS2030").build())); + } + + @Test + public void toStringMethod() { + String keyword = "CS1010"; + ModuleContainsKeywordsPredicate predicate = new ModuleContainsKeywordsPredicate(keyword); + + String expected = ModuleContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keyword + "}"; + assertEquals(expected, predicate.toString()); + } +}