diff options
author | 2014-02-20 04:36:23 -0800 | |
---|---|---|
committer | 2014-02-20 04:36:23 -0800 | |
commit | 4ebf5619328bfd9ca11d0624f9d4f1d7d5a1e7ff (patch) | |
tree | 6e3bc42ce9f96d97e842708e7d0aedcea517ab83 | |
parent | 0917b6fd8f07bd3f1f35a55ec9e045f09cb98a82 (diff) | |
parent | 21f94829994d5a5c2773605fec6b7eeef920c646 (diff) | |
download | latinime-4ebf5619328bfd9ca11d0624f9d4f1d7d5a1e7ff.tar.gz latinime-4ebf5619328bfd9ca11d0624f9d4f1d7d5a1e7ff.tar.xz latinime-4ebf5619328bfd9ca11d0624f9d4f1d7d5a1e7ff.zip |
am 21f94829: Fix: UserHistoryDictionaryTests.testDecaying().
* commit '21f94829994d5a5c2773605fec6b7eeef920c646':
Fix: UserHistoryDictionaryTests.testDecaying().
-rw-r--r-- | tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index 449030cec..b1239f0af 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -50,8 +50,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { @Override protected void setUp() throws Exception { super.setUp(); - mCurrentTime = 0; - setCurrentTimeForTestMode(mCurrentTime); + resetCurrentTimeForTestMode(); } @Override @@ -60,9 +59,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { super.tearDown(); } + private void resetCurrentTimeForTestMode() { + mCurrentTime = 0; + setCurrentTimeForTestMode(mCurrentTime); + } + private void forcePassingShortTime() { - // 4 days. - final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(4); + // 3 days. + final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(3); mCurrentTime += timeToElapse; setCurrentTimeForTestMode(mCurrentTime); } @@ -250,10 +254,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis()); final int numberOfWords = 5000; final Random random = new Random(123456); + resetCurrentTimeForTestMode(); clearHistory(dummyLocale); final List<String> words = generateWords(numberOfWords, random); final UserHistoryDictionary dict = PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale); + dict.waitAllTasksForTests(); String prevWord = null; for (final String word : words) { dict.addToDictionary(prevWord, word, true, mCurrentTime); @@ -261,10 +267,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word)); } forcePassingShortTime(); + dict.decayIfNeeded(); + dict.waitAllTasksForTests(); for (final String word : words) { assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word)); } forcePassingLongTime(); + dict.decayIfNeeded(); + dict.waitAllTasksForTests(); for (final String word : words) { assertFalse(dict.isInUnderlyingBinaryDictionaryForTests(word)); } |