1 /* 2 * Copyright (C) 2013 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 17 package com.android.inputmethod.latin; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 /** 23 * Unit test for ExpandableDictionary 24 */ 25 @SmallTest 26 public class ExpandableDictionaryTests extends AndroidTestCase { 27 28 private final static int UNIGRAM_FREQ = 50; 29 // See UserBinaryDictionary for more information about this variable. 30 // For tests, its actual value does not matter. 31 private final static int SHORTCUT_FREQ = 14; 32 33 public void testAddWordAndGetWordFrequency() { 34 final ExpandableDictionary dict = new ExpandableDictionary(Dictionary.TYPE_USER); 35 36 // Add words 37 dict.addWord("abcde", "abcde", UNIGRAM_FREQ, SHORTCUT_FREQ); 38 dict.addWord("abcef", null, UNIGRAM_FREQ + 1, 0); 39 40 // Check words 41 assertFalse(dict.isValidWord("abcde")); 42 assertEquals(UNIGRAM_FREQ, dict.getWordFrequency("abcde")); 43 assertTrue(dict.isValidWord("abcef")); 44 assertEquals(UNIGRAM_FREQ+1, dict.getWordFrequency("abcef")); 45 46 dict.addWord("abc", null, UNIGRAM_FREQ + 2, 0); 47 assertTrue(dict.isValidWord("abc")); 48 assertEquals(UNIGRAM_FREQ + 2, dict.getWordFrequency("abc")); 49 50 // Add existing word with lower frequency 51 dict.addWord("abc", null, UNIGRAM_FREQ, 0); 52 assertEquals(UNIGRAM_FREQ + 2, dict.getWordFrequency("abc")); 53 54 // Add existing word with higher frequency 55 dict.addWord("abc", null, UNIGRAM_FREQ + 3, 0); 56 assertEquals(UNIGRAM_FREQ + 3, dict.getWordFrequency("abc")); 57 } 58 } 59