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