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 17 package com.android.inputmethod.latin; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertTrue; 22 23 import android.test.suitebuilder.annotation.SmallTest; 24 25 import org.junit.Test; 26 27 import java.util.Locale; 28 29 /** 30 * Tests for {@link ContactsDictionaryUtils} 31 */ 32 @SmallTest 33 public class ContactsDictionaryUtilsTest { 34 35 @Test testGetWordEndPosition()36 public void testGetWordEndPosition() { 37 final String testString1 = "Larry Page"; 38 assertEquals(5, ContactsDictionaryUtils.getWordEndPosition( 39 testString1, testString1.length(), 0 /* startIndex */)); 40 41 assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( 42 testString1, testString1.length(), 6 /* startIndex */)); 43 44 final String testString2 = "Larry-Page"; 45 assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( 46 testString2, testString1.length(), 0 /* startIndex */)); 47 48 final String testString3 = "Larry'Page"; 49 assertEquals(10, ContactsDictionaryUtils.getWordEndPosition( 50 testString3, testString1.length(), 0 /* startIndex */)); 51 } 52 53 @Test testUseFirstLastBigramsForLocale()54 public void testUseFirstLastBigramsForLocale() { 55 assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.ENGLISH)); 56 assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.US)); 57 assertTrue(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.UK)); 58 assertFalse(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.CHINA)); 59 assertFalse(ContactsDictionaryUtils.useFirstLastBigramsForLocale(Locale.GERMAN)); 60 } 61 } 62