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.
Add tests for address predicate and nric predicate
- Loading branch information
1 parent
a48222e
commit e9323ab
Showing
3 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
src/test/java/seedu/address/model/person/AddressContainsKeywordsPredicateTest.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,90 @@ | ||
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 AddressContainsKeywordsPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
List<String> firstPredicateKeywordList = Collections.singletonList("first"); | ||
List<String> secondPredicateKeywordList = Arrays.asList("first", "second"); | ||
|
||
AddressContainsKeywordsPredicate firstPredicate = | ||
new AddressContainsKeywordsPredicate(firstPredicateKeywordList); | ||
AddressContainsKeywordsPredicate secondPredicate = | ||
new AddressContainsKeywordsPredicate(secondPredicateKeywordList); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
AddressContainsKeywordsPredicate firstPredicateCopy = | ||
new AddressContainsKeywordsPredicate(firstPredicateKeywordList); | ||
assertTrue(firstPredicate.equals(firstPredicateCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// different address -> returns false | ||
assertFalse(firstPredicate.equals(secondPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_addressContainsKeywords_returnsTrue() { | ||
// One keyword | ||
AddressContainsKeywordsPredicate predicate = | ||
new AddressContainsKeywordsPredicate(Collections.singletonList("jurong")); | ||
assertTrue(predicate.test(new PersonBuilder().withAddress("blk 12, jurong east street 14").build())); | ||
|
||
// Multiple keywords | ||
predicate = new AddressContainsKeywordsPredicate(Arrays.asList("sky habitat", "bishan")); | ||
assertTrue(predicate.test(new PersonBuilder().withAddress("2 Bishan Street 14, Sky Habitat").build())); | ||
|
||
// Only one matching keyword | ||
predicate = new AddressContainsKeywordsPredicate(Arrays.asList("sky habitat", "pasir ris")); | ||
assertTrue(predicate.test(new PersonBuilder().withAddress("Watercolours, 28 Pasir Ris Link").build())); | ||
|
||
// Mixed-case keywords | ||
predicate = new AddressContainsKeywordsPredicate(Arrays.asList("wAteRcOlOuRs", "pASiR rIs")); | ||
assertTrue(predicate.test(new PersonBuilder().withAddress("Watercolours, 28 Pasir Ris Link").build())); | ||
} | ||
|
||
@Test | ||
public void test_addressDoesNotContainKeywords_returnsFalse() { | ||
// Zero keywords | ||
AddressContainsKeywordsPredicate predicate = new AddressContainsKeywordsPredicate(Collections.emptyList()); | ||
assertFalse(predicate.test(new PersonBuilder().withAddress("Watercolours, 28 Pasir Ris Link").build())); | ||
|
||
// Non-matching keyword | ||
predicate = new AddressContainsKeywordsPredicate(Arrays.asList("pasir ris", "orchard")); | ||
assertFalse(predicate.test(new PersonBuilder().withAddress("Blk 24, Woodlands Ring Road").build())); | ||
|
||
// Keywords match name, phone and email, but does not match address | ||
predicate = new AddressContainsKeywordsPredicate( | ||
Arrays.asList("Alice Tan", "91234567", "jurong", "alice@email.com")); | ||
assertFalse(predicate.test(new PersonBuilder().withName("Alice Tan").withPhone("91234567") | ||
.withAddress("Watercolours, 28 Pasir Ris Link").withEmail("alice@email.com").build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
List<String> keywords = List.of("keyword1", "keyword2"); | ||
AddressContainsKeywordsPredicate predicate = new AddressContainsKeywordsPredicate(keywords); | ||
|
||
String expected = AddressContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}"; | ||
assertEquals(expected, predicate.toString()); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
src/test/java/seedu/address/model/person/NricContainsKeywordsPredicateTest.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,72 @@ | ||
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 NricContainsKeywordsPredicateTest { | ||
|
||
@Test | ||
public void equals() { | ||
String firstPredicateKeyword = "first"; | ||
String secondPredicateKeyword = "second"; | ||
|
||
NricContainsKeywordsPredicate firstPredicate = | ||
new NricContainsKeywordsPredicate(firstPredicateKeyword); | ||
NricContainsKeywordsPredicate secondPredicate = | ||
new NricContainsKeywordsPredicate(secondPredicateKeyword); | ||
|
||
// same object -> returns true | ||
assertTrue(firstPredicate.equals(firstPredicate)); | ||
|
||
// same values -> returns true | ||
NricContainsKeywordsPredicate firstPredicateCopy = | ||
new NricContainsKeywordsPredicate(firstPredicateKeyword); | ||
assertTrue(firstPredicate.equals(firstPredicateCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(firstPredicate.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(firstPredicate.equals(null)); | ||
|
||
// different NRIC -> returns false | ||
assertFalse(firstPredicate.equals(secondPredicate)); | ||
} | ||
|
||
@Test | ||
public void test_nricContainsKeywords_returnsTrue() { | ||
// One keyword | ||
NricContainsKeywordsPredicate predicate = | ||
new NricContainsKeywordsPredicate("T1234567A"); | ||
assertTrue(predicate.test(new PersonBuilder().withNric("T1234567A").build())); | ||
|
||
// small last letter | ||
predicate = new NricContainsKeywordsPredicate("T1234567a"); | ||
assertTrue(predicate.test(new PersonBuilder().withNric("T1234567A").build())); | ||
|
||
// small first letter | ||
predicate = new NricContainsKeywordsPredicate("t1234567A"); | ||
assertTrue(predicate.test(new PersonBuilder().withNric("T1234567A").build())); | ||
} | ||
|
||
@Test | ||
public void test_nricDoesNotContainKeywords_returnsFalse() { | ||
// Non-matching keyword | ||
NricContainsKeywordsPredicate predicate = new NricContainsKeywordsPredicate("S7654321A"); | ||
assertFalse(predicate.test(new PersonBuilder().withNric("T1234567A").build())); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
String keyword = "keyword"; | ||
NricContainsKeywordsPredicate predicate = new NricContainsKeywordsPredicate(keyword); | ||
|
||
String expected = NricContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keyword + "}"; | ||
assertEquals(expected, predicate.toString()); | ||
} | ||
} |