1 /* 2 * Copyright (C) 2009 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 libcore.icu; 18 19 import java.util.Locale; 20 21 public class NativePluralRulesTest extends junit.framework.TestCase { 22 public void testEnglish() throws Exception { 23 NativePluralRules npr = NativePluralRules.forLocale(new Locale("en", "US")); 24 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(-1)); 25 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(0)); 26 assertEquals(NativePluralRules.ONE, npr.quantityForInt(1)); 27 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(2)); 28 } 29 30 public void testCzech() throws Exception { 31 NativePluralRules npr = NativePluralRules.forLocale(new Locale("cs", "CZ")); 32 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(-1)); 33 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(0)); 34 assertEquals(NativePluralRules.ONE, npr.quantityForInt(1)); 35 assertEquals(NativePluralRules.FEW, npr.quantityForInt(2)); 36 assertEquals(NativePluralRules.FEW, npr.quantityForInt(3)); 37 assertEquals(NativePluralRules.FEW, npr.quantityForInt(4)); 38 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(5)); 39 } 40 41 public void testArabic() throws Exception { 42 NativePluralRules npr = NativePluralRules.forLocale(new Locale("ar")); 43 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(-1)); 44 assertEquals(NativePluralRules.ZERO, npr.quantityForInt(0)); 45 assertEquals(NativePluralRules.ONE, npr.quantityForInt(1)); 46 assertEquals(NativePluralRules.TWO, npr.quantityForInt(2)); 47 for (int i = 3; i <= 10; ++i) { 48 assertEquals(NativePluralRules.FEW, npr.quantityForInt(i)); 49 } 50 assertEquals(NativePluralRules.MANY, npr.quantityForInt(11)); 51 assertEquals(NativePluralRules.MANY, npr.quantityForInt(99)); 52 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(100)); 53 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(101)); 54 assertEquals(NativePluralRules.OTHER, npr.quantityForInt(102)); 55 assertEquals(NativePluralRules.FEW, npr.quantityForInt(103)); 56 assertEquals(NativePluralRules.MANY, npr.quantityForInt(111)); 57 } 58 59 public void testHebrew() throws Exception { 60 // java.util.Locale will translate "he" to the deprecated "iw". 61 NativePluralRules he = NativePluralRules.forLocale(new Locale("he")); 62 assertEquals(NativePluralRules.ONE, he.quantityForInt(1)); 63 assertEquals(NativePluralRules.TWO, he.quantityForInt(2)); 64 assertEquals(NativePluralRules.OTHER, he.quantityForInt(3)); 65 assertEquals(NativePluralRules.MANY, he.quantityForInt(10)); 66 } 67 } 68