DistracterFilterTest.java revision bdf745da32ddd4b2d0e395c7ae9eb346fffcfe91
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.inputmethod.latin; 18 19import java.util.Locale; 20 21import android.test.suitebuilder.annotation.LargeTest; 22 23import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatches; 24 25/** 26 * Unit test for DistracterFilter 27 */ 28@LargeTest 29public class DistracterFilterTest extends InputTestsBase { 30 private DistracterFilterCheckingExactMatches mDistracterFilter; 31 32 @Override 33 protected void setUp() throws Exception { 34 super.setUp(); 35 mDistracterFilter = new DistracterFilterCheckingExactMatches(getContext()); 36 mDistracterFilter.updateEnabledSubtypes(mLatinIME.getEnabledSubtypesForTest()); 37 } 38 39 public void testIsDistractorToWordsInDictionaries() { 40 final PrevWordsInfo EMPTY_PREV_WORDS_INFO = PrevWordsInfo.EMPTY_PREV_WORDS_INFO; 41 42 final Locale localeEnUs = new Locale("en", "US"); 43 String typedWord; 44 45 typedWord = "Bill"; 46 // For this test case, we consider "Bill" is a distracter to "bill". 47 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 48 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 49 50 typedWord = "nOt"; 51 // For this test case, we consider "nOt" is a distracter to "not". 52 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 53 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 54 55 typedWord = "youre"; 56 // For this test case, we consider "youre" is a distracter to "you're". 57 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 58 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 59 60 typedWord = "Banana"; 61 // For this test case, we consider "Banana" is a distracter to "banana". 62 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 63 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 64 65 typedWord = "orange"; 66 // For this test case, we consider "orange" is not a distracter to any word in dictionaries. 67 assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( 68 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 69 70 typedWord = "Orange"; 71 // For this test case, we consider "Orange" is a distracter to "orange". 72 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 73 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 74 75 typedWord = "café"; 76 // For this test case, we consider "café" is a distracter to "cafe". 77 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 78 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 79 80 typedWord = "cafe"; 81 // For this test case, we consider "cafe" is not a distracter to any word in dictionaries. 82 assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( 83 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 84 85 typedWord = "I'll"; 86 // For this test case, we consider "I'll" is not a distracter to any word in dictionaries. 87 assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( 88 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 89 90 typedWord = "ill"; 91 // For this test case, we consider "ill" is a distracter to "I'll" 92 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 93 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 94 95 typedWord = "asdfd"; 96 // For this test case, we consider "asdfd" is not a distracter to any word in dictionaries. 97 assertFalse( 98 mDistracterFilter.isDistracterToWordsInDictionaries( 99 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 100 101 typedWord = "thank"; 102 // For this test case, we consider "thank" is not a distracter to any other word 103 // in dictionaries. 104 assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( 105 EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs)); 106 107 final Locale localeDeDe = new Locale("de", "DE"); 108 109 typedWord = "fuer"; 110 // For this test case, we consider "fuer" is a distracter to "für". 111 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 112 EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); 113 114 typedWord = "fUEr"; 115 // For this test case, we consider "fUEr" is a distracter to "für". 116 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 117 EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); 118 119 typedWord = "fur"; 120 // For this test case, we consider "fur" is a distracter to "für". 121 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 122 EMPTY_PREV_WORDS_INFO, typedWord, localeDeDe)); 123 124 final Locale localeFrFr = new Locale("fr", "FR"); 125 126 typedWord = "a"; 127 // For this test case, we consider "a" is a distracter to "à". 128 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 129 EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); 130 131 typedWord = "à"; 132 // For this test case, we consider "à" is not a distracter to any word in dictionaries. 133 assertFalse(mDistracterFilter.isDistracterToWordsInDictionaries( 134 EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); 135 136 typedWord = "etre"; 137 // For this test case, we consider "etre" is a distracter to "être". 138 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 139 EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); 140 141 typedWord = "États-unis"; 142 // For this test case, we consider "États-unis" is a distracter to "États-Unis". 143 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 144 EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); 145 146 typedWord = "ÉtatsUnis"; 147 // For this test case, we consider "ÉtatsUnis" is a distracter to "États-Unis". 148 assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries( 149 EMPTY_PREV_WORDS_INFO, typedWord, localeFrFr)); 150 } 151} 152