< prev index next >

test/java/text/Format/NumberFormat/Bug4838107.java

Print this page




  54          * Number's value anymore.
  55          */
  56 
  57         test_double();
  58         test_long();
  59         test_BigDecimal();
  60         test_BigInteger();
  61 
  62         Locale.setDefault(defaultLoc);
  63 
  64         if (err) {
  65             throw new RuntimeException("Wrong format with DecimalFormat");
  66         }
  67     }
  68 
  69     static void test_double() {
  70         df = new DecimalFormat();
  71         dfs = df.getDecimalFormatSymbols();
  72 
  73         /* Test with default pattern */
  74         test(new Double(1234),    "1,234");
  75         test(new Double(0.1234),  "0.123");     // rounded
  76         test(new Double(-1234),   "-1,234");
  77         test(new Double(-0.1234), "-0.123");    // rounded
  78 
  79         test(new Double(Double.POSITIVE_INFINITY), "\u221e");
  80         test(new Double(Double.NEGATIVE_INFINITY), "-\u221e");
  81         test(new Double(Double.NaN), "\ufffd"); // without prefix and suffix
  82         test(new Double(0.0),  "0");
  83         test(new Double(-0.0), "-0");   // with the minus sign
  84 
  85         /* Specify a pattern and the minus sign. */
  86         prepareFormatter("<P>#.###E00<S>", 'm');
  87         test(new Double(1234),    "<P>1.234E03<S>");
  88         test(new Double(0.1234),  "<P>1.234Em01<S>");
  89         test(new Double(-1234),   "m<P>1.234E03<S>");
  90         test(new Double(-0.1234), "m<P>1.234Em01<S>");
  91 
  92         prepareFormatter("<P>#.###E00<S>;#.###E00", 'm');
  93         test(new Double(1234),    "<P>1.234E03<S>");
  94         test(new Double(0.1234),  "<P>1.234Em01<S>");
  95         test(new Double(-1234),   "1.234E03");
  96         test(new Double(-0.1234), "1.234Em01");
  97 
  98         prepareFormatter("#.###E00;<P>#.###E00<S>", 'm');
  99         test(new Double(1234),    "1.234E03");
 100         test(new Double(0.1234),  "1.234Em01");
 101         test(new Double(-1234),   "<P>1.234E03<S>");
 102         test(new Double(-0.1234), "<P>1.234Em01<S>");
 103 
 104         prepareFormatter("<P>#.###E00<S>;<p>-#.###E00<s>", 'm');
 105         test(new Double(1234),    "<P>1.234E03<S>");
 106         test(new Double(0.1234),  "<P>1.234Em01<S>");
 107         test(new Double(-1234),   "<p>m1.234E03<s>");
 108         test(new Double(-0.1234), "<p>m1.234Em01<s>");
 109 
 110         test(new Double(Double.POSITIVE_INFINITY), "<P>\u221e<S>");
 111         test(new Double(Double.NEGATIVE_INFINITY), "<p>m\u221e<s>");
 112         test(new Double(Double.NaN), "\ufffd"); // without prefix and suffix
 113         test(new Double(0.0),  "<P>0E00<S>");
 114         test(new Double(-0.0), "<p>m0E00<s>");  // with the minus sign
 115     }
 116 
 117     static void test_BigDecimal() {
 118         df = new DecimalFormat();
 119         dfs = df.getDecimalFormatSymbols();
 120 
 121         /* Test with default pattern */
 122         test(new BigDecimal("123456789012345678901234567890"),
 123              "123,456,789,012,345,678,901,234,567,890");
 124         test(new BigDecimal("0.000000000123456789012345678901234567890"),
 125              "0");
 126         test(new BigDecimal("-123456789012345678901234567890"),
 127              "-123,456,789,012,345,678,901,234,567,890");
 128         test(new BigDecimal("-0.000000000123456789012345678901234567890"),
 129               "-0");
 130 
 131         test(new BigDecimal("0"), "0");
 132         test(new BigDecimal("-0"), "0");
 133 
 134         /* Specify a pattern and the minus sign. */
 135         prepareFormatter("<P>#.####################E00<S>;<p>-#.####################E00<s>", 'm');
 136         test(new BigDecimal("123456789012345678901234567890"),
 137              "<P>1.23456789012345678901E29<S>");
 138         test(new BigDecimal("0.000000000123456789012345678901234567890"),
 139              "<P>1.23456789012345678901Em10<S>");
 140         test(new BigDecimal("-123456789012345678901234567890"),
 141              "<p>m1.23456789012345678901E29<s>");
 142         test(new BigDecimal("-0.000000000123456789012345678901234567890"),
 143               "<p>m1.23456789012345678901Em10<s>");
 144 
 145         test(new BigDecimal("0"), "<P>0E00<S>");
 146         test(new BigDecimal("-0"), "<P>0E00<S>");
 147     }
 148 
 149     static void test_long() {
 150         df = new DecimalFormat();
 151         dfs = df.getDecimalFormatSymbols();
 152 
 153         /* Test with default pattern */
 154         test(new Long(123456789),  "123,456,789");
 155         test(new Long(-123456789), "-123,456,789");
 156 
 157         test(new Long(0), "0");
 158         test(new Long(-0), "0");
 159 
 160         /* Specify a pattern and the minus sign. */
 161         prepareFormatter("<P>#,###<S>;<p>-#,###<s>", 'm');
 162         test(new Long(123456789),  "<P>123,456,789<S>");
 163         test(new Long(-123456789), "<p>m123,456,789<s>");
 164 
 165         test(new Long(0), "<P>0<S>");
 166         test(new Long(-0), "<P>0<S>");
 167     }
 168 
 169     static void test_BigInteger() {
 170         df = new DecimalFormat();
 171         dfs = df.getDecimalFormatSymbols();
 172 
 173         /* Test with default pattern */
 174         test(new BigInteger("123456789012345678901234567890"),
 175              "123,456,789,012,345,678,901,234,567,890");
 176         test(new BigInteger("-123456789012345678901234567890"),
 177              "-123,456,789,012,345,678,901,234,567,890");
 178 
 179         test(new BigInteger("0"), "0");
 180         test(new BigInteger("-0"), "0");
 181 
 182         /* Specify a pattern and the minus sign. */
 183         prepareFormatter("<P>#,###<S>;<p>-#,###<s>", 'm');
 184         test(new BigInteger("123456789012345678901234567890"),
 185              "<P>123,456,789,012,345,678,901,234,567,890<S>");
 186         test(new BigInteger("-123456789012345678901234567890"),




  54          * Number's value anymore.
  55          */
  56 
  57         test_double();
  58         test_long();
  59         test_BigDecimal();
  60         test_BigInteger();
  61 
  62         Locale.setDefault(defaultLoc);
  63 
  64         if (err) {
  65             throw new RuntimeException("Wrong format with DecimalFormat");
  66         }
  67     }
  68 
  69     static void test_double() {
  70         df = new DecimalFormat();
  71         dfs = df.getDecimalFormatSymbols();
  72 
  73         /* Test with default pattern */
  74         test(1234D,    "1,234");
  75         test(0.1234,  "0.123");     // rounded
  76         test(-1234D,   "-1,234");
  77         test(-0.1234, "-0.123");    // rounded
  78 
  79         test(Double.POSITIVE_INFINITY, "\u221e");
  80         test(Double.NEGATIVE_INFINITY, "-\u221e");
  81         test(Double.NaN, "\ufffd"); // without prefix and suffix
  82         test(0.0,  "0");
  83         test(-0.0, "-0");   // with the minus sign
  84 
  85         /* Specify a pattern and the minus sign. */
  86         prepareFormatter("<P>#.###E00<S>", 'm');
  87         test(1234D,    "<P>1.234E03<S>");
  88         test(0.1234,  "<P>1.234Em01<S>");
  89         test(-1234D,   "m<P>1.234E03<S>");
  90         test(-0.1234, "m<P>1.234Em01<S>");
  91 
  92         prepareFormatter("<P>#.###E00<S>;#.###E00", 'm');
  93         test(1234D,    "<P>1.234E03<S>");
  94         test(0.1234,  "<P>1.234Em01<S>");
  95         test(-1234D,   "1.234E03");
  96         test(-0.1234, "1.234Em01");
  97 
  98         prepareFormatter("#.###E00;<P>#.###E00<S>", 'm');
  99         test(1234D,    "1.234E03");
 100         test(0.1234,  "1.234Em01");
 101         test(-1234D,   "<P>1.234E03<S>");
 102         test(-0.1234, "<P>1.234Em01<S>");
 103 
 104         prepareFormatter("<P>#.###E00<S>;<p>-#.###E00<s>", 'm');
 105         test(1234D,    "<P>1.234E03<S>");
 106         test(0.1234,  "<P>1.234Em01<S>");
 107         test(-1234D,   "<p>m1.234E03<s>");
 108         test(-0.1234, "<p>m1.234Em01<s>");
 109 
 110         test(Double.POSITIVE_INFINITY, "<P>\u221e<S>");
 111         test(Double.NEGATIVE_INFINITY, "<p>m\u221e<s>");
 112         test(Double.NaN, "\ufffd"); // without prefix and suffix
 113         test(0.0,  "<P>0E00<S>");
 114         test(-0.0, "<p>m0E00<s>");  // with the minus sign
 115     }
 116 
 117     static void test_BigDecimal() {
 118         df = new DecimalFormat();
 119         dfs = df.getDecimalFormatSymbols();
 120 
 121         /* Test with default pattern */
 122         test(new BigDecimal("123456789012345678901234567890"),
 123              "123,456,789,012,345,678,901,234,567,890");
 124         test(new BigDecimal("0.000000000123456789012345678901234567890"),
 125              "0");
 126         test(new BigDecimal("-123456789012345678901234567890"),
 127              "-123,456,789,012,345,678,901,234,567,890");
 128         test(new BigDecimal("-0.000000000123456789012345678901234567890"),
 129               "-0");
 130 
 131         test(new BigDecimal("0"), "0");
 132         test(new BigDecimal("-0"), "0");
 133 
 134         /* Specify a pattern and the minus sign. */
 135         prepareFormatter("<P>#.####################E00<S>;<p>-#.####################E00<s>", 'm');
 136         test(new BigDecimal("123456789012345678901234567890"),
 137              "<P>1.23456789012345678901E29<S>");
 138         test(new BigDecimal("0.000000000123456789012345678901234567890"),
 139              "<P>1.23456789012345678901Em10<S>");
 140         test(new BigDecimal("-123456789012345678901234567890"),
 141              "<p>m1.23456789012345678901E29<s>");
 142         test(new BigDecimal("-0.000000000123456789012345678901234567890"),
 143               "<p>m1.23456789012345678901Em10<s>");
 144 
 145         test(new BigDecimal("0"), "<P>0E00<S>");
 146         test(new BigDecimal("-0"), "<P>0E00<S>");
 147     }
 148 
 149     static void test_long() {
 150         df = new DecimalFormat();
 151         dfs = df.getDecimalFormatSymbols();
 152 
 153         /* Test with default pattern */
 154         test(123456789L,  "123,456,789");
 155         test(-123456789L, "-123,456,789");
 156 
 157         test(0L, "0");
 158         test(-0L, "0");
 159 
 160         /* Specify a pattern and the minus sign. */
 161         prepareFormatter("<P>#,###<S>;<p>-#,###<s>", 'm');
 162         test(123456789L,  "<P>123,456,789<S>");
 163         test(-123456789L, "<p>m123,456,789<s>");
 164 
 165         test(0L, "<P>0<S>");
 166         test(-0L, "<P>0<S>");
 167     }
 168 
 169     static void test_BigInteger() {
 170         df = new DecimalFormat();
 171         dfs = df.getDecimalFormatSymbols();
 172 
 173         /* Test with default pattern */
 174         test(new BigInteger("123456789012345678901234567890"),
 175              "123,456,789,012,345,678,901,234,567,890");
 176         test(new BigInteger("-123456789012345678901234567890"),
 177              "-123,456,789,012,345,678,901,234,567,890");
 178 
 179         test(new BigInteger("0"), "0");
 180         test(new BigInteger("-0"), "0");
 181 
 182         /* Specify a pattern and the minus sign. */
 183         prepareFormatter("<P>#,###<S>;<p>-#,###<s>", 'm');
 184         test(new BigInteger("123456789012345678901234567890"),
 185              "<P>123,456,789,012,345,678,901,234,567,890<S>");
 186         test(new BigInteger("-123456789012345678901234567890"),


< prev index next >