Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f88ec161 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi Committed by Android (Google) Code Review
Browse files

Merge "Fix unit tests."

parents 5c6db929 845c0619
Loading
Loading
Loading
Loading
+24 −3
Original line number Original line Diff line number Diff line
@@ -132,7 +132,8 @@ public class PrevWordsInfo {


    @Override
    @Override
    public int hashCode() {
    public int hashCode() {
        return Arrays.hashCode(mPrevWordsInfo);
        // Just for having equals().
        return mPrevWordsInfo[0].hashCode();
    }
    }


    @Override
    @Override
@@ -140,7 +141,23 @@ public class PrevWordsInfo {
        if (this == o) return true;
        if (this == o) return true;
        if (!(o instanceof PrevWordsInfo)) return false;
        if (!(o instanceof PrevWordsInfo)) return false;
        final PrevWordsInfo prevWordsInfo = (PrevWordsInfo)o;
        final PrevWordsInfo prevWordsInfo = (PrevWordsInfo)o;
        return Arrays.equals(mPrevWordsInfo, prevWordsInfo.mPrevWordsInfo);

        final int minLength = Math.min(mPrevWordsInfo.length, prevWordsInfo.mPrevWordsInfo.length);
        for (int i = 0; i < minLength; i++) {
            if (!mPrevWordsInfo[i].equals(prevWordsInfo.mPrevWordsInfo[i])) {
                return false;
            }
        }
        final WordInfo[] longerWordsInfo =
                (mPrevWordsInfo.length > prevWordsInfo.mPrevWordsInfo.length) ?
                        mPrevWordsInfo : prevWordsInfo.mPrevWordsInfo;
        for (int i = minLength; i < longerWordsInfo.length; i++) {
            if (longerWordsInfo[i] != null
                    && !WordInfo.EMPTY_WORD_INFO.equals(longerWordsInfo[i])) {
                return false;
            }
        }
        return true;
    }
    }


    @Override
    @Override
@@ -151,7 +168,11 @@ public class PrevWordsInfo {
            builder.append("PrevWord[");
            builder.append("PrevWord[");
            builder.append(i);
            builder.append(i);
            builder.append("]: ");
            builder.append("]: ");
            if (wordInfo == null || !wordInfo.isValid()) {
            if (wordInfo == null) {
                builder.append("null. ");
                continue;
            }
            if (!wordInfo.isValid()) {
                builder.append("Empty. ");
                builder.append("Empty. ");
                continue;
                continue;
            }
            }
+2 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.inputmethod.latin.utils;
package com.android.inputmethod.latin.utils;


import java.util.Arrays;
import java.util.regex.Pattern;
import java.util.regex.Pattern;


import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.Constants;
@@ -56,6 +57,7 @@ public final class PrevWordsInfoUtils {
        if (prev == null) return PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
        if (prev == null) return PrevWordsInfo.EMPTY_PREV_WORDS_INFO;
        final String[] w = SPACE_REGEX.split(prev);
        final String[] w = SPACE_REGEX.split(prev);
        final WordInfo[] prevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
        final WordInfo[] prevWordsInfo = new WordInfo[Constants.MAX_PREV_WORD_COUNT_FOR_N_GRAM];
        Arrays.fill(prevWordsInfo, WordInfo.EMPTY_WORD_INFO);
        for (int i = 0; i < prevWordsInfo.length; i++) {
        for (int i = 0; i < prevWordsInfo.length; i++) {
            final int focusedWordIndex = w.length - n - i;
            final int focusedWordIndex = w.length - n - i;
            // Referring to the word after the focused word.
            // Referring to the word after the focused word.
@@ -66,7 +68,6 @@ public final class PrevWordsInfoUtils {
                    if (spacingAndPunctuations.isWordConnector(firstChar)) {
                    if (spacingAndPunctuations.isWordConnector(firstChar)) {
                        // The word following the focused word is starting with a word connector.
                        // The word following the focused word is starting with a word connector.
                        // TODO: Return meaningful context for this case.
                        // TODO: Return meaningful context for this case.
                        prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO;
                        break;
                        break;
                    }
                    }
                }
                }
@@ -93,7 +94,6 @@ public final class PrevWordsInfoUtils {
            // TODO: Return meaningful context for this case.
            // TODO: Return meaningful context for this case.
            if (spacingAndPunctuations.isWordSeparator(lastChar)
            if (spacingAndPunctuations.isWordSeparator(lastChar)
                    || spacingAndPunctuations.isWordConnector(lastChar)) {
                    || spacingAndPunctuations.isWordConnector(lastChar)) {
                prevWordsInfo[i] = WordInfo.EMPTY_WORD_INFO;
                break;
                break;
            }
            }
            prevWordsInfo[i] = new WordInfo(focusedWord);
            prevWordsInfo[i] = new WordInfo(focusedWord);