From 3dccad51ab525c6df9d7e02205c3d5a995df5a95 Mon Sep 17 00:00:00 2001 From: jessica2828 Date: Tue, 29 Oct 2024 17:47:14 +0800 Subject: [PATCH 1/3] Add test: ModuleContainsKeywordsPredicateTest --- .../model/person/ModuleContainsKeywordsPredicateTest.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java 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..645c2521a47 --- /dev/null +++ b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java @@ -0,0 +1,2 @@ +package seedu.address.model.person;public class ModuleContainsKeywordsPredicateTest { +} From 873ecb5b7c5da9aec63f299aa0523f4fcad8e6e6 Mon Sep 17 00:00:00 2001 From: jessica2828 Date: Tue, 29 Oct 2024 17:47:59 +0800 Subject: [PATCH 2/3] Add more FilterCommand related tests --- .../address/logic/commands/FilterCommand.java | 1 + .../logic/commands/FilterCommandTest.java | 29 +++++++- .../seedu/address/model/ModelManagerTest.java | 14 +++- .../ModuleContainsKeywordsPredicateTest.java | 67 ++++++++++++++++++- 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/FilterCommand.java b/src/main/java/seedu/address/logic/commands/FilterCommand.java index ff6a10de046..ffd17267289 100644 --- a/src/main/java/seedu/address/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/address/logic/commands/FilterCommand.java @@ -80,6 +80,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..77ea5141f97 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 execute_zeroKeywords_noPersonFound_courseFilter() { + 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 execute_zeroKeywords_noPersonFound_moduleFilter() { + 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 index 645c2521a47..0b3680ee138 100644 --- a/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/person/ModuleContainsKeywordsPredicateTest.java @@ -1,2 +1,67 @@ -package seedu.address.model.person;public class ModuleContainsKeywordsPredicateTest { +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()); + } } From 614264971f3eff594d0e9d614c2d6872609c40eb Mon Sep 17 00:00:00 2001 From: jessica2828 Date: Thu, 31 Oct 2024 22:08:46 +0800 Subject: [PATCH 3/3] Fix checkstyle issue --- .../java/seedu/address/logic/commands/FilterCommandTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java index 77ea5141f97..c31bee08484 100644 --- a/src/test/java/seedu/address/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FilterCommandTest.java @@ -67,7 +67,7 @@ public void execute_zeroKeywords_noPersonFound() { } @Test - public void execute_zeroKeywords_noPersonFound_courseFilter() { + public void executeNoKeywordsCourseFilter() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); CourseContainsKeywordsPredicate predicate = new CourseContainsKeywordsPredicate(Collections.singletonList(" ")); @@ -78,7 +78,7 @@ public void execute_zeroKeywords_noPersonFound_courseFilter() { } @Test - public void execute_zeroKeywords_noPersonFound_moduleFilter() { + public void executeNoKeywordsModuleFilter() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); ModuleContainsKeywordsPredicate predicate = new ModuleContainsKeywordsPredicate(" ");