OLD | NEW |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 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 package com.ibm.icu.dev.test.number; | 3 package com.ibm.icu.dev.test.number; |
4 | 4 |
5 import static org.junit.Assert.assertEquals; | 5 import static org.junit.Assert.assertEquals; |
6 import static org.junit.Assert.assertNotEquals; | 6 import static org.junit.Assert.assertNotEquals; |
7 import static org.junit.Assert.assertTrue; | 7 import static org.junit.Assert.assertTrue; |
8 | 8 |
9 import java.lang.reflect.InvocationTargetException; | 9 import java.lang.reflect.InvocationTargetException; |
10 import java.lang.reflect.Method; | 10 import java.lang.reflect.Method; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 import com.ibm.icu.util.MeasureUnit; | 44 import com.ibm.icu.util.MeasureUnit; |
45 import com.ibm.icu.util.NoUnit; | 45 import com.ibm.icu.util.NoUnit; |
46 import com.ibm.icu.util.ULocale; | 46 import com.ibm.icu.util.ULocale; |
47 | 47 |
48 public class NumberFormatterApiTest { | 48 public class NumberFormatterApiTest { |
49 | 49 |
50 private static final Currency USD = Currency.getInstance("USD"); | 50 private static final Currency USD = Currency.getInstance("USD"); |
51 private static final Currency GBP = Currency.getInstance("GBP"); | 51 private static final Currency GBP = Currency.getInstance("GBP"); |
52 private static final Currency CZK = Currency.getInstance("CZK"); | 52 private static final Currency CZK = Currency.getInstance("CZK"); |
53 private static final Currency CAD = Currency.getInstance("CAD"); | 53 private static final Currency CAD = Currency.getInstance("CAD"); |
| 54 private static final Currency ESP = Currency.getInstance("ESP"); |
54 | 55 |
55 @Test | 56 @Test |
56 public void notationSimple() { | 57 public void notationSimple() { |
57 assertFormatDescending( | 58 assertFormatDescending( |
58 "Basic", | 59 "Basic", |
59 "", | 60 "", |
60 NumberFormatter.with(), | 61 NumberFormatter.with(), |
61 ULocale.ENGLISH, | 62 ULocale.ENGLISH, |
62 "87,650", | 63 "87,650", |
63 "8,765", | 64 "8,765", |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 5.43, | 642 5.43, |
642 "$5.43"); | 643 "$5.43"); |
643 | 644 |
644 assertFormatSingle( | 645 assertFormatSingle( |
645 "Currency Difference between Narrow and Short (Short Version)", | 646 "Currency Difference between Narrow and Short (Short Version)", |
646 "", | 647 "", |
647 NumberFormatter.with().unit(USD).unitWidth(UnitWidth.SHORT), | 648 NumberFormatter.with().unit(USD).unitWidth(UnitWidth.SHORT), |
648 ULocale.forLanguageTag("en_CA"), | 649 ULocale.forLanguageTag("en_CA"), |
649 5.43, | 650 5.43, |
650 "US$ 5.43"); | 651 "US$ 5.43"); |
| 652 |
| 653 assertFormatSingle( |
| 654 "Currency-dependent format (General Version)", |
| 655 "", |
| 656 NumberFormatter.with().unit(USD).unitWidth(UnitWidth.SHORT), |
| 657 ULocale.forLanguageTag("ca"), |
| 658 444444.55, |
| 659 "444.444,55 USD"); |
| 660 |
| 661 assertFormatSingle( |
| 662 "Currency-dependent format (Custom Format)", |
| 663 "", |
| 664 NumberFormatter.with().unit(ESP).unitWidth(UnitWidth.SHORT), |
| 665 ULocale.forLanguageTag("ca"), |
| 666 444444.55, |
| 667 "₧ 444,444.55"); |
651 } | 668 } |
652 | 669 |
653 @Test | 670 @Test |
654 public void unitPercent() { | 671 public void unitPercent() { |
655 assertFormatDescending( | 672 assertFormatDescending( |
656 "Percent", | 673 "Percent", |
657 "%", | 674 "%", |
658 NumberFormatter.with().unit(NoUnit.PERCENT), | 675 NumberFormatter.with().unit(NoUnit.PERCENT), |
659 ULocale.ENGLISH, | 676 ULocale.ENGLISH, |
660 "87,650%", | 677 "87,650%", |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 ULocale.ENGLISH, | 899 ULocale.ENGLISH, |
883 "88,000.00", // maxSig beats maxFrac | 900 "88,000.00", // maxSig beats maxFrac |
884 "8,800.00", // maxSig beats maxFrac | 901 "8,800.00", // maxSig beats maxFrac |
885 "880.00", // maxSig beats maxFrac | 902 "880.00", // maxSig beats maxFrac |
886 "88.00", // maxSig beats maxFrac | 903 "88.00", // maxSig beats maxFrac |
887 "8.80", // maxSig beats maxFrac | 904 "8.80", // maxSig beats maxFrac |
888 "0.88", | 905 "0.88", |
889 "0.09", | 906 "0.09", |
890 "0.01", | 907 "0.01", |
891 "0.00"); | 908 "0.00"); |
| 909 |
| 910 assertFormatDescending( |
| 911 "FracSig minMaxFrac minMaxSig", |
| 912 "", |
| 913 NumberFormatter.with().rounding(Rounder.fixedFraction(1).withMin
MaxDigits(2, 4)), |
| 914 ULocale.ENGLISH, |
| 915 "87,650.0", // maxSig beats maxFrac |
| 916 "8,765.0", // maxSig beats maxFrac |
| 917 "876.5", // maxSig and maxFrac are tied |
| 918 "87.6", // maxFrac beats maxSig |
| 919 "8.8", // maxFrac beats maxSig and tied with minSig |
| 920 "0.88", // minSig beats maxFrac |
| 921 "0.088", // minSig beats maxFrac |
| 922 "0.0088", // minSig beats maxFrac |
| 923 "0.0"); |
| 924 |
| 925 assertFormatSingle( |
| 926 "FracSig with trailing zeros A", |
| 927 "", |
| 928 NumberFormatter.with().rounding(Rounder.fixedFraction(2).withMin
Digits(3)), |
| 929 ULocale.ENGLISH, |
| 930 0.1, |
| 931 "0.10"); |
| 932 |
| 933 assertFormatSingle( |
| 934 "FracSig with trailing zeros B", |
| 935 "", |
| 936 NumberFormatter.with().rounding(Rounder.fixedFraction(2).withMin
Digits(3)), |
| 937 ULocale.ENGLISH, |
| 938 0.0999999, |
| 939 "0.10"); |
| 940 |
| 941 assertFormatSingle( |
| 942 "FracSig with trailing zeros C", |
| 943 "", |
| 944 NumberFormatter.with().rounding(Rounder.fixedFraction(2).withMin
MaxDigits(3, 4)), |
| 945 ULocale.ENGLISH, |
| 946 0.0999999, |
| 947 "0.10"); |
| 948 |
| 949 assertFormatSingle( |
| 950 "FracSig with trailing zeros D", |
| 951 "", |
| 952 NumberFormatter.with().rounding(Rounder.fixedFraction(2).withMin
MaxDigits(3, 8)), |
| 953 ULocale.ENGLISH, |
| 954 0.0999999, |
| 955 "0.10"); |
892 } | 956 } |
893 | 957 |
894 @Test | 958 @Test |
895 public void roundingOther() { | 959 public void roundingOther() { |
896 assertFormatDescending( | 960 assertFormatDescending( |
897 "Rounding None", | 961 "Rounding None", |
898 "Y", | 962 "Y", |
899 NumberFormatter.with().rounding(Rounder.unlimited()), | 963 NumberFormatter.with().rounding(Rounder.unlimited()), |
900 ULocale.ENGLISH, | 964 ULocale.ENGLISH, |
901 "87,650", | 965 "87,650", |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 // TODO: Add a check for skeleton. | 1963 // TODO: Add a check for skeleton. |
1900 // assertEquals(message + ": Skeleton:", skeleton, f.toSkeleton()); | 1964 // assertEquals(message + ": Skeleton:", skeleton, f.toSkeleton()); |
1901 LocalizedNumberFormatter l1 = f.threshold(0L).locale(locale); // no self
-regulation | 1965 LocalizedNumberFormatter l1 = f.threshold(0L).locale(locale); // no self
-regulation |
1902 LocalizedNumberFormatter l2 = f.threshold(1L).locale(locale); // all sel
f-regulation | 1966 LocalizedNumberFormatter l2 = f.threshold(1L).locale(locale); // all sel
f-regulation |
1903 String actual1 = l1.format(input).toString(); | 1967 String actual1 = l1.format(input).toString(); |
1904 assertEquals(message + ": Unsafe Path: " + input, expected, actual1); | 1968 assertEquals(message + ": Unsafe Path: " + input, expected, actual1); |
1905 String actual2 = l2.format(input).toString(); | 1969 String actual2 = l2.format(input).toString(); |
1906 assertEquals(message + ": Safe Path: " + input, expected, actual2); | 1970 assertEquals(message + ": Safe Path: " + input, expected, actual2); |
1907 } | 1971 } |
1908 } | 1972 } |
OLD | NEW |