Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[T4A7][W11-B2] Zhi Jiang #1673

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Name {

public static final String EXAMPLE = "John Doe";
public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphabetic characters";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alpha} ]+";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alpha}\\, ]+";

public final String fullName;

Expand Down Expand Up @@ -60,5 +60,28 @@ public boolean equals(Object other) {
public int hashCode() {
return fullName.hashCode();
}

public boolean isSimilar(Name other) {
if (other == null) {
return false;
}
String n1 = this.toString().toLowerCase();
String n2 = other.toString().toLowerCase();

String[] arr1 = n1.split("[,\\s+]+");
String[] arr2 = n2.split("[,\\s+]+");

for (String s1:arr1) {
for (String s2:arr2) {
if (s1.equals(s2)) {
return true;
}
}
}



return false;
}

}
45 changes: 45 additions & 0 deletions src/seedu/addressbook/data/person/NameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.addressbook.data.person;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import seedu.addressbook.data.exception.IllegalValueException;

public class NameTest {

private Name n1;

@Before
public void setup() throws IllegalValueException {
n1 = new Name("John K Smith");
}

@Test
public void similarInput_returnsTrue() throws IllegalValueException {
final Name n2 = new Name("John");
assertTrue(n1.isSimilar(n2));
}

@Test
public void nullInput_returnsFalse() {
final Name n2 = null;
assertFalse(n1.isSimilar(n2));
}

@Test
public void caseInsensitiveInput_returnsTrue() throws IllegalValueException {
final Name n2 = new Name("john");
assertTrue(n1.isSimilar(n2));

}

@Test
public void nameWithCommaInput_returnsTrue() throws IllegalValueException {
final Name n2 = new Name("Smith, John K");
assertTrue(n1.isSimilar(n2));

}

}