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);
}
}
}
Aggregations