Skip to content

Commit

Permalink
Add tests for address predicate and nric predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-setyawan committed Apr 12, 2024
1 parent a48222e commit e9323ab
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 3 deletions.
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public void equals() {
// null -> returns false
assertFalse(firstPredicate.equals(null));

// different person -> returns false
// different condition -> returns false
assertFalse(firstPredicate.equals(secondPredicate));
}

@Test
public void test_nameContainsKeywords_returnsTrue() {
public void test_conditionContainsKeywords_returnsTrue() {
// One keyword
ConditionContainsKeywordsPredicate predicate =
new ConditionContainsKeywordsPredicate(Collections.singletonList("runny nose"));
Expand All @@ -63,7 +63,7 @@ public void test_nameContainsKeywords_returnsTrue() {
}

@Test
public void test_nameDoesNotContainKeywords_returnsFalse() {
public void test_conditionDoesNotContainKeywords_returnsFalse() {
// Zero keywords
ConditionContainsKeywordsPredicate predicate = new ConditionContainsKeywordsPredicate(Collections.emptyList());
assertFalse(predicate.test(new PersonBuilder().withCondition("myopia").build()));
Expand Down
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());
}
}

0 comments on commit e9323ab

Please sign in to comment.