001: /*
002: * Copyright 2006 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016:
017: package com.google.gwt.i18n.client;
018:
019: import com.google.gwt.junit.client.GWTTestCase;
020:
021: /**
022: * GWT JUnit tests must extend GWTTestCase.
023: */
024: public class NumberParse_en_Test extends GWTTestCase {
025:
026: /**
027: * Must refer to a valid module that inherits from com.google.gwt.junit.JUnit.
028: */
029: public String getModuleName() {
030: return "com.google.gwt.i18n.I18NTest_en";
031: }
032:
033: private static Number numberParse(String pattern, String toParse) {
034: NumberFormat fmt = NumberFormat.getFormat(pattern);
035: return new Double(fmt.parse(toParse));
036: }
037:
038: public void testBasicParse() {
039: Number value;
040:
041: value = numberParse("0.0000", "123.4579");
042: assertTrue(value.doubleValue() == 123.4579);
043:
044: value = numberParse("0.0000", "+123.4579");
045: assertTrue(value.doubleValue() == 123.4579);
046:
047: value = numberParse("0.0000", "-123.4579");
048: assertTrue(value.doubleValue() == -123.4579);
049: }
050:
051: public void testExponentParse() {
052: Number value;
053:
054: value = numberParse("#E0", "1.234E3");
055: assertTrue(value.doubleValue() == 1.234E+3);
056:
057: value = numberParse("0.###E0", "1.234E3");
058: assertTrue(value.doubleValue() == 1.234E+3);
059:
060: value = numberParse("#E0", "1.2345E4");
061: assertTrue(value.doubleValue() == 12345.0);
062:
063: value = numberParse("0E0", "1.2345E4");
064: assertTrue(value.doubleValue() == 12345.0);
065:
066: value = numberParse("0E0", "1.2345E+4");
067: assertTrue(value.doubleValue() == 12345.0);
068: }
069:
070: public void testGroupingParse() {
071: Number value;
072:
073: value = numberParse("#,###", "1,234,567,890");
074: assertTrue(value.doubleValue() == 1234567890);
075: value = numberParse("#,####", "12,3456,7890");
076: assertTrue(value.doubleValue() == 1234567890);
077:
078: value = numberParse("#", "1234567890");
079: assertTrue(value.doubleValue() == 1234567890);
080: }
081:
082: public void testInfinityParse() {
083: Number value;
084:
085: // gwt need to add those symbols first
086: value = numberParse("0.0;(0.0)", "\u221E");
087: assertTrue(value.doubleValue() == Double.POSITIVE_INFINITY);
088:
089: value = numberParse("0.0;(0.0)", "(\u221E)");
090: assertTrue(value.doubleValue() == Double.NEGATIVE_INFINITY);
091: }
092:
093: public void testNaNParse() {
094: Number value;
095:
096: // gwt need to add those symbols first
097: value = numberParse("0.0;(0.0)", "NaN");
098: assertTrue(Double.isNaN(value.doubleValue()));
099: }
100:
101: public void testPrecentParse() {
102: Number value;
103:
104: value = numberParse("0.0;(0.0)", "123.4579%");
105: assertTrue(value.doubleValue() == (123.4579 / 100));
106:
107: value = numberParse("0.0;(0.0)", "(%123.4579)");
108: assertTrue(value.doubleValue() == (-123.4579 / 100));
109:
110: value = numberParse("0.0;(0.0)", "123.4579\u2030");
111: assertTrue(value.doubleValue() == (123.4579 / 1000));
112:
113: value = numberParse("0.0;(0.0)", "(\u2030123.4579)");
114: assertTrue(value.doubleValue() == (-123.4579 / 1000));
115: }
116:
117: public void testPrefixParse() {
118: Number value;
119:
120: value = numberParse("0.0;(0.0)", "123.4579");
121: assertTrue(value.doubleValue() == 123.4579);
122:
123: value = numberParse("0.0;(0.0)", "(123.4579)");
124: assertTrue(value.doubleValue() == -123.4579);
125: }
126: }
|