use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.
the class RbnfLenientScannerTest method TestEnglishSpellout.
/**
* Perform a simple spot check on the English spellout rules
*/
@Test
public void TestEnglishSpellout() {
RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(Locale.US, RuleBasedNumberFormat.SPELLOUT);
formatter.setLenientScannerProvider(provider);
formatter.setLenientParseMode(true);
String[][] lpTestData = { { "FOurhundred thiRTY six", "436" }, // leaving "-7" for remaining parse, resulting in 2643 as the parse result.
{ "fifty-7", "57" }, { " fifty-7", "57" }, { " fifty-7", "57" }, { "2 thousand six HUNDRED fifty-7", "2,657" }, { "fifteen hundred and zero", "1,500" } };
doLenientParseTest(formatter, lpTestData);
}
use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.
the class RbnfTest method TestOrdinalAbbreviations.
/**
* Perform a simple spot check on the English ordinal-abbreviation rules
*/
@Test
public void TestOrdinalAbbreviations() {
RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(Locale.US, RuleBasedNumberFormat.ORDINAL);
String[][] testData = { { "1", "1st" }, { "2", "2nd" }, { "3", "3rd" }, { "4", "4th" }, { "7", "7th" }, { "10", "10th" }, { "11", "11th" }, { "13", "13th" }, { "20", "20th" }, { "21", "21st" }, { "22", "22nd" }, { "23", "23rd" }, { "24", "24th" }, { "33", "33rd" }, { "102", "102nd" }, { "312", "312th" }, { "12,345", "12,345th" } };
doTest(formatter, testData, false);
}
use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.
the class RbnfTest method TestGetRulesSetDisplayName.
/* Tests the method
* public String getRuleSetDisplayName(String ruleSetName, ULocale loc)
*/
@Test
public void TestGetRulesSetDisplayName() {
RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat("dummy");
// Tests when the method throws an exception
try {
rbnf.getRuleSetDisplayName("", new ULocale("en_US"));
errln("RuleBasedNumberFormat.getRuleSetDisplayName(String ruleSetName, ULocale loc) " + "was suppose to have an exception.");
} catch (Exception e) {
}
try {
rbnf.getRuleSetDisplayName("dummy", new ULocale("en_US"));
errln("RuleBasedNumberFormat.getRuleSetDisplayName(String ruleSetName, ULocale loc) " + "was suppose to have an exception.");
} catch (Exception e) {
}
}
use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.
the class RbnfTest method TestSpanishSpellout.
/**
* Perform a simple spot check on the Spanish spellout rules
*/
@Test
public void TestSpanishSpellout() {
RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(new Locale("es", "es", ""), RuleBasedNumberFormat.SPELLOUT);
String[][] testData = { { "1", "uno" }, { "6", "seis" }, { "16", "diecis\u00e9is" }, { "20", "veinte" }, { "24", "veinticuatro" }, { "26", "veintis\u00e9is" }, { "73", "setenta y tres" }, { "88", "ochenta y ocho" }, { "100", "cien" }, { "106", "ciento seis" }, { "127", "ciento veintisiete" }, { "200", "doscientos" }, { "579", "quinientos setenta y nueve" }, { "1,000", "mil" }, { "2,000", "dos mil" }, { "3,004", "tres mil cuatro" }, { "4,567", "cuatro mil quinientos sesenta y siete" }, { "15,943", "quince mil novecientos cuarenta y tres" }, { "2,345,678", "dos millones trescientos cuarenta y cinco mil " + "seiscientos setenta y ocho" }, { "-36", "menos treinta y seis" }, { "234.567", "doscientos treinta y cuatro coma cinco seis siete" } };
doTest(formatter, testData, true);
}
use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.
the class RbnfTest method TestUndefinedSpellout.
@Test
public void TestUndefinedSpellout() {
Locale greek = new Locale("el", "", "");
RuleBasedNumberFormat[] formatters = { new RuleBasedNumberFormat(greek, RuleBasedNumberFormat.SPELLOUT), new RuleBasedNumberFormat(greek, RuleBasedNumberFormat.ORDINAL), new RuleBasedNumberFormat(greek, RuleBasedNumberFormat.DURATION) };
String[] data = { "0", "1", "15", "20", "23", "73", "88", "100", "106", "127", "200", "579", "1,000", "2,000", "3,004", "4,567", "15,943", "105,000", "2,345,678", "-36", "-36.91215", "234.56789" };
NumberFormat decFormat = NumberFormat.getInstance(Locale.US);
for (int j = 0; j < formatters.length; ++j) {
android.icu.text.NumberFormat formatter = formatters[j];
logln("formatter[" + j + "]");
for (int i = 0; i < data.length; ++i) {
try {
String result = formatter.format(decFormat.parse(data[i]));
logln("[" + i + "] " + data[i] + " ==> " + result);
} catch (Exception e) {
errln("formatter[" + j + "], data[" + i + "] " + data[i] + " threw exception " + e.getMessage());
}
}
}
}
Aggregations