diff options
author | Yorke Lee <yorkelee@google.com> | 2013-04-18 16:12:34 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2013-04-19 10:51:02 -0700 |
commit | a539c86d015c3eb9819cf38d1ccb04edb1461fe2 (patch) | |
tree | 7ad62cf915136b70ab0872b293b0ff33eef81448 /tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java | |
parent | afd650b7f81f363a4bb554ff7199338aee1a49c2 (diff) |
Allow name matching for contacts with numbers in their name
For SmartDialTrie, also include numbers as valid characters when
calculating indexes when generating the byte array.
For SmartDialNameMatcher, include '0'-'9' as valid latin characters,
and handle them appropriately after remapping accented characters.
Also fixed a subtle matching bug that would manifest itself when
matching against multiple tokens with similar initials - E.g.
"Dr.Dredd"
Bug 8659001
Change-Id: If461d2760a723ef7fd03dda0c1a1515cd7b44cf6
Diffstat (limited to 'tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java')
-rw-r--r-- | tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java index 7f55263e1..cd87b6613 100644 --- a/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java +++ b/tests/src/com/android/dialer/dialpad/SmartDialTrieTest.java @@ -106,6 +106,14 @@ public class SmartDialTrieTest extends TestCase{ assertTrue(checkContains(trie, martinjuniorharry, "6542")); // 542 corresponds to jha = "Martin (J)r (Ha)rry" assertTrue(checkContains(trie, martinjuniorharry, "542")); + // 642 corresponds to mha = "(M)artin Jr (Ha)rry" + assertTrue(checkContains(trie, martinjuniorharry, "642")); + // 6542779 (M)artin (J)r (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "6542779")); + // 65742779 (M)artin (Jr) (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "65742779")); + // 542779 Martin (J)r (Harry) + assertTrue(checkContains(trie, martinjuniorharry, "542779")); // 547 doesn't match assertFalse(checkContains(trie, martinjuniorharry, "547")); // 655 doesn't match @@ -114,6 +122,39 @@ public class SmartDialTrieTest extends TestCase{ assertFalse(checkContains(trie, martinjuniorharry, "653")); // 6543 doesn't match assertFalse(checkContains(trie, martinjuniorharry, "6543")); + // 7(2^3 -1) entries for the name, and 1 for the number + assertEquals(8, trie.numEntries()); + } + + public void testPutForInitialMatchesCombinations() { + final SmartDialTrie trie = new SmartDialTrie(); + final ContactNumber alphabet = new ContactNumber(0, "abc def ghi jkl mno pqrs tuv wxyz", + "1", "1", 2); + trie.put(alphabet); + // 255 (2^8 - 1) combinations for the name, and 1 for the number + assertEquals(256, trie.numEntries()); + + // Test every single combination of the leading initials of each name token by generating + // strings consisting of all combinations of the digits 2-9. + final StringBuilder sb = new StringBuilder(); + + // Create an array of bit positions 0b10000000, 0b01000000, 0b00100000, ... + final int[] pos = new int[8]; + for (int i = 2; i <= 9; i++) { + pos[i - 2] = 1 << (9 - i); + } + for (int i = 1; i < 256; i++) { + sb.setLength(0); + // If the bit at nth position is set to true, then add the nth initial to the target + // string + for (int j = 2; j <= 9; j++) { + if ((i & pos[j - 2]) > 0) { + sb.append(j); + } + } + assertTrue(checkContains(trie, alphabet, sb.toString())); + } + } public void testSeparators() { @@ -141,6 +182,19 @@ public class SmartDialTrieTest extends TestCase{ assertTrue(checkContains(trie, bronte, "276683")); } + public void testNumbersInName() { + final SmartDialTrie trie = new SmartDialTrie(); + final ContactNumber contact = new ContactNumber(0, "12345678", "0", "0", 1); + final ContactNumber teacher = new ContactNumber(1, "1st Grade Teacher", "0", "1", 2); + trie.put(contact); + trie.put(teacher); + assertTrue(checkContains(trie, contact, "12345678")); + // (1st Grade) Teacher + assertTrue(checkContains(trie, teacher, "17847233")); + // (1)st (G)rade (Tea)cher + assertTrue(checkContains(trie, teacher, "14832")); + } + public void testPutForNumbers() { final SmartDialTrie trie = new SmartDialTrie(); final ContactNumber contactno1 = new ContactNumber(0, "James", "510-527-2357", "0", 1); |