Skip to content

Commit

Permalink
Update module filter matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica2828 committed Nov 10, 2024
1 parent 22887bd commit 39b0066
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public ModuleContainsKeywordsPredicate(String keyword) {
this.keyword = keyword;
}

@Override
public boolean test(Person person) {
return person.getModules().stream()
.anyMatch(module -> module.toString().toLowerCase().contains(keyword.toLowerCase()));
}
@Override
public boolean test(Person person) {
String regex = "\\b" + keyword.toLowerCase() + "\\b";
return person.getModules().stream()
.anyMatch(module -> module.toString().toLowerCase().matches(".*" + regex + ".*"));
}

@Override
public boolean equals(Object other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ public void test_moduleContainsKeyword_returnsTrue() {

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
Expand Down

0 comments on commit 39b0066

Please sign in to comment.