LEFT | RIGHT |
1 // © 2016 and later: Unicode, Inc. and others. | 1 // © 2016 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 /* | 3 /* |
4 ******************************************************************************* | 4 ******************************************************************************* |
5 * Copyright (C) 2001-2016, International Business Machines Corporation and | 5 * Copyright (C) 2001-2016, International Business Machines Corporation and |
6 * others. All Rights Reserved. | 6 * others. All Rights Reserved. |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 */ | 8 */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 import org.junit.Test; | 35 import org.junit.Test; |
36 | 36 |
37 import com.ibm.icu.dev.test.TestFmwk; | 37 import com.ibm.icu.dev.test.TestFmwk; |
38 import com.ibm.icu.dev.test.TestUtil; | 38 import com.ibm.icu.dev.test.TestUtil; |
39 import com.ibm.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer; | 39 import com.ibm.icu.dev.test.format.IntlTestDecimalFormatAPIC.FieldContainer; |
40 import com.ibm.icu.impl.ICUConfig; | 40 import com.ibm.icu.impl.ICUConfig; |
41 import com.ibm.icu.impl.LocaleUtility; | 41 import com.ibm.icu.impl.LocaleUtility; |
42 import com.ibm.icu.impl.data.ResourceReader; | 42 import com.ibm.icu.impl.data.ResourceReader; |
43 import com.ibm.icu.impl.data.TokenIterator; | 43 import com.ibm.icu.impl.data.TokenIterator; |
| 44 import com.ibm.icu.impl.number.rounders.SignificantDigitsRounder.SignificantDigi
tsMode; |
44 import com.ibm.icu.math.BigDecimal; | 45 import com.ibm.icu.math.BigDecimal; |
45 import com.ibm.icu.math.MathContext; | 46 import com.ibm.icu.math.MathContext; |
46 import com.ibm.icu.text.CompactDecimalFormat; | 47 import com.ibm.icu.text.CompactDecimalFormat; |
47 import com.ibm.icu.text.DecimalFormat; | 48 import com.ibm.icu.text.DecimalFormat; |
48 import com.ibm.icu.text.DecimalFormatSymbols; | 49 import com.ibm.icu.text.DecimalFormatSymbols; |
49 import com.ibm.icu.text.DisplayContext; | 50 import com.ibm.icu.text.DisplayContext; |
50 import com.ibm.icu.text.MeasureFormat; | 51 import com.ibm.icu.text.MeasureFormat; |
51 import com.ibm.icu.text.NumberFormat; | 52 import com.ibm.icu.text.NumberFormat; |
52 import com.ibm.icu.text.NumberFormat.NumberFormatFactory; | 53 import com.ibm.icu.text.NumberFormat.NumberFormatFactory; |
53 import com.ibm.icu.text.NumberFormat.SimpleNumberFormatFactory; | 54 import com.ibm.icu.text.NumberFormat.SimpleNumberFormatFactory; |
(...skipping 3413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3467 } | 3468 } |
3468 | 3469 |
3469 } | 3470 } |
3470 | 3471 |
3471 @Test | 3472 @Test |
3472 public void TestCurrencyAmountCoverage() { | 3473 public void TestCurrencyAmountCoverage() { |
3473 CurrencyAmount ca, cb; | 3474 CurrencyAmount ca, cb; |
3474 | 3475 |
3475 try { | 3476 try { |
3476 ca = new CurrencyAmount(null, null); | 3477 ca = new CurrencyAmount(null, null); |
3477 errln("IllegalArgumentException should have been thrown."); | 3478 errln("NullPointerException should have been thrown."); |
3478 } catch (IllegalArgumentException ex) { | 3479 } catch (NullPointerException ex) { |
3479 } | 3480 } |
3480 try { | 3481 try { |
3481 ca = new CurrencyAmount(new Integer(0), null); | 3482 ca = new CurrencyAmount(new Integer(0), null); |
3482 errln("IllegalArgumentException should have been thrown."); | 3483 errln("NullPointerException should have been thrown."); |
3483 } catch (IllegalArgumentException ex) { | 3484 } catch (NullPointerException ex) { |
3484 } | 3485 } |
3485 | 3486 |
3486 ca = new CurrencyAmount(new Integer(0), Currency.getInstance(new ULocale
("ja_JP"))); | 3487 ca = new CurrencyAmount(new Integer(0), Currency.getInstance(new ULocale
("ja_JP"))); |
3487 cb = new CurrencyAmount(new Integer(1), Currency.getInstance(new ULocale
("ja_JP"))); | 3488 cb = new CurrencyAmount(new Integer(1), Currency.getInstance(new ULocale
("ja_JP"))); |
3488 if (ca.equals(null)) { | 3489 if (ca.equals(null)) { |
3489 errln("Comparison should return false."); | 3490 errln("Comparison should return false."); |
3490 } | 3491 } |
3491 if (!ca.equals(ca)) { | 3492 if (!ca.equals(ca)) { |
3492 errln("Comparision should return true."); | 3493 errln("Comparision should return true."); |
3493 } | 3494 } |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4110 df.setMinimumFractionDigits(4); | 4111 df.setMinimumFractionDigits(4); |
4111 assertEquals("Currency with min fraction == 4", "$1.2340", df.format(1.2
34)); | 4112 assertEquals("Currency with min fraction == 4", "$1.2340", df.format(1.2
34)); |
4112 } | 4113 } |
4113 | 4114 |
4114 @Test | 4115 @Test |
4115 public void TestParseRequiredDecimalPoint() { | 4116 public void TestParseRequiredDecimalPoint() { |
4116 | 4117 |
4117 String[] testPattern = { "00.####", "00.0", "00" }; | 4118 String[] testPattern = { "00.####", "00.0", "00" }; |
4118 | 4119 |
4119 String value2Parse = "99"; | 4120 String value2Parse = "99"; |
| 4121 String value2ParseWithDecimal = "99.9"; |
4120 double parseValue = 99; | 4122 double parseValue = 99; |
| 4123 double parseValueWithDecimal = 99.9; |
4121 DecimalFormat parser = new DecimalFormat(); | 4124 DecimalFormat parser = new DecimalFormat(); |
4122 double result; | 4125 double result; |
4123 boolean hasDecimalPoint; | 4126 boolean hasDecimalPoint; |
4124 for (int i = 0; i < testPattern.length; i++) { | 4127 for (int i = 0; i < testPattern.length; i++) { |
4125 parser.applyPattern(testPattern[i]); | 4128 parser.applyPattern(testPattern[i]); |
4126 hasDecimalPoint = testPattern[i].contains("."); | 4129 hasDecimalPoint = testPattern[i].contains("."); |
4127 | 4130 |
4128 parser.setDecimalPatternMatchRequired(false); | 4131 parser.setDecimalPatternMatchRequired(false); |
4129 try { | 4132 try { |
4130 result = parser.parse(value2Parse).doubleValue(); | 4133 result = parser.parse(value2Parse).doubleValue(); |
4131 assertEquals("wrong parsed value", parseValue, result); | 4134 assertEquals("wrong parsed value", parseValue, result); |
4132 } catch (ParseException e) { | 4135 } catch (ParseException e) { |
4133 TestFmwk.errln("Parsing " + value2Parse + " should have succeede
d with " + testPattern[i] + | 4136 TestFmwk.errln("Parsing " + value2Parse + " should have succeede
d with " + testPattern[i] + |
4134 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); | 4137 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); |
4135 } | 4138 } |
| 4139 try { |
| 4140 result = parser.parse(value2ParseWithDecimal).doubleValue(); |
| 4141 assertEquals("wrong parsed value", parseValueWithDecimal, result
); |
| 4142 } catch (ParseException e) { |
| 4143 TestFmwk.errln("Parsing " + value2ParseWithDecimal + " should ha
ve succeeded with " + testPattern[i] + |
| 4144 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); |
| 4145 } |
4136 | 4146 |
4137 parser.setDecimalPatternMatchRequired(true); | 4147 parser.setDecimalPatternMatchRequired(true); |
4138 try { | 4148 try { |
4139 result = parser.parse(value2Parse).doubleValue(); | 4149 result = parser.parse(value2Parse).doubleValue(); |
4140 if(hasDecimalPoint){ | 4150 if(hasDecimalPoint){ |
4141 TestFmwk.errln("Parsing " + value2Parse + " should NOT have
succeeded with " + testPattern[i] + | 4151 TestFmwk.errln("Parsing " + value2Parse + " should NOT have
succeeded with " + testPattern[i] + |
| 4152 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); |
| 4153 } |
| 4154 } catch (ParseException e) { |
| 4155 // OK, should fail |
| 4156 } |
| 4157 try { |
| 4158 result = parser.parse(value2ParseWithDecimal).doubleValue(); |
| 4159 if(!hasDecimalPoint){ |
| 4160 TestFmwk.errln("Parsing " + value2ParseWithDecimal + " shoul
d NOT have succeeded with " + testPattern[i] + |
4142 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); | 4161 " and isDecimalPointMatchRequired set to: " + parser
.isDecimalPatternMatchRequired()); |
4143 } | 4162 } |
4144 } catch (ParseException e) { | 4163 } catch (ParseException e) { |
4145 // OK, should fail | 4164 // OK, should fail |
4146 } | 4165 } |
4147 } | 4166 } |
4148 } | 4167 } |
4149 | 4168 |
4150 @Test | 4169 @Test |
4151 public void TestCurrFmtNegSameAsPositive() { | 4170 public void TestCurrFmtNegSameAsPositive() { |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4705 assertEquals("Triple-currency should give long name on getPositivePrefix
", "US dollars ", result); | 4724 assertEquals("Triple-currency should give long name on getPositivePrefix
", "US dollars ", result); |
4706 } | 4725 } |
4707 | 4726 |
4708 @Test | 4727 @Test |
4709 public void Test11645() { | 4728 public void Test11645() { |
4710 String pattern = "#,##0.0#"; | 4729 String pattern = "#,##0.0#"; |
4711 DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance(); | 4730 DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance(); |
4712 fmt.applyPattern(pattern); | 4731 fmt.applyPattern(pattern); |
4713 DecimalFormat fmtCopy; | 4732 DecimalFormat fmtCopy; |
4714 | 4733 |
| 4734 final int newMultiplier = 37; |
4715 fmtCopy = (DecimalFormat) fmt.clone(); | 4735 fmtCopy = (DecimalFormat) fmt.clone(); |
4716 fmtCopy.setMultiplier(37); | 4736 assertNotEquals("Value before setter", fmtCopy.getMultiplier(), newMulti
plier); |
| 4737 fmtCopy.setMultiplier(newMultiplier); |
| 4738 assertEquals("Value after setter", fmtCopy.getMultiplier(), newMultiplie
r); |
4717 fmtCopy.applyPattern(pattern); | 4739 fmtCopy.applyPattern(pattern); |
| 4740 assertEquals("Value after applyPattern", fmtCopy.getMultiplier(), newMul
tiplier); |
4718 assertFalse("multiplier", fmt.equals(fmtCopy)); | 4741 assertFalse("multiplier", fmt.equals(fmtCopy)); |
4719 | 4742 |
| 4743 final int newRoundingMode = RoundingMode.CEILING.ordinal(); |
4720 fmtCopy = (DecimalFormat) fmt.clone(); | 4744 fmtCopy = (DecimalFormat) fmt.clone(); |
4721 fmtCopy.setRoundingMode(RoundingMode.CEILING.ordinal()); | 4745 assertNotEquals("Value before setter", fmtCopy.getRoundingMode(), newRou
ndingMode); |
| 4746 fmtCopy.setRoundingMode(newRoundingMode); |
| 4747 assertEquals("Value after setter", fmtCopy.getRoundingMode(), newRoundin
gMode); |
4722 fmtCopy.applyPattern(pattern); | 4748 fmtCopy.applyPattern(pattern); |
| 4749 assertEquals("Value after applyPattern", fmtCopy.getRoundingMode(), newR
oundingMode); |
4723 assertFalse("roundingMode", fmt.equals(fmtCopy)); | 4750 assertFalse("roundingMode", fmt.equals(fmtCopy)); |
4724 | 4751 |
| 4752 final Currency newCurrency = Currency.getInstance("EAT"); |
4725 fmtCopy = (DecimalFormat) fmt.clone(); | 4753 fmtCopy = (DecimalFormat) fmt.clone(); |
4726 fmtCopy.setCurrency(Currency.getInstance("EAT")); | 4754 assertNotEquals("Value before setter", fmtCopy.getCurrency(), newCurrenc
y); |
| 4755 fmtCopy.setCurrency(newCurrency); |
| 4756 assertEquals("Value after setter", fmtCopy.getCurrency(), newCurrency); |
4727 fmtCopy.applyPattern(pattern); | 4757 fmtCopy.applyPattern(pattern); |
| 4758 assertEquals("Value after applyPattern", fmtCopy.getCurrency(), newCurre
ncy); |
4728 assertFalse("currency", fmt.equals(fmtCopy)); | 4759 assertFalse("currency", fmt.equals(fmtCopy)); |
4729 | 4760 |
| 4761 final CurrencyUsage newCurrencyUsage = CurrencyUsage.CASH; |
4730 fmtCopy = (DecimalFormat) fmt.clone(); | 4762 fmtCopy = (DecimalFormat) fmt.clone(); |
| 4763 assertNotEquals("Value before setter", fmtCopy.getCurrencyUsage(), newCu
rrencyUsage); |
4731 fmtCopy.setCurrencyUsage(CurrencyUsage.CASH); | 4764 fmtCopy.setCurrencyUsage(CurrencyUsage.CASH); |
| 4765 assertEquals("Value after setter", fmtCopy.getCurrencyUsage(), newCurren
cyUsage); |
4732 fmtCopy.applyPattern(pattern); | 4766 fmtCopy.applyPattern(pattern); |
| 4767 assertEquals("Value after applyPattern", fmtCopy.getCurrencyUsage(), new
CurrencyUsage); |
4733 assertFalse("currencyUsage", fmt.equals(fmtCopy)); | 4768 assertFalse("currencyUsage", fmt.equals(fmtCopy)); |
4734 } | 4769 } |
4735 | 4770 |
4736 @Test | 4771 @Test |
4737 public void Test11646() { | 4772 public void Test11646() { |
4738 DecimalFormatSymbols symbols = new DecimalFormatSymbols(new ULocale("en_
US")); | 4773 DecimalFormatSymbols symbols = new DecimalFormatSymbols(new ULocale("en_
US")); |
4739 String pattern = "\u00a4\u00a4\u00a4 0.00 %\u00a4\u00a4"; | 4774 String pattern = "\u00a4\u00a4\u00a4 0.00 %\u00a4\u00a4"; |
4740 DecimalFormat fmt = new DecimalFormat(pattern, symbols); | 4775 DecimalFormat fmt = new DecimalFormat(pattern, symbols); |
4741 | 4776 |
4742 // Test equality with affixes. set affix methods can't capture special | 4777 // Test equality with affixes. set affix methods can't capture special |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4875 @Test | 4910 @Test |
4876 public void Test11739() { | 4911 public void Test11739() { |
4877 NumberFormat nf = NumberFormat.getCurrencyInstance(new ULocale("sr_BA"))
; | 4912 NumberFormat nf = NumberFormat.getCurrencyInstance(new ULocale("sr_BA"))
; |
4878 ((DecimalFormat) nf).applyPattern("0.0 ¤¤¤"); | 4913 ((DecimalFormat) nf).applyPattern("0.0 ¤¤¤"); |
4879 ParsePosition ppos = new ParsePosition(0); | 4914 ParsePosition ppos = new ParsePosition(0); |
4880 CurrencyAmount result = nf.parseCurrency("1.500 амерички долар", ppos); | 4915 CurrencyAmount result = nf.parseCurrency("1.500 амерички долар", ppos); |
4881 assertEquals("Should parse to 1500 USD", new CurrencyAmount(1500, Curren
cy.getInstance("USD")), result); | 4916 assertEquals("Should parse to 1500 USD", new CurrencyAmount(1500, Curren
cy.getInstance("USD")), result); |
4882 } | 4917 } |
4883 | 4918 |
4884 @Test | 4919 @Test |
| 4920 public void Test11647() { |
| 4921 DecimalFormat df = new DecimalFormat(); |
| 4922 df.applyPattern("¤¤¤¤#"); |
| 4923 String actual = df.format(123); |
| 4924 assertEquals("Should replace 4 currency signs with U+FFFD", "\uFFFD123",
actual); |
| 4925 } |
| 4926 |
| 4927 @Test |
| 4928 public void Test12567() { |
| 4929 DecimalFormat df1 = (DecimalFormat) NumberFormat.getInstance(NumberForma
t.PLURALCURRENCYSTYLE); |
| 4930 DecimalFormat df2 = (DecimalFormat) NumberFormat.getInstance(NumberForma
t.NUMBERSTYLE); |
| 4931 df2.setCurrency(df1.getCurrency()); |
| 4932 df2.setCurrencyPluralInfo(df1.getCurrencyPluralInfo()); |
| 4933 df1.applyPattern("0.00"); |
| 4934 df2.applyPattern("0.00"); |
| 4935 assertEquals("df1 == df2", df1, df2); |
| 4936 assertEquals("df2 == df1", df2, df1); |
| 4937 df2.setPositivePrefix("abc"); |
| 4938 assertNotEquals("df1 != df2", df1, df2); |
| 4939 assertNotEquals("df2 != df1", df2, df1); |
| 4940 } |
| 4941 |
| 4942 @Test |
| 4943 public void testPercentZero() { |
| 4944 DecimalFormat df = (DecimalFormat) NumberFormat.getPercentInstance(); |
| 4945 String actual = df.format(0); |
| 4946 assertEquals("Should have one zero digit", "0%", actual); |
| 4947 } |
| 4948 |
| 4949 @Test |
| 4950 public void testCurrencyZeroRounding() { |
| 4951 DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(); |
| 4952 df.setMaximumFractionDigits(0); |
| 4953 String actual = df.format(0); |
| 4954 assertEquals("Should have zero fraction digits", "$0", actual); |
| 4955 } |
| 4956 |
| 4957 @Test |
| 4958 public void testCustomCurrencySymbol() { |
| 4959 DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(); |
| 4960 df.setCurrency(Currency.getInstance("USD")); |
| 4961 DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); |
| 4962 symbols.setCurrencySymbol("#"); |
| 4963 df.setDecimalFormatSymbols(symbols); |
| 4964 String actual = df.format(123); |
| 4965 assertEquals("Should use '#' instad of '$'", "#123.00", actual); |
| 4966 } |
| 4967 |
| 4968 @Test |
4885 public void TestBasicSerializationRoundTrip() throws IOException, ClassNotFo
undException { | 4969 public void TestBasicSerializationRoundTrip() throws IOException, ClassNotFo
undException { |
4886 DecimalFormat df0 = new DecimalFormat("A-**#####,#00.00b¤"); | 4970 DecimalFormat df0 = new DecimalFormat("A-**#####,#00.00b¤"); |
4887 | 4971 |
4888 // Write to byte stream | 4972 // Write to byte stream |
4889 ByteArrayOutputStream baos = new ByteArrayOutputStream(); | 4973 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
4890 ObjectOutputStream oos = new ObjectOutputStream(baos); | 4974 ObjectOutputStream oos = new ObjectOutputStream(baos); |
4891 oos.writeObject(df0); | 4975 oos.writeObject(df0); |
4892 oos.flush(); | 4976 oos.flush(); |
4893 baos.close(); | 4977 baos.close(); |
4894 byte[] bytes = baos.toByteArray(); | 4978 byte[] bytes = baos.toByteArray(); |
(...skipping 16 matching lines...) Expand all Loading... |
4911 @Test | 4995 @Test |
4912 public void testGetSetCurrency() { | 4996 public void testGetSetCurrency() { |
4913 DecimalFormat df = new DecimalFormat("¤#"); | 4997 DecimalFormat df = new DecimalFormat("¤#"); |
4914 assertEquals("Currency should start out null", null, df.getCurrency()); | 4998 assertEquals("Currency should start out null", null, df.getCurrency()); |
4915 Currency curr = Currency.getInstance("EUR"); | 4999 Currency curr = Currency.getInstance("EUR"); |
4916 df.setCurrency(curr); | 5000 df.setCurrency(curr); |
4917 assertEquals("Currency should equal EUR after set", curr, df.getCurrency
()); | 5001 assertEquals("Currency should equal EUR after set", curr, df.getCurrency
()); |
4918 String result = df.format(123); | 5002 String result = df.format(123); |
4919 assertEquals("Currency should format as expected in EUR", "€123.00", res
ult); | 5003 assertEquals("Currency should format as expected in EUR", "€123.00", res
ult); |
4920 } | 5004 } |
| 5005 |
| 5006 @Test |
| 5007 public void testRoundingModeSetters() { |
| 5008 DecimalFormat df1 = new DecimalFormat(); |
| 5009 DecimalFormat df2 = new DecimalFormat(); |
| 5010 |
| 5011 df1.setRoundingMode(java.math.BigDecimal.ROUND_CEILING); |
| 5012 assertNotEquals("Rounding mode was set to a non-default", df1, df2); |
| 5013 df2.setRoundingMode(com.ibm.icu.math.BigDecimal.ROUND_CEILING); |
| 5014 assertEquals("Rounding mode from icu.math and java.math should be the sa
me", df1, df2); |
| 5015 df2.setRoundingMode(java.math.RoundingMode.CEILING.ordinal()); |
| 5016 assertEquals("Rounding mode ordinal from java.math.RoundingMode should b
e the same", df1, df2); |
| 5017 } |
| 5018 |
| 5019 @Test |
| 5020 public void testSignificantDigitsMode() { |
| 5021 String[][] allExpected = { |
| 5022 {"12340.0", "12340.0", "12340.0"}, |
| 5023 {"1234.0", "1234.0", "1234.0"}, |
| 5024 {"123.4", "123.4", "123.4"}, |
| 5025 {"12.34", "12.34", "12.34"}, |
| 5026 {"1.234", "1.23", "1.23"}, |
| 5027 {"0.1234", "0.12", "0.123"}, |
| 5028 {"0.01234", "0.01", "0.0123"}, |
| 5029 {"0.001234", "0.00", "0.00123"} |
| 5030 }; |
| 5031 |
| 5032 DecimalFormat df = new DecimalFormat(); |
| 5033 df.setMinimumFractionDigits(1); |
| 5034 df.setMaximumFractionDigits(2); |
| 5035 df.setMinimumSignificantDigits(3); |
| 5036 df.setMaximumSignificantDigits(4); |
| 5037 df.setGroupingUsed(false); |
| 5038 |
| 5039 SignificantDigitsMode[] modes = new SignificantDigitsMode[] { |
| 5040 SignificantDigitsMode.OVERRIDE_MAXIMUM_FRACTION, |
| 5041 SignificantDigitsMode.RESPECT_MAXIMUM_FRACTION, |
| 5042 SignificantDigitsMode.ENSURE_MINIMUM_SIGNIFICANT |
| 5043 }; |
| 5044 |
| 5045 for (double d = 12340.0, i=0; d > 0.001; d /= 10, i++) { |
| 5046 for (int j=0; j<modes.length; j++) { |
| 5047 SignificantDigitsMode mode = modes[j]; |
| 5048 df.setSignificantDigitsMode(mode); |
| 5049 String expected = allExpected[(int)i][j]; |
| 5050 String actual = df.format(d); |
| 5051 assertEquals("Significant digits mode getter is broken", |
| 5052 mode, df.getSignificantDigitsMode()); |
| 5053 assertEquals("Significant digits output differs for "+i+", "+j, |
| 5054 expected, actual); |
| 5055 } |
| 5056 } |
| 5057 } |
| 5058 |
| 5059 @Test |
| 5060 public void testParseNoExponent() throws ParseException { |
| 5061 DecimalFormat df = new DecimalFormat(); |
| 5062 assertEquals("Parse no exponent has wrong default", false, df.getParseNo
Exponent()); |
| 5063 Number result1 = df.parse("123E4"); |
| 5064 df.setParseNoExponent(true); |
| 5065 assertEquals("Parse no exponent getter is broken", true, df.getParseNoEx
ponent()); |
| 5066 Number result2 = df.parse("123E4"); |
| 5067 assertEquals("Exponent did not parse before setParseNoExponent", result1
, new Long(1230000)); |
| 5068 assertEquals("Exponent parsed after setParseNoExponent", result2, new Lo
ng(123)); |
| 5069 } |
| 5070 |
| 5071 @Test |
| 5072 public void testMinimumGroupingDigits() { |
| 5073 String[][] allExpected = { |
| 5074 {"123", "123"}, |
| 5075 {"1,230", "1230"}, |
| 5076 {"12,300", "12,300"}, |
| 5077 {"1,23,000", "1,23,000"} |
| 5078 }; |
| 5079 |
| 5080 DecimalFormat df = new DecimalFormat("#,##,##0"); |
| 5081 assertEquals("Minimum grouping digits has wrong default", 1, df.getMinim
umGroupingDigits()); |
| 5082 |
| 5083 for (int l = 123, i=0; l <= 123000; l *= 10, i++) { |
| 5084 df.setMinimumGroupingDigits(1); |
| 5085 assertEquals("Minimum grouping digits getter is broken", 1, df.getMi
nimumGroupingDigits()); |
| 5086 String actual = df.format(l); |
| 5087 assertEquals("Output is wrong for 1, "+i, allExpected[i][0], actual)
; |
| 5088 df.setMinimumGroupingDigits(2); |
| 5089 assertEquals("Minimum grouping digits getter is broken", 2, df.getMi
nimumGroupingDigits()); |
| 5090 actual = df.format(l); |
| 5091 assertEquals("Output is wrong for 2, "+i, allExpected[i][1], actual)
; |
| 5092 } |
| 5093 } |
| 5094 |
| 5095 @Test |
| 5096 public void testParseCaseSensitive() { |
| 5097 String[] patterns = {"a#b", "A#B"}; |
| 5098 String[] inputs = {"a500b", "A500b", "a500B", "a500e10b", "a500E10b"}; |
| 5099 int[][] expectedParsePositions = { |
| 5100 {5, 5, 5, 8, 8}, // case insensitive, pattern 0 |
| 5101 {5, 0, 4, 4, 8}, // case sensitive, pattern 0 |
| 5102 {5, 5, 5, 8, 8}, // case insensitive, pattern 1 |
| 5103 {0, 4, 0, 0, 0}, // case sensitive, pattern 1 |
| 5104 }; |
| 5105 |
| 5106 for (int p = 0; p < patterns.length; p++) { |
| 5107 String pat = patterns[p]; |
| 5108 DecimalFormat df = new DecimalFormat(pat); |
| 5109 assertEquals("parseCaseSensitive default is wrong", false, df.getPar
seCaseSensitive()); |
| 5110 for (int i = 0; i < inputs.length; i++) { |
| 5111 String inp = inputs[i]; |
| 5112 df.setParseCaseSensitive(false); |
| 5113 assertEquals("parseCaseSensitive getter is broken", false, df.ge
tParseCaseSensitive()); |
| 5114 ParsePosition actualInsensitive = new ParsePosition(0); |
| 5115 df.parse(inp, actualInsensitive); |
| 5116 assertEquals("Insensitive, pattern "+p+", input "+i, |
| 5117 expectedParsePositions[p*2][i], actualInsensitive.getInd
ex()); |
| 5118 df.setParseCaseSensitive(true); |
| 5119 assertEquals("parseCaseSensitive getter is broken", true, df.get
ParseCaseSensitive()); |
| 5120 ParsePosition actualSensitive = new ParsePosition(0); |
| 5121 df.parse(inp, actualSensitive); |
| 5122 assertEquals("Sensitive, pattern "+p+", input "+i, |
| 5123 expectedParsePositions[p*2+1][i], actualSensitive.getInd
ex()); |
| 5124 } |
| 5125 } |
| 5126 } |
4921 } | 5127 } |
LEFT | RIGHT |