aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java5
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java43
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java17
-rw-r--r--tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java195
6 files changed, 24 insertions, 240 deletions
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
index 5d842950c..edeb6a6c2 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTestsBase.java
@@ -52,9 +52,8 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
- final String language = TEST_LOCALE.getLanguage();
- mCodesSet.setLanguage(language);
- mTextsSet.setLanguage(language);
+ mCodesSet.setLocale(TEST_LOCALE);
+ mTextsSet.setLocale(TEST_LOCALE);
final Context context = getContext();
new RunInLocale<Void>() {
@Override
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
index 5f301a839..42a94f420 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java
@@ -41,7 +41,7 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase {
final Instrumentation instrumentation = getInstrumentation();
final Context targetContext = instrumentation.getTargetContext();
- mTextsSet.setLanguage(TEST_LOCALE.getLanguage());
+ mTextsSet.setLocale(TEST_LOCALE);
new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
diff --git a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
index b1bdef81f..13700418f 100644
--- a/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
+++ b/tests/src/com/android/inputmethod/latin/BinaryDictionaryTests.java
@@ -24,9 +24,9 @@ import android.util.Pair;
import com.android.inputmethod.latin.makedict.CodePointUtils;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
+import com.android.inputmethod.latin.makedict.WordProperty;
import com.android.inputmethod.latin.utils.FileUtils;
import com.android.inputmethod.latin.utils.LanguageModelParam;
-import com.android.inputmethod.latin.utils.WordProperty;
import java.io.File;
import java.io.IOException;
@@ -916,15 +916,15 @@ public class BinaryDictionaryTests extends AndroidTestCase {
}
words.add(word);
wordProbabilities.put(word, unigramProbability);
- final WordProperty unigramProperty = binaryDictionary.getWordProperty(word);
- assertEquals(word, unigramProperty.mCodePoints);
- assertTrue(unigramProperty.isValid());
- assertEquals(isNotAWord, unigramProperty.mIsNotAWord);
- assertEquals(isBlacklisted, unigramProperty.mIsBlacklisted);
- assertEquals(false, unigramProperty.mHasBigrams);
- assertEquals(false, unigramProperty.mHasShortcuts);
- assertEquals(unigramProbability, unigramProperty.mProbabilityInfo.mProbability);
- assertTrue(unigramProperty.mShortcutTargets.isEmpty());
+ final WordProperty wordProperty = binaryDictionary.getWordProperty(word);
+ assertEquals(word, wordProperty.mWord);
+ assertTrue(wordProperty.isValid());
+ assertEquals(isNotAWord, wordProperty.mIsNotAWord);
+ assertEquals(isBlacklisted, wordProperty.mIsBlacklistEntry);
+ assertEquals(false, wordProperty.mHasBigrams);
+ assertEquals(false, wordProperty.mHasShortcuts);
+ assertEquals(unigramProbability, wordProperty.mProbabilityInfo.mProbability);
+ assertTrue(wordProperty.mShortcutTargets.isEmpty());
}
for (int i = 0; i < BIGRAM_COUNT; i++) {
@@ -955,18 +955,15 @@ public class BinaryDictionaryTests extends AndroidTestCase {
continue;
}
final HashSet<String> bigramWord1s = bigrams.get(word0);
- final WordProperty unigramProperty = binaryDictionary.getWordProperty(word0);
- assertEquals(bigramWord1s.size(), unigramProperty.mBigramTargets.size());
- assertEquals(unigramProperty.mBigramTargets.size(),
- unigramProperty.mBigramProbabilityInfo.size());
- for (int j = 0; j < unigramProperty.mBigramTargets.size(); j++) {
- final String word1 = unigramProperty.mBigramTargets.get(j).mWord;
+ final WordProperty wordProperty = binaryDictionary.getWordProperty(word0);
+ assertEquals(bigramWord1s.size(), wordProperty.mBigrams.size());
+ for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
+ final String word1 = wordProperty.mBigrams.get(j).mWord;
assertTrue(bigramWord1s.contains(word1));
- final int probability = unigramProperty.mBigramTargets.get(j).getProbability();
+ final int probability = wordProperty.mBigrams.get(j).getProbability();
assertEquals((int)bigramProbabilities.get(new Pair<String, String>(word0, word1)),
probability);
- assertEquals(unigramProperty.mBigramProbabilityInfo.get(j).mProbability,
- probability);
+ assertEquals(wordProperty.mBigrams.get(j).getProbability(), probability);
}
}
}
@@ -1045,15 +1042,15 @@ public class BinaryDictionaryTests extends AndroidTestCase {
final BinaryDictionary.GetNextWordPropertyResult result =
binaryDictionary.getNextWordProperty(token);
final WordProperty wordProperty = result.mWordProperty;
- final String word0 = wordProperty.mCodePoints;
+ final String word0 = wordProperty.mWord;
assertEquals((int)wordProbabilitiesToCheckLater.get(word0),
wordProperty.mProbabilityInfo.mProbability);
wordSet.remove(word0);
final HashSet<String> bigramWord1s = bigrams.get(word0);
- for (int j = 0; j < wordProperty.mBigramTargets.size(); j++) {
- final String word1 = wordProperty.mBigramTargets.get(j).mWord;
+ for (int j = 0; j < wordProperty.mBigrams.size(); j++) {
+ final String word1 = wordProperty.mBigrams.get(j).mWord;
assertTrue(bigramWord1s.contains(word1));
- final int probability = wordProperty.mBigramTargets.get(j).getProbability();
+ final int probability = wordProperty.mBigrams.get(j).getProbability();
final Pair<String, String> bigram = new Pair<String, String>(word0, word1);
assertEquals((int)bigramProbabilitiesToCheckLater.get(bigram), probability);
bigramSet.remove(bigram);
diff --git a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
index 375352067..53839b67f 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestedWordsTests.java
@@ -46,7 +46,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
}
final SuggestedWords words = new SuggestedWords(
- list,
+ list, null /* rawSuggestions */,
false /* typedWordValid */,
false /* willAutoCorrect */,
false /* isPunctuationSuggestions */,
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
index 0815819d6..bc4452fd6 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderEncoderTests.java
@@ -468,10 +468,6 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
BinaryDictUtils.VERSION2_OPTIONS);
- runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
- BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
- runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_BUFFER,
- BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
for (final String result : results) {
Log.d(TAG, result);
@@ -483,10 +479,6 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
BinaryDictUtils.VERSION2_OPTIONS);
- runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
- BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
- runReadUnigramsAndBigramsTests(results, BinaryDictUtils.USE_BYTE_ARRAY,
- BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
for (final String result : results) {
Log.d(TAG, result);
@@ -597,17 +589,8 @@ public class BinaryDictDecoderEncoderTests extends AndroidTestCase {
runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
BinaryDictUtils.VERSION2_OPTIONS);
- runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
- BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
- runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_ARRAY,
- BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
-
runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
BinaryDictUtils.VERSION2_OPTIONS);
- runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
- BinaryDictUtils.VERSION4_OPTIONS_WITHOUT_TIMESTAMP);
- runGetTerminalPositionTests(BinaryDictUtils.USE_BYTE_BUFFER,
- BinaryDictUtils.VERSION4_OPTIONS_WITH_TIMESTAMP);
for (final String result : results) {
Log.d(TAG, result);
diff --git a/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java b/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java
deleted file mode 100644
index aeb8552bd..000000000
--- a/tests/src/com/android/inputmethod/latin/makedict/SparseTableTests.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.inputmethod.latin.makedict;
-
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.util.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Random;
-
-/**
- * Unit tests for SparseTable.
- */
-@LargeTest
-public class SparseTableTests extends AndroidTestCase {
- private static final String TAG = SparseTableTests.class.getSimpleName();
-
- private final Random mRandom;
- private final ArrayList<Integer> mRandomIndex;
-
- private static final int DEFAULT_SIZE = 10000;
- private static final int BLOCK_SIZE = 8;
-
- public SparseTableTests() {
- this(System.currentTimeMillis(), DEFAULT_SIZE);
- }
-
- public SparseTableTests(final long seed, final int tableSize) {
- super();
- Log.d(TAG, "Seed for test is " + seed + ", size is " + tableSize);
- mRandom = new Random(seed);
- mRandomIndex = new ArrayList<Integer>(tableSize);
- for (int i = 0; i < tableSize; ++i) {
- mRandomIndex.add(SparseTable.NOT_EXIST);
- }
- }
-
- public void testSet() {
- final SparseTable table = new SparseTable(16, BLOCK_SIZE, 1);
- table.set(0, 3, 6);
- table.set(0, 8, 16);
- for (int i = 0; i < 16; ++i) {
- if (i == 3 || i == 8) {
- assertEquals(i * 2, table.get(0, i));
- } else {
- assertEquals(SparseTable.NOT_EXIST, table.get(0, i));
- }
- }
- }
-
- private void generateRandomIndex(final int size, final int prop) {
- for (int i = 0; i < size; ++i) {
- if (mRandom.nextInt(100) < prop) {
- mRandomIndex.set(i, mRandom.nextInt());
- } else {
- mRandomIndex.set(i, SparseTable.NOT_EXIST);
- }
- }
- }
-
- private void runTestRandomSet() {
- final SparseTable table = new SparseTable(DEFAULT_SIZE, BLOCK_SIZE, 1);
- int elementCount = 0;
- for (int i = 0; i < DEFAULT_SIZE; ++i) {
- if (mRandomIndex.get(i) != SparseTable.NOT_EXIST) {
- table.set(0, i, mRandomIndex.get(i));
- elementCount++;
- }
- }
-
- Log.d(TAG, "table size = " + table.getLookupTableSize() + " + "
- + table.getContentTableSize());
- Log.d(TAG, "the table has " + elementCount + " elements");
- for (int i = 0; i < DEFAULT_SIZE; ++i) {
- assertEquals(table.get(0, i), (int)mRandomIndex.get(i));
- }
-
- // flush and reload
- OutputStream lookupOutStream = null;
- OutputStream contentOutStream = null;
- try {
- final File lookupIndexFile = File.createTempFile("testRandomSet", ".small");
- final File contentFile = File.createTempFile("testRandomSet", ".big");
- lookupOutStream = new FileOutputStream(lookupIndexFile);
- contentOutStream = new FileOutputStream(contentFile);
- table.write(lookupOutStream, new OutputStream[] { contentOutStream });
- lookupOutStream.flush();
- contentOutStream.flush();
- final SparseTable newTable = SparseTable.readFromFiles(lookupIndexFile,
- new File[] { contentFile }, BLOCK_SIZE);
- for (int i = 0; i < DEFAULT_SIZE; ++i) {
- assertEquals(table.get(0, i), newTable.get(0, i));
- }
- } catch (IOException e) {
- Log.d(TAG, "IOException while flushing and realoding", e);
- } finally {
- if (lookupOutStream != null) {
- try {
- lookupOutStream.close();
- } catch (IOException e) {
- Log.d(TAG, "IOException while closing the stream", e);
- }
- }
- if (contentOutStream != null) {
- try {
- contentOutStream.close();
- } catch (IOException e) {
- Log.d(TAG, "IOException while closing contentStream.", e);
- }
- }
- }
- }
-
- public void testRandomSet() {
- for (int i = 0; i <= 100; i += 10) {
- generateRandomIndex(DEFAULT_SIZE, i);
- runTestRandomSet();
- }
- }
-
- public void testMultipleContents() {
- final int numOfContents = 5;
- generateRandomIndex(DEFAULT_SIZE, 20);
- final SparseTable table = new SparseTable(DEFAULT_SIZE, BLOCK_SIZE, numOfContents);
- for (int i = 0; i < mRandomIndex.size(); ++i) {
- if (mRandomIndex.get(i) != SparseTable.NOT_EXIST) {
- for (int j = 0; j < numOfContents; ++j) {
- table.set(j, i, mRandomIndex.get(i));
- }
- }
- }
-
- OutputStream lookupOutStream = null;
- OutputStream[] contentsOutStream = new OutputStream[numOfContents];
- try {
- final File lookupIndexFile = File.createTempFile("testMultipleContents", "small");
- lookupOutStream = new FileOutputStream(lookupIndexFile);
- final File[] contentFiles = new File[numOfContents];
- for (int i = 0; i < numOfContents; ++i) {
- contentFiles[i] = File.createTempFile("testMultipleContents", "big" + i);
- contentsOutStream[i] = new FileOutputStream(contentFiles[i]);
- }
- table.write(lookupOutStream, contentsOutStream);
- lookupOutStream.flush();
- for (int i = 0; i < numOfContents; ++i) {
- contentsOutStream[i].flush();
- }
- final SparseTable newTable = SparseTable.readFromFiles(lookupIndexFile, contentFiles,
- BLOCK_SIZE);
- for (int i = 0; i < numOfContents; ++i) {
- for (int j = 0; j < DEFAULT_SIZE; ++j) {
- assertEquals(table.get(i, j), newTable.get(i, j));
- }
- }
- } catch (IOException e) {
- Log.d(TAG, "IOException while flushing and reloading", e);
- } finally {
- if (lookupOutStream != null) {
- try {
- lookupOutStream.close();
- } catch (IOException e) {
- Log.d(TAG, "IOException while closing the stream", e);
- }
- }
- for (int i = 0; i < numOfContents; ++i) {
- if (contentsOutStream[i] != null) {
- try {
- contentsOutStream[i].close();
- } catch (IOException e) {
- Log.d(TAG, "IOException while closing the stream.", e);
- }
- }
- }
- }
- }
-}