am 29500ef4: Fix the BinaryDictionaryTests

* commit '29500ef4ba8e01f4c467a62399c8249d532ee82c':
  Fix the BinaryDictionaryTests
main
Mohammadinamul Sheik 2015-03-14 01:29:06 +00:00 committed by Android Git Automerger
commit 6fa6abae2f
2 changed files with 7 additions and 5 deletions

View File

@ -58,6 +58,8 @@ public final class BinaryDictionary extends Dictionary {
// Must be equal to CONFIDENCE_TO_AUTO_COMMIT in native/jni/src/defines.h // Must be equal to CONFIDENCE_TO_AUTO_COMMIT in native/jni/src/defines.h
private static final int CONFIDENCE_TO_AUTO_COMMIT = 1000000; private static final int CONFIDENCE_TO_AUTO_COMMIT = 1000000;
static final int DICTIONARY_MAX_WORD_LENGTH = 48;
@UsedForTesting @UsedForTesting
public static final String UNIGRAM_COUNT_QUERY = "UNIGRAM_COUNT"; public static final String UNIGRAM_COUNT_QUERY = "UNIGRAM_COUNT";
@UsedForTesting @UsedForTesting
@ -318,9 +320,9 @@ public final class BinaryDictionary extends Dictionary {
final int count = session.mOutputSuggestionCount[0]; final int count = session.mOutputSuggestionCount[0];
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>(); final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
final int start = j * DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; final int start = j * DICTIONARY_MAX_WORD_LENGTH;
int len = 0; int len = 0;
while (len < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH while (len < DICTIONARY_MAX_WORD_LENGTH
&& session.mOutputCodePoints[start + len] != 0) { && session.mOutputCodePoints[start + len] != 0) {
++len; ++len;
} }
@ -389,7 +391,7 @@ public final class BinaryDictionary extends Dictionary {
return null; return null;
} }
final int[] codePoints = StringUtils.toCodePointArray(word); final int[] codePoints = StringUtils.toCodePointArray(word);
final int[] outCodePoints = new int[DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH]; final int[] outCodePoints = new int[DICTIONARY_MAX_WORD_LENGTH];
final boolean[] outFlags = new boolean[FORMAT_WORD_PROPERTY_OUTPUT_FLAG_COUNT]; final boolean[] outFlags = new boolean[FORMAT_WORD_PROPERTY_OUTPUT_FLAG_COUNT];
final int[] outProbabilityInfo = final int[] outProbabilityInfo =
new int[FORMAT_WORD_PROPERTY_OUTPUT_PROBABILITY_INFO_COUNT]; new int[FORMAT_WORD_PROPERTY_OUTPUT_PROBABILITY_INFO_COUNT];
@ -428,7 +430,7 @@ public final class BinaryDictionary extends Dictionary {
* If token is 0, this method newly starts iterating the dictionary. * If token is 0, this method newly starts iterating the dictionary.
*/ */
public GetNextWordPropertyResult getNextWordProperty(final int token) { public GetNextWordPropertyResult getNextWordProperty(final int token) {
final int[] codePoints = new int[DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH]; final int[] codePoints = new int[DICTIONARY_MAX_WORD_LENGTH];
final boolean[] isBeginningOfSentence = new boolean[1]; final boolean[] isBeginningOfSentence = new boolean[1];
final int nextToken = getNextWordNative(mNativeDict, token, codePoints, final int nextToken = getNextWordNative(mNativeDict, token, codePoints,
isBeginningOfSentence); isBeginningOfSentence);

View File

@ -170,7 +170,7 @@ public class BinaryDictionaryTests extends AndroidTestCase {
private void testAddTooLongWord(final int formatVersion) { private void testAddTooLongWord(final int formatVersion) {
final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(formatVersion); final BinaryDictionary binaryDictionary = getEmptyBinaryDictionary(formatVersion);
final StringBuffer stringBuilder = new StringBuffer(); final StringBuffer stringBuilder = new StringBuffer();
for (int i = 0; i < DecoderSpecificConstants.DICTIONARY_MAX_WORD_LENGTH; i++) { for (int i = 0; i < BinaryDictionary.DICTIONARY_MAX_WORD_LENGTH; i++) {
stringBuilder.append('a'); stringBuilder.append('a');
} }
final String validLongWord = stringBuilder.toString(); final String validLongWord = stringBuilder.toString();