use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method assertDecimalFormatIsLossless.
private static void assertDecimalFormatIsLossless(double d) throws Exception {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat format = new DecimalFormat("#0.#", dfs);
format.setGroupingUsed(false);
format.setMaximumIntegerDigits(400);
format.setMaximumFractionDigits(400);
// Every floating point binary can be represented exactly in decimal if you have enough
// digits. This shows the value actually being tested.
String testId = "decimalValue: " + new BigDecimal(d);
// As a sanity check we try out parseDouble() with the string generated by
// Double.toString(). Strictly speaking Double.toString() is probably not guaranteed to be
// lossless, but in reality it probably is, or at least is close enough.
assertDoubleEqual(testId + " failed parseDouble(toString()) sanity check", d, Double.parseDouble(Double.toString(d)));
// Format the number: If this is lossy it is a problem. We are trying to check that it
// doesn't lose any unnecessary precision.
String result = format.format(d);
// Here we use Double.parseDouble() which should able to parse a number we know was
// representable as a double into the original double. If parseDouble() is not implemented
// correctly the test is invalid.
double doubleParsed = Double.parseDouble(result);
assertDoubleEqual(testId + " (format() produced " + result + ")", d, doubleParsed);
// For completeness we try to parse using the formatter too. If this fails but the format
// above didn't it may be a problem with parse(), or with format() that we didn't spot.
assertDoubleEqual(testId + " failed parse(format()) check", d, format.parse(result).doubleValue());
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method test_equalsLjava_lang_Object.
/**
* @tests java.text.DecimalFormatSymbols#equals(java.lang.Object)
*/
public void test_equalsLjava_lang_Object() {
assertTrue("Equal objects returned false", dfs.equals(dfs.clone()));
dfs.setDigit('B');
assertTrue("Un-Equal objects returned true", !dfs.equals(new DecimalFormatSymbols()));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method test_getCurrency.
/**
* @tests java.text.DecimalFormatSymbols#getCurrency()
*/
public void test_getCurrency() {
Currency currency = Currency.getInstance("USD");
assertEquals("Returned incorrect currency", dfsUS.getCurrency(), currency);
Currency currK = Currency.getInstance("KRW");
Currency currX = Currency.getInstance("XXX");
Currency currE = Currency.getInstance("EUR");
// Currency currF = Currency.getInstance("FRF");
DecimalFormatSymbols dfs1 = new DecimalFormatSymbols(new Locale("ko", "KR"));
assertTrue("Test1: Returned incorrect currency", dfs1.getCurrency() == currK);
assertEquals("Test1: Returned incorrect currencySymbol", "₩", dfs1.getCurrencySymbol());
assertEquals("Test1: Returned incorrect intlCurrencySymbol", "KRW", dfs1.getInternationalCurrencySymbol());
dfs1 = new DecimalFormatSymbols(new Locale("", "KR"));
assertTrue("Test2: Returned incorrect currency", dfs1.getCurrency() == currK);
assertEquals("Test2: Returned incorrect currencySymbol", "₩", dfs1.getCurrencySymbol());
assertEquals("Test2: Returned incorrect intlCurrencySymbol", "KRW", dfs1.getInternationalCurrencySymbol());
dfs1 = new DecimalFormatSymbols(new Locale("ko", ""));
assertTrue("Test3: Returned incorrect currency", dfs1.getCurrency() == currX);
assertEquals("Test3: Returned incorrect currencySymbol", "¤", dfs1.getCurrencySymbol());
assertEquals("Test3: Returned incorrect intlCurrencySymbol", "XXX", dfs1.getInternationalCurrencySymbol());
dfs1 = new DecimalFormatSymbols(new Locale("fr", "FR"));
assertTrue("Test4: Returned incorrect currency", dfs1.getCurrency() == currE);
assertEquals("Test4: Returned incorrect currencySymbol", "€", dfs1.getCurrencySymbol());
assertEquals("Test4: Returned incorrect intlCurrencySymbol", "EUR", dfs1.getInternationalCurrencySymbol());
// RI fails these tests since it doesn't have the PREEURO variant
// dfs1 = new DecimalFormatSymbols(new Locale("fr", "FR","PREEURO"));
// assertTrue("Test5: Returned incorrect currency", dfs1.getCurrency()
// == currF);
// assertTrue("Test5: Returned incorrect currencySymbol",
// dfs1.getCurrencySymbol().equals("F"));
// assertTrue("Test5: Returned incorrect intlCurrencySymbol",
// dfs1.getInternationalCurrencySymbol().equals("FRF"));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method test_getInstanceLjava_util_Locale.
public void test_getInstanceLjava_util_Locale() {
try {
DecimalFormatSymbols.getInstance(null);
fail();
} catch (NullPointerException expected) {
}
assertEquals(new DecimalFormatSymbols(Locale.GERMANY), DecimalFormatSymbols.getInstance(Locale.GERMANY));
Locale locale = new Locale("not exist language", "not exist country");
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
assertNotNull(symbols);
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method testSerializationSelf.
/**
* @tests serialization/deserialization compatibility.
*/
public void testSerializationSelf() throws Exception {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ITALIAN);
SerializationTest.verifySelf(symbols);
}
Aggregations