Search in sources :

Example 1 with KeywordStatus

use of android.icu.text.PluralRules.KeywordStatus in project j2objc by google.

the class PluralRulesTest method TestKeywords.

@Test
public void TestKeywords() {
    Set<String> possibleKeywords = new LinkedHashSet(Arrays.asList("zero", "one", "two", "few", "many", "other"));
    Object[][][] tests = { // format is locale, explicits, then triples of keyword, status, unique value.
    { { "en", null }, { "one", KeywordStatus.UNIQUE, 1.0d }, { "other", KeywordStatus.UNBOUNDED, null } }, { { "pl", null }, { "one", KeywordStatus.UNIQUE, 1.0d }, { "few", KeywordStatus.UNBOUNDED, null }, { "many", KeywordStatus.UNBOUNDED, null }, // note that it is
    { "other", KeywordStatus.SUPPRESSED, null, KeywordStatus.UNBOUNDED, null } // suppressed in
    // INTEGER but not
    // DECIMAL
    }, { // check that 1 is suppressed
    { "en", new HashSet<Double>(Arrays.asList(1.0d)) }, { "one", KeywordStatus.SUPPRESSED, null }, { "other", KeywordStatus.UNBOUNDED, null } } };
    Output<Double> uniqueValue = new Output<Double>();
    for (Object[][] test : tests) {
        ULocale locale = new ULocale((String) test[0][0]);
        // NumberType numberType = (NumberType) test[1];
        Set<Double> explicits = (Set<Double>) test[0][1];
        PluralRules pluralRules = factory.forLocale(locale);
        LinkedHashSet<String> remaining = new LinkedHashSet(possibleKeywords);
        for (int i = 1; i < test.length; ++i) {
            Object[] row = test[i];
            String keyword = (String) row[0];
            KeywordStatus statusExpected = (KeywordStatus) row[1];
            Double uniqueExpected = (Double) row[2];
            remaining.remove(keyword);
            KeywordStatus status = pluralRules.getKeywordStatus(keyword, 0, explicits, uniqueValue);
            assertEquals(getAssertMessage("Unique Value", locale, pluralRules, keyword), uniqueExpected, uniqueValue.value);
            assertEquals(getAssertMessage("Keyword Status", locale, pluralRules, keyword), statusExpected, status);
            if (row.length > 3) {
                statusExpected = (KeywordStatus) row[3];
                uniqueExpected = (Double) row[4];
                status = pluralRules.getKeywordStatus(keyword, 0, explicits, uniqueValue, SampleType.DECIMAL);
                assertEquals(getAssertMessage("Unique Value - decimal", locale, pluralRules, keyword), uniqueExpected, uniqueValue.value);
                assertEquals(getAssertMessage("Keyword Status - decimal", locale, pluralRules, keyword), statusExpected, status);
            }
        }
        for (String keyword : remaining) {
            KeywordStatus status = pluralRules.getKeywordStatus(keyword, 0, null, uniqueValue);
            assertEquals("Invalid keyword " + keyword, status, KeywordStatus.INVALID);
            assertNull("Invalid keyword " + keyword, uniqueValue.value);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ULocale(android.icu.util.ULocale) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) PluralRules(android.icu.text.PluralRules) KeywordStatus(android.icu.text.PluralRules.KeywordStatus) Output(android.icu.util.Output) Test(org.junit.Test)

Aggregations

PluralRules (android.icu.text.PluralRules)1 KeywordStatus (android.icu.text.PluralRules.KeywordStatus)1 Output (android.icu.util.Output)1 ULocale (android.icu.util.ULocale)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1