Fix: UserHistoryDictionaryTests.testDecaying().
Bug: 13106697 Change-Id: If81f77c3cefdefae94cb9145aa9f700494f8237amain
parent
a7ee108fc5
commit
21f9482999
|
@ -50,8 +50,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mCurrentTime = 0;
|
resetCurrentTimeForTestMode();
|
||||||
setCurrentTimeForTestMode(mCurrentTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,9 +59,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resetCurrentTimeForTestMode() {
|
||||||
|
mCurrentTime = 0;
|
||||||
|
setCurrentTimeForTestMode(mCurrentTime);
|
||||||
|
}
|
||||||
|
|
||||||
private void forcePassingShortTime() {
|
private void forcePassingShortTime() {
|
||||||
// 4 days.
|
// 3 days.
|
||||||
final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(4);
|
final int timeToElapse = (int)TimeUnit.DAYS.toSeconds(3);
|
||||||
mCurrentTime += timeToElapse;
|
mCurrentTime += timeToElapse;
|
||||||
setCurrentTimeForTestMode(mCurrentTime);
|
setCurrentTimeForTestMode(mCurrentTime);
|
||||||
}
|
}
|
||||||
|
@ -250,10 +254,12 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis());
|
final Locale dummyLocale = new Locale("test_decaying" + System.currentTimeMillis());
|
||||||
final int numberOfWords = 5000;
|
final int numberOfWords = 5000;
|
||||||
final Random random = new Random(123456);
|
final Random random = new Random(123456);
|
||||||
|
resetCurrentTimeForTestMode();
|
||||||
clearHistory(dummyLocale);
|
clearHistory(dummyLocale);
|
||||||
final List<String> words = generateWords(numberOfWords, random);
|
final List<String> words = generateWords(numberOfWords, random);
|
||||||
final UserHistoryDictionary dict =
|
final UserHistoryDictionary dict =
|
||||||
PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale);
|
PersonalizationHelper.getUserHistoryDictionary(getContext(), dummyLocale);
|
||||||
|
dict.waitAllTasksForTests();
|
||||||
String prevWord = null;
|
String prevWord = null;
|
||||||
for (final String word : words) {
|
for (final String word : words) {
|
||||||
dict.addToDictionary(prevWord, word, true, mCurrentTime);
|
dict.addToDictionary(prevWord, word, true, mCurrentTime);
|
||||||
|
@ -261,10 +267,14 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
|
||||||
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
||||||
}
|
}
|
||||||
forcePassingShortTime();
|
forcePassingShortTime();
|
||||||
|
dict.decayIfNeeded();
|
||||||
|
dict.waitAllTasksForTests();
|
||||||
for (final String word : words) {
|
for (final String word : words) {
|
||||||
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertTrue(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
||||||
}
|
}
|
||||||
forcePassingLongTime();
|
forcePassingLongTime();
|
||||||
|
dict.decayIfNeeded();
|
||||||
|
dict.waitAllTasksForTests();
|
||||||
for (final String word : words) {
|
for (final String word : words) {
|
||||||
assertFalse(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
assertFalse(dict.isInUnderlyingBinaryDictionaryForTests(word));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue