diff options
author | 2014-02-20 18:36:46 +0900 | |
---|---|---|
committer | 2014-02-20 18:36:46 +0900 | |
commit | 0bc66daae36ef7a1f2db1e2fd5c22abfe1b20163 (patch) | |
tree | 605fd31ea2e040ed6eeadc6c5fb31758b3468034 /tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | |
parent | bb17354041ed4fff635e2f324bd55a3d79a5cfe5 (diff) | |
download | latinime-0bc66daae36ef7a1f2db1e2fd5c22abfe1b20163.tar.gz latinime-0bc66daae36ef7a1f2db1e2fd5c22abfe1b20163.tar.xz latinime-0bc66daae36ef7a1f2db1e2fd5c22abfe1b20163.zip |
Add user history dictionary decaying test.
Bug: 10667710
Change-Id: Ib2be57d8c4cbbb34f64555d84ea6fd571cfdd247
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java')
-rw-r--r-- | tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java index dff5a77d7..449030cec 100644 --- a/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java +++ b/tests/src/com/android/inputmethod/latin/personalization/UserHistoryDictionaryTests.java @@ -20,6 +20,7 @@ import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; +import com.android.inputmethod.latin.BinaryDictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.FileUtils; @@ -44,6 +45,43 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; + private int mCurrentTime = 0; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mCurrentTime = 0; + setCurrentTimeForTestMode(mCurrentTime); + } + + @Override + protected void tearDown() throws Exception { + stopTestModeInNativeCode(); + super.tearDown(); + } + + private void forcePassingShortTime() { + // 4 days. + final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(4); + mCurrentTime += timeToElapse; + setCurrentTimeForTestMode(mCurrentTime); + } + + private void forcePassingLongTime() { + // 60 days. + final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(60); + mCurrentTime += timeToElapse; + setCurrentTimeForTestMode(mCurrentTime); + } + + private static int setCurrentTimeForTestMode(final int currentTime) { + return BinaryDictionary.setCurrentTimeForTest(currentTime); + } + + private static int stopTestModeInNativeCode() { + return BinaryDictionary.setCurrentTimeForTest(-1); + } + /** * Generates a random word. */ @@ -207,4 +245,28 @@ public class UserHistoryDictionaryTests extends AndroidTestCase { FileUtils.deleteRecursively(dictFile); } } + + public void testDecaying() { + final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis()); + final int numberOfWords = 5000; + final Random random = new Random(123456); + clearHistory(dummyLocale); + final List<String> words = generateWords(numberOfWords, random); + final UserHistoryDictionary dict = + PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale); + String prevWord = null; + for (final String word : words) { + dict.addToDictionary(prevWord, word, true, mCurrentTime); + prevWord = word; + assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word)); + } + forcePassingShortTime(); + for (final String word : words) { + assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word)); + } + forcePassingLongTime(); + for (final String word : words) { + assertFalse(dict.isInUnderlyingBinaryDictionaryForTests(word)); + } + } } |