2010-07-26 18:43:29 +00:00
|
|
|
/*
|
2011-02-08 09:30:26 +00:00
|
|
|
* Copyright (C) 2010,2011 The Android Open Source Project
|
2010-07-26 18:43:29 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-04-29 01:12:58 +00:00
|
|
|
|
2010-08-04 01:28:38 +00:00
|
|
|
package com.android.inputmethod.latin;
|
2010-04-29 01:12:58 +00:00
|
|
|
|
2010-08-04 01:28:38 +00:00
|
|
|
import com.android.inputmethod.latin.tests.R;
|
2010-04-29 01:12:58 +00:00
|
|
|
|
2011-02-08 09:30:26 +00:00
|
|
|
import android.content.res.AssetFileDescriptor;
|
2010-04-29 01:12:58 +00:00
|
|
|
|
2011-02-25 05:36:30 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2011-02-08 09:30:26 +00:00
|
|
|
public class SuggestTests extends SuggestTestsBase {
|
|
|
|
private SuggestHelper mHelper;
|
2010-04-29 01:12:58 +00:00
|
|
|
|
|
|
|
@Override
|
2011-02-08 09:30:26 +00:00
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
|
|
|
final AssetFileDescriptor dict = openTestRawResourceFd(R.raw.test);
|
|
|
|
mHelper = new SuggestHelper(
|
|
|
|
getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
|
2011-02-25 05:36:30 +00:00
|
|
|
createKeyboardId(Locale.US));
|
2011-02-08 09:30:26 +00:00
|
|
|
mHelper.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************** Tests ************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for simple completions of one character.
|
|
|
|
*/
|
|
|
|
public void testCompletion1char() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("people", mHelper.getFirstSuggestion("peopl"));
|
|
|
|
suggested("about", mHelper.getFirstSuggestion("abou"));
|
|
|
|
suggested("their", mHelper.getFirstSuggestion("thei"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for simple completions of two characters.
|
|
|
|
*/
|
|
|
|
public void testCompletion2char() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("people", mHelper.getFirstSuggestion("peop"));
|
|
|
|
suggested("calling", mHelper.getFirstSuggestion("calli"));
|
|
|
|
suggested("business", mHelper.getFirstSuggestion("busine"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for proximity errors.
|
|
|
|
*/
|
|
|
|
public void testProximityPositive() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("typed peiple", "people", mHelper.getFirstSuggestion("peiple"));
|
|
|
|
suggested("typed peoole", "people", mHelper.getFirstSuggestion("peoole"));
|
|
|
|
suggested("typed pwpple", "people", mHelper.getFirstSuggestion("pwpple"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-08 09:30:26 +00:00
|
|
|
* Tests for proximity errors - negative, when the error key is not close.
|
2010-04-29 01:12:58 +00:00
|
|
|
*/
|
|
|
|
public void testProximityNegative() {
|
2011-02-08 09:30:26 +00:00
|
|
|
notSuggested("about", mHelper.getFirstSuggestion("arout"));
|
|
|
|
notSuggested("are", mHelper.getFirstSuggestion("ire"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for checking if apostrophes are added automatically.
|
|
|
|
*/
|
|
|
|
public void testApostropheInsertion() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("I'm", mHelper.getFirstSuggestion("im"));
|
|
|
|
suggested("don't", mHelper.getFirstSuggestion("dont"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test to make sure apostrophed word is not suggested for an apostrophed word.
|
|
|
|
*/
|
|
|
|
public void testApostrophe() {
|
2011-02-08 09:30:26 +00:00
|
|
|
notSuggested("don't", mHelper.getFirstSuggestion("don't"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for suggestion of capitalized version of a word.
|
|
|
|
*/
|
|
|
|
public void testCapitalization() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("I'm", mHelper.getFirstSuggestion("i'm"));
|
|
|
|
suggested("Sunday", mHelper.getFirstSuggestion("sunday"));
|
|
|
|
suggested("Sunday", mHelper.getFirstSuggestion("sundat"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests to see if more than one completion is provided for certain prefixes.
|
|
|
|
*/
|
|
|
|
public void testMultipleCompletions() {
|
2011-02-08 09:30:26 +00:00
|
|
|
isInSuggestions("com: come", mHelper.getSuggestIndex("com", "come"));
|
|
|
|
isInSuggestions("com: company", mHelper.getSuggestIndex("com", "company"));
|
|
|
|
isInSuggestions("th: the", mHelper.getSuggestIndex("th", "the"));
|
|
|
|
isInSuggestions("th: that", mHelper.getSuggestIndex("th", "that"));
|
|
|
|
isInSuggestions("th: this", mHelper.getSuggestIndex("th", "this"));
|
|
|
|
isInSuggestions("th: they", mHelper.getSuggestIndex("th", "they"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the suggestion engine recognize zero frequency words as valid words.
|
|
|
|
*/
|
|
|
|
public void testZeroFrequencyAccepted() {
|
2011-02-08 09:30:26 +00:00
|
|
|
assertTrue("valid word yikes", mHelper.isValidWord("yikes"));
|
|
|
|
assertFalse("non valid word yike", mHelper.isValidWord("yike"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests to make sure that zero frequency words are not suggested as completions.
|
|
|
|
*/
|
|
|
|
public void testZeroFrequencySuggestionsNegative() {
|
2011-02-20 05:35:45 +00:00
|
|
|
assertTrue(mHelper.getSuggestIndex("yike", "yikes") < 0);
|
|
|
|
assertTrue(mHelper.getSuggestIndex("what", "whatcha") < 0);
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-08 09:30:26 +00:00
|
|
|
* Tests to ensure that words with large edit distances are not suggested, in some cases.
|
|
|
|
* Also such word is not considered auto correction, in some cases.
|
2010-04-29 01:12:58 +00:00
|
|
|
*/
|
|
|
|
public void testTooLargeEditDistance() {
|
2011-02-20 05:35:45 +00:00
|
|
|
assertTrue(mHelper.getSuggestIndex("sniyr", "about") < 0);
|
2010-12-16 13:55:13 +00:00
|
|
|
// TODO: The following test fails.
|
2011-02-08 09:30:26 +00:00
|
|
|
// notSuggested("the", mHelper.getAutoCorrection("rjw"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-08 09:30:26 +00:00
|
|
|
* Make sure mHelper.isValidWord is case-sensitive.
|
2010-04-29 01:12:58 +00:00
|
|
|
*/
|
|
|
|
public void testValidityCaseSensitivity() {
|
2011-02-08 09:30:26 +00:00
|
|
|
assertTrue("valid word Sunday", mHelper.isValidWord("Sunday"));
|
|
|
|
assertFalse("non valid word sunday", mHelper.isValidWord("sunday"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Are accented forms of words suggested as corrections?
|
|
|
|
*/
|
|
|
|
public void testAccents() {
|
2010-06-01 10:58:36 +00:00
|
|
|
// ni<LATIN SMALL LETTER N WITH TILDE>o
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("ni\u00F1o", mHelper.getAutoCorrection("nino"));
|
2010-06-01 10:58:36 +00:00
|
|
|
// ni<LATIN SMALL LETTER N WITH TILDE>o
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("ni\u00F1o", mHelper.getAutoCorrection("nimo"));
|
2010-06-01 10:58:36 +00:00
|
|
|
// Mar<LATIN SMALL LETTER I WITH ACUTE>a
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("Mar\u00EDa", mHelper.getAutoCorrection("maria"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
2010-07-01 03:28:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure bigrams are showing when first character is typed
|
|
|
|
* and don't show any when there aren't any
|
|
|
|
*/
|
|
|
|
public void testBigramsAtFirstChar() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("bigram: about p[art]",
|
|
|
|
"part", mHelper.getBigramFirstSuggestion("about", "p"));
|
|
|
|
suggested("bigram: I'm a[bout]",
|
|
|
|
"about", mHelper.getBigramFirstSuggestion("I'm", "a"));
|
|
|
|
suggested("bigram: about b[usiness]",
|
|
|
|
"business", mHelper.getBigramFirstSuggestion("about", "b"));
|
|
|
|
isInSuggestions("bigram: about b[eing]",
|
|
|
|
mHelper.searchBigramSuggestion("about", "b", "being"));
|
|
|
|
notSuggested("bigram: about p",
|
|
|
|
"business", mHelper.getBigramFirstSuggestion("about", "p"));
|
2010-07-01 03:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure bigrams score affects the original score
|
|
|
|
*/
|
|
|
|
public void testBigramsScoreEffect() {
|
2011-02-08 09:30:26 +00:00
|
|
|
suggested("single: page",
|
|
|
|
"page", mHelper.getAutoCorrection("pa"));
|
|
|
|
suggested("bigram: about pa[rt]",
|
|
|
|
"part", mHelper.getBigramAutoCorrection("about", "pa"));
|
2010-12-16 13:55:13 +00:00
|
|
|
// TODO: The following test fails.
|
2011-02-08 09:30:26 +00:00
|
|
|
// suggested("single: said", "said", mHelper.getAutoCorrection("sa"));
|
|
|
|
suggested("bigram: from sa[me]",
|
|
|
|
"same", mHelper.getBigramAutoCorrection("from", "sa"));
|
2010-04-29 01:12:58 +00:00
|
|
|
}
|
|
|
|
}
|