Merge "Fix some more tests"

This commit is contained in:
Jean Chalard 2013-12-02 12:41:24 +00:00 committed by Android (Google) Code Review
commit 5fa4ad6a85
3 changed files with 20 additions and 12 deletions

View file

@ -73,8 +73,8 @@ public final class UserHistoryDictIOUtils {
@UsedForTesting
public static void writeDictionary(final DictEncoder dictEncoder,
final BigramDictionaryInterface dict, final UserHistoryDictionaryBigramList bigrams,
final FormatOptions formatOptions) {
final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams);
final FormatOptions formatOptions, final HashMap<String, String> options) {
final FusionDictionary fusionDict = constructFusionDictionary(dict, bigrams, options);
fusionDict.addOptionAttribute(USES_FORGETTING_CURVE_KEY, USES_FORGETTING_CURVE_VALUE);
fusionDict.addOptionAttribute(LAST_UPDATED_TIME_KEY,
String.valueOf(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())));
@ -92,10 +92,10 @@ public final class UserHistoryDictIOUtils {
* Constructs a new FusionDictionary from BigramDictionaryInterface.
*/
@UsedForTesting
static FusionDictionary constructFusionDictionary(
final BigramDictionaryInterface dict, final UserHistoryDictionaryBigramList bigrams) {
static FusionDictionary constructFusionDictionary(final BigramDictionaryInterface dict,
final UserHistoryDictionaryBigramList bigrams, final HashMap<String, String> options) {
final FusionDictionary fusionDict = new FusionDictionary(new PtNodeArray(),
new FusionDictionary.DictionaryOptions(new HashMap<String, String>(), false,
new FusionDictionary.DictionaryOptions(options, false,
false));
int profTotal = 0;
for (final String word1 : bigrams.keySet()) {

View file

@ -558,12 +558,12 @@ public class BinaryDictionaryTests extends AndroidTestCase {
dictFile.delete();
}
public void testRandomOperetionsAndFlashWithGC() {
testRandomOperetionsAndFlashWithGC(3 /* formatVersion */);
testRandomOperetionsAndFlashWithGC(4 /* formatVersion */);
public void testRandomOperationsAndFlashWithGC() {
testRandomOperationsAndFlashWithGC(3 /* formatVersion */);
testRandomOperationsAndFlashWithGC(4 /* formatVersion */);
}
private void testRandomOperetionsAndFlashWithGC(final int formatVersion) {
private void testRandomOperationsAndFlashWithGC(final int formatVersion) {
final int flashWithGCIterationCount = 50;
final int operationCountInEachIteration = 200;
final int initialUnigramCount = 100;

View file

@ -24,6 +24,7 @@ import android.util.Log;
import com.android.inputmethod.latin.makedict.DictDecoder;
import com.android.inputmethod.latin.makedict.DictEncoder;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
@ -53,6 +54,12 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);
private static final String TEST_DICT_FILE_EXTENSION = ".testDict";
private static final HashMap<String, String> HEADER_OPTIONS = new HashMap<String, String>();
static {
HEADER_OPTIONS.put(FileHeader.DICTIONARY_LOCALE_ATTRIBUTE, "en_US");
HEADER_OPTIONS.put(FileHeader.DICTIONARY_ID_ATTRIBUTE, "test");
HEADER_OPTIONS.put(FileHeader.DICTIONARY_VERSION_ATTRIBUTE, "1000");
}
/**
* Return same frequency for all words and bigrams
@ -140,7 +147,8 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
private void writeDictToFile(final File file,
final UserHistoryDictionaryBigramList bigramList) {
final DictEncoder dictEncoder = new Ver3DictEncoder(file);
UserHistoryDictIOUtils.writeDictionary(dictEncoder, this, bigramList, FORMAT_OPTIONS);
UserHistoryDictIOUtils.writeDictionary(dictEncoder, this, bigramList, FORMAT_OPTIONS,
HEADER_OPTIONS);
}
private void readDictFromFile(final File file, final OnAddWordListener listener)
@ -159,8 +167,8 @@ public class UserHistoryDictIOUtilsTests extends AndroidTestCase
addBigramToBigramList("this", "was", addedWords, originalList);
addBigramToBigramList("hello", "world", addedWords, originalList);
final FusionDictionary fusionDict =
UserHistoryDictIOUtils.constructFusionDictionary(this, originalList);
final FusionDictionary fusionDict = UserHistoryDictIOUtils.constructFusionDictionary(
this, originalList, HEADER_OPTIONS);
checkWordsInFusionDict(fusionDict, addedWords);
}