forked from AY2324S2-CS2103T-T08-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix finding profiles by condition, add tests for condition predicate
- Loading branch information
1 parent
b826ac7
commit d2eda09
Showing
4 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
89 changes: 89 additions & 0 deletions
89
src/test/java/seedu/address/model/person/ConditionContainsKeywordsPredicateTest.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,89 @@ | ||
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 java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.testutil.PersonBuilder; | ||
|
||
public class ConditionContainsKeywordsPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
List<String> firstPredicateKeywordList = Collections.singletonList("first"); | ||
List<String> secondPredicateKeywordList = Arrays.asList("first", "second"); | ||
|
||
ConditionContainsKeywordsPredicate firstPredicate = | ||
new ConditionContainsKeywordsPredicate(firstPredicateKeywordList); | ||
ConditionContainsKeywordsPredicate secondPredicate = | ||
new ConditionContainsKeywordsPredicate(secondPredicateKeywordList); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
ConditionContainsKeywordsPredicate firstPredicateCopy = | ||
new ConditionContainsKeywordsPredicate(firstPredicateKeywordList); | ||
assertTrue(firstPredicate.equals(firstPredicateCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(firstPredicate.equals(secondPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_nameContainsKeywords_returnsTrue() { | ||
// One keyword | ||
ConditionContainsKeywordsPredicate predicate = | ||
new ConditionContainsKeywordsPredicate(Collections.singletonList("runny nose")); | ||
assertTrue(predicate.test(new PersonBuilder().withCondition("very runny nose").build())); | ||
|
||
// Multiple keywords | ||
predicate = new ConditionContainsKeywordsPredicate(Arrays.asList("myopia", "diabetes")); | ||
assertTrue(predicate.test(new PersonBuilder().withCondition("myopia, diabetes").build())); | ||
|
||
// Only one matching keyword | ||
predicate = new ConditionContainsKeywordsPredicate(Arrays.asList("myopia", "diabetes")); | ||
assertTrue(predicate.test(new PersonBuilder().withCondition("severe myopia").build())); | ||
|
||
// Mixed-case keywords | ||
predicate = new ConditionContainsKeywordsPredicate(Arrays.asList("mYoPiA", "dIaBeTeS")); | ||
assertTrue(predicate.test(new PersonBuilder().withCondition("myopia, diabetes").build())); | ||
} | ||
|
||
@Test | ||
public void test_nameDoesNotContainKeywords_returnsFalse() { | ||
// Zero keywords | ||
ConditionContainsKeywordsPredicate predicate = new ConditionContainsKeywordsPredicate(Collections.emptyList()); | ||
assertFalse(predicate.test(new PersonBuilder().withCondition("myopia").build())); | ||
|
||
// Non-matching keyword | ||
predicate = new ConditionContainsKeywordsPredicate(Arrays.asList("high blood pressure")); | ||
assertFalse(predicate.test(new PersonBuilder().withCondition("myopia, diabetes").build())); | ||
|
||
// Keywords match phone and address, but does not match condition | ||
predicate = new ConditionContainsKeywordsPredicate(Arrays.asList("91234567", "alice@email.com", "myopia")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("91234567") | ||
.withAddress("Main Street").withCondition("diabetes").build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
List<String> keywords = List.of("keyword1", "keyword2"); | ||
ConditionContainsKeywordsPredicate predicate = new ConditionContainsKeywordsPredicate(keywords); | ||
|
||
String expected = ConditionContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}"; | ||
assertEquals(expected, predicate.toString()); | ||
} | ||
} |