DistracterFilterTest.java revision 83c40a2301a0b5a42a75eecada48e7887a7c940e
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.DistracterFilter;
24
25/**
26 * Unit test for DistracterFilter
27 */
28@LargeTest
29public class DistracterFilterTest extends InputTestsBase {
30    private DistracterFilter mDistracterFilter;
31
32    @Override
33    protected void setUp() throws Exception {
34        super.setUp();
35        mDistracterFilter = mLatinIME.createDistracterFilter();
36    }
37
38    public void testIsDistractorToWordsInDictionaries() {
39        final PrevWordsInfo EMPTY_PREV_WORDS_INFO = new PrevWordsInfo(null);
40
41        final Locale localeEnUs = new Locale("en", "US");
42        String typedWord = "alot";
43        // For this test case, we consider "alot" is a distracter to "a lot".
44        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
45                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
46
47        typedWord = "mot";
48        // For this test case, we consider "mot" is a distracter to "not".
49        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
50                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
51
52        typedWord = "wierd";
53        // For this test case, we consider "wierd" is a distracter to "weird".
54        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
55                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
56
57        typedWord = "hoe";
58        // For this test case, we consider "hoe" is a distracter to "how".
59        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
60                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
61
62        typedWord = "nit";
63        // For this test case, we consider "nit" is a distracter to "not".
64        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
65                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
66
67        typedWord = "ill";
68        // For this test case, we consider "ill" is a distracter to "I'll".
69        assertTrue(mDistracterFilter.isDistracterToWordsInDictionaries(
70                EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
71
72        typedWord = "asdfd";
73        // For this test case, we consider "asdfd" is not a distracter to any word in dictionaries.
74        assertFalse(
75                mDistracterFilter.isDistracterToWordsInDictionaries(
76                        EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
77
78        typedWord = "thank";
79        // For this test case, we consider "thank" is not a distracter to any other word
80        // in dictionaries.
81        assertFalse(
82                mDistracterFilter.isDistracterToWordsInDictionaries(
83                        EMPTY_PREV_WORDS_INFO, typedWord, localeEnUs));
84    }
85}
86