aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/latin/DistracterFilterTest.java29
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java39
-rw-r--r--tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java7
3 files changed, 61 insertions, 14 deletions
diff --git a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
index a4dbfaa6b..406e9a9b8 100644
--- a/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
+++ b/tests/src/com/android/inputmethod/latin/DistracterFilterTest.java
@@ -57,11 +57,36 @@ public class DistracterFilterTest extends InputTestsBase {
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
- typedWord = "were";
- // For this test case, we consider "were" is a distracter to "we're".
+ typedWord = "youre";
+ // For this test case, we consider "youre" is a distracter to "you're".
assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+ typedWord = "Banana";
+ // For this test case, we consider "Banana" is a distracter to "banana".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "orange";
+ // For this test case, we consider "orange" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "Orange";
+ // For this test case, we consider "Orange" is a distracter to "orange".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "café";
+ // For this test case, we consider "café" is a distracter to "cafe".
+ assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
+ typedWord = "cafe";
+ // For this test case, we consider "café" is not a distracter to any word in dictionaries.
+ assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
+ EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
+
typedWord = "ill";
// For this test case, we consider "ill" is not a distracter to any word in dictionaries.
assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries(
diff --git a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
index 0528e341e..8f32e5336 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/Ver4DictEncoder.java
@@ -75,33 +75,54 @@ public class Ver4DictEncoder implements DictEncoder {
for (final WordProperty wordProperty : dict) {
// TODO: switch to addMultipleDictionaryEntries when they support shortcuts
if (null == wordProperty.mShortcutTargets || wordProperty.mShortcutTargets.isEmpty()) {
- binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
+ if (!binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
null /* shortcutTarget */, 0 /* shortcutProbability */,
wordProperty.mIsBeginningOfSentence, wordProperty.mIsNotAWord,
- wordProperty.mIsBlacklistEntry, 0 /* timestamp */);
+ wordProperty.mIsBlacklistEntry, 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add unigram entry for " + wordProperty.mWord);
+ }
} else {
for (final WeightedString shortcutTarget : wordProperty.mShortcutTargets) {
- binaryDict.addUnigramEntry(wordProperty.mWord, wordProperty.getProbability(),
+ if (!binaryDict.addUnigramEntry(wordProperty.mWord,
+ wordProperty.getProbability(),
shortcutTarget.mWord, shortcutTarget.getProbability(),
wordProperty.mIsBeginningOfSentence, wordProperty.mIsNotAWord,
- wordProperty.mIsBlacklistEntry, 0 /* timestamp */);
+ wordProperty.mIsBlacklistEntry, 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add unigram entry for " + wordProperty.mWord
+ + ", shortcutTarget: " + shortcutTarget.mWord);
+ return;
+ }
}
}
if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
}
}
for (final WordProperty word0Property : dict) {
if (null == word0Property.mBigrams) continue;
for (final WeightedString word1 : word0Property.mBigrams) {
- binaryDict.addNgramEntry(new PrevWordsInfo(word0Property.mWord), word1.mWord,
- word1.getProbability(), 0 /* timestamp */);
+ final PrevWordsInfo prevWordsInfo = new PrevWordsInfo(word0Property.mWord);
+ if (!binaryDict.addNgramEntry(prevWordsInfo, word1.mWord,
+ word1.getProbability(), 0 /* timestamp */)) {
+ MakedictLog.e("Cannot add n-gram entry for "
+ + prevWordsInfo + " -> " + word1.mWord);
+ return;
+ }
if (binaryDict.needsToRunGC(true /* mindsBlockByGC */)) {
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
}
}
}
- binaryDict.flushWithGC();
+ if (!binaryDict.flushWithGC()) {
+ MakedictLog.e("Cannot flush dict with GC.");
+ return;
+ }
binaryDict.close();
}
diff --git a/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java b/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java
index e0755483c..8b78816ce 100644
--- a/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java
+++ b/tests/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutorTests.java
@@ -30,11 +30,12 @@ import java.util.concurrent.atomic.AtomicInteger;
public class PrioritizedSerialExecutorTests extends AndroidTestCase {
private static final String TAG = PrioritizedSerialExecutorTests.class.getSimpleName();
+ private static final String TEST_EXECUTOR_ID = "test";
private static final int NUM_OF_TASKS = 10;
private static final int DELAY_FOR_WAITING_TASKS_MILLISECONDS = 500;
public void testExecute() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
+ final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor(TEST_EXECUTOR_ID);
final AtomicInteger v = new AtomicInteger(0);
for (int i = 0; i < NUM_OF_TASKS; ++i) {
executor.execute(new Runnable() {
@@ -54,7 +55,7 @@ public class PrioritizedSerialExecutorTests extends AndroidTestCase {
}
public void testExecutePrioritized() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
+ final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor(TEST_EXECUTOR_ID);
final AtomicInteger v = new AtomicInteger(0);
for (int i = 0; i < NUM_OF_TASKS; ++i) {
executor.executePrioritized(new Runnable() {
@@ -74,7 +75,7 @@ public class PrioritizedSerialExecutorTests extends AndroidTestCase {
}
public void testExecuteCombined() {
- final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor();
+ final PrioritizedSerialExecutor executor = new PrioritizedSerialExecutor(TEST_EXECUTOR_ID);
final AtomicInteger v = new AtomicInteger(0);
for (int i = 0; i < NUM_OF_TASKS; ++i) {
executor.execute(new Runnable() {