Search in sources :

Example 36 with RuleBasedNumberFormat

use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.

the class RbnfTest method TestGetRuleDisplayNameLocales.

/* Tests the method
     *      public ULocale[] getRuleSetDisplayNameLocales()
     */
@Test
public void TestGetRuleDisplayNameLocales() {
    // Tests when "if (ruleSetDisplayNames != null" is false
    RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat("dummy");
    rbnf.getRuleSetDisplayNameLocales();
    if (rbnf.getRuleSetDisplayNameLocales() != null) {
        errln("RuleBasedNumberFormat.getRuleDisplayNameLocales() was suppose to " + "return null.");
    }
}
Also used : RuleBasedNumberFormat(android.icu.text.RuleBasedNumberFormat) Test(org.junit.Test)

Example 37 with RuleBasedNumberFormat

use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.

the class RbnfTest method TestEquals.

/* Tests the method
     *      public boolean equals(Object that)
     */
@Test
public void TestEquals() {
    // Tests when "if (!(that instanceof RuleBasedNumberFormat))" is true
    RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat("dummy");
    if (rbnf.equals("dummy") || rbnf.equals(new Character('a')) || rbnf.equals(new Object()) || rbnf.equals(-1) || rbnf.equals(0) || rbnf.equals(1) || rbnf.equals(-1.0) || rbnf.equals(0.0) || rbnf.equals(1.0)) {
        errln("RuleBasedNumberFormat.equals(Object that) was suppose to " + "be false for an invalid object.");
    }
    // Tests when
    // "if (!locale.equals(that2.locale) || lenientParse != that2.lenientParse)"
    // is true
    RuleBasedNumberFormat rbnf1 = new RuleBasedNumberFormat("dummy", new Locale("en"));
    RuleBasedNumberFormat rbnf2 = new RuleBasedNumberFormat("dummy", new Locale("jp"));
    RuleBasedNumberFormat rbnf3 = new RuleBasedNumberFormat("dummy", new Locale("sp"));
    RuleBasedNumberFormat rbnf4 = new RuleBasedNumberFormat("dummy", new Locale("fr"));
    if (rbnf1.equals(rbnf2) || rbnf1.equals(rbnf3) || rbnf1.equals(rbnf4) || rbnf2.equals(rbnf3) || rbnf2.equals(rbnf4) || rbnf3.equals(rbnf4)) {
        errln("RuleBasedNumberFormat.equals(Object that) was suppose to " + "be false for an invalid object.");
    }
    if (!rbnf1.equals(rbnf1)) {
        errln("RuleBasedNumberFormat.equals(Object that) was not suppose to " + "be false for an invalid object.");
    }
    if (!rbnf2.equals(rbnf2)) {
        errln("RuleBasedNumberFormat.equals(Object that) was not suppose to " + "be false for an invalid object.");
    }
    if (!rbnf3.equals(rbnf3)) {
        errln("RuleBasedNumberFormat.equals(Object that) was not suppose to " + "be false for an invalid object.");
    }
    if (!rbnf4.equals(rbnf4)) {
        errln("RuleBasedNumberFormat.equals(Object that) was not suppose to " + "be false for an invalid object.");
    }
    RuleBasedNumberFormat rbnf5 = new RuleBasedNumberFormat("dummy", new Locale("en"));
    RuleBasedNumberFormat rbnf6 = new RuleBasedNumberFormat("dummy", new Locale("en"));
    if (!rbnf5.equals(rbnf6)) {
        errln("RuleBasedNumberFormat.equals(Object that) was not suppose to " + "be false for an invalid object.");
    }
    rbnf6.setLenientParseMode(true);
    if (rbnf5.equals(rbnf6)) {
        errln("RuleBasedNumberFormat.equals(Object that) was suppose to " + "be false for an invalid object.");
    }
    // Tests when "if (!ruleSets[i].equals(that2.ruleSets[i]))" is true
    RuleBasedNumberFormat rbnf7 = new RuleBasedNumberFormat("not_dummy", new Locale("en"));
    if (rbnf5.equals(rbnf7)) {
        errln("RuleBasedNumberFormat.equals(Object that) was suppose to " + "be false for an invalid object.");
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) RuleBasedNumberFormat(android.icu.text.RuleBasedNumberFormat) Test(org.junit.Test)

Example 38 with RuleBasedNumberFormat

use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.

the class RbnfTest method TestSetDecimalFormatSymbols.

@Test
public void TestSetDecimalFormatSymbols() {
    RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(Locale.ENGLISH, RuleBasedNumberFormat.ORDINAL);
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.ENGLISH);
    double number = 1001;
    String[] expected = { "1,001st", "1&001st" };
    String result = rbnf.format(number);
    if (!result.equals(expected[0])) {
        errln("Format Error - Got: " + result + " Expected: " + expected[0]);
    }
    /* Set new symbol for testing */
    dfs.setGroupingSeparator('&');
    rbnf.setDecimalFormatSymbols(dfs);
    result = rbnf.format(number);
    if (!result.equals(expected[1])) {
        errln("Format Error - Got: " + result + " Expected: " + expected[1]);
    }
}
Also used : RuleBasedNumberFormat(android.icu.text.RuleBasedNumberFormat) DecimalFormatSymbols(android.icu.text.DecimalFormatSymbols) Test(org.junit.Test)

Example 39 with RuleBasedNumberFormat

use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.

the class RbnfTest method testLargeNumbers.

@Test
public void testLargeNumbers() {
    RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(ULocale.US, RuleBasedNumberFormat.SPELLOUT);
    String[][] enTestFullData = { { "9999999999999998", "nine quadrillion nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-eight" }, { "9999999999999999", "nine quadrillion nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine" }, { "999999999999999999", "nine hundred ninety-nine quadrillion nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine" }, // The rules don't go to 1 quintillion yet
    { "1000000000000000000", "1,000,000,000,000,000,000" }, // We've gone beyond 64-bit precision
    { "-9223372036854775809", "-9,223,372,036,854,775,809" }, // We've gone beyond +64-bit precision
    { "-9223372036854775808", "-9,223,372,036,854,775,808" }, // Minimum 64-bit precision
    { "-9223372036854775807", "minus 9,223,372,036,854,775,807" }, // Minimum 64-bit precision + 1
    { "-9223372036854775806", "minus 9,223,372,036,854,775,806" }, // Below 64-bit precision
    { "9223372036854774111", "9,223,372,036,854,774,111" }, // Below 64-bit precision
    { "9223372036854774999", "9,223,372,036,854,774,999" }, // Below 64-bit precision
    { "9223372036854775000", "9,223,372,036,854,775,000" }, // Maximum 64-bit precision - 1
    { "9223372036854775806", "9,223,372,036,854,775,806" }, // Maximum 64-bit precision
    { "9223372036854775807", "9,223,372,036,854,775,807" }, // We've gone beyond 64-bit precision
    { "9223372036854775808", "9,223,372,036,854,775,808" } };
    doTest(rbnf, enTestFullData, false);
}
Also used : RuleBasedNumberFormat(android.icu.text.RuleBasedNumberFormat) Test(org.junit.Test)

Example 40 with RuleBasedNumberFormat

use of android.icu.text.RuleBasedNumberFormat in project j2objc by google.

the class RbnfTest method TestSwissFrenchSpellout.

/**
 * Perform a simple spot check on the Swiss French spellout rules
 */
@Test
public void TestSwissFrenchSpellout() {
    RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(new Locale("fr", "CH"), RuleBasedNumberFormat.SPELLOUT);
    String[][] testData = { { "1", "un" }, { "15", "quinze" }, { "20", "vingt" }, { "21", "vingt-et-un" }, { "23", "vingt-trois" }, { "62", "soixante-deux" }, { "70", "septante" }, { "71", "septante-et-un" }, { "73", "septante-trois" }, { "80", "huitante" }, { "88", "huitante-huit" }, { "100", "cent" }, { "106", "cent six" }, { "127", "cent vingt-sept" }, { "200", "deux cents" }, { "579", "cinq cent septante-neuf" }, { "1,000", "mille" }, { "1,123", "mille cent vingt-trois" }, { "1,594", "mille cinq cent nonante-quatre" }, { "2,000", "deux mille" }, { "3,004", "trois mille quatre" }, { "4,567", "quatre mille cinq cent soixante-sept" }, { "15,943", "quinze mille neuf cent quarante-trois" }, { "2,345,678", "deux millions trois cent quarante-cinq mille " + "six cent septante-huit" }, { "-36", "moins trente-six" }, { "234.567", "deux cent trente-quatre virgule cinq six sept" } };
    doTest(formatter, testData, true);
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) RuleBasedNumberFormat(android.icu.text.RuleBasedNumberFormat) Test(org.junit.Test)

Aggregations

RuleBasedNumberFormat (android.icu.text.RuleBasedNumberFormat)55 Test (org.junit.Test)52 ULocale (android.icu.util.ULocale)14 Locale (java.util.Locale)14 ParseException (java.text.ParseException)8 NumberFormat (android.icu.text.NumberFormat)3 BigDecimal (android.icu.math.BigDecimal)2 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)2 DisplayContext (android.icu.text.DisplayContext)2 Random (java.util.Random)2 DecimalFormat (android.icu.text.DecimalFormat)1 BigInteger (java.math.BigInteger)1 FieldPosition (java.text.FieldPosition)1 NumberFormat (java.text.NumberFormat)1