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_fr_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_fr";
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:
040: Number value;
041:
042: value = numberParse("0.0000", "123,4579");
043: assertTrue(value.doubleValue() == 123.4579);
044:
045: value = numberParse("0.0000", "+123,4579");
046: assertTrue(value.doubleValue() == 123.4579);
047:
048: value = numberParse("0.0000", "-123,4579");
049: assertTrue(value.doubleValue() == -123.4579);
050: }
051:
052: public void testExponentParse() {
053:
054: Number value;
055:
056: value = numberParse("#E0", "1,234E3");
057: assertTrue(value.doubleValue() == 1.234E+3);
058:
059: value = numberParse("0.###E0", "1,234E3");
060: assertTrue(value.doubleValue() == 1.234E+3);
061:
062: value = numberParse("#E0", "1,2345E4");
063: assertTrue(value.doubleValue() == 12345.0);
064:
065: value = numberParse("0E0", "1,2345E4");
066: assertTrue(value.doubleValue() == 12345.0);
067:
068: value = numberParse("0E0", "1,2345E+4");
069: assertTrue(value.doubleValue() == 12345.0);
070: }
071:
072: public void testGroupingParse() {
073:
074: Number value;
075:
076: value = numberParse("#,###", "1\u00a0234\u00a0567\u00a0890");
077: assertTrue(value.doubleValue() == 1234567890);
078: value = numberParse("#,####", "12\u00a03456\u00a07890");
079: assertTrue(value.doubleValue() == 1234567890);
080:
081: value = numberParse("#", "1234567890");
082: assertTrue(value.doubleValue() == 1234567890);
083: }
084:
085: public void testInfinityParse() {
086:
087: Number value;
088:
089: value = numberParse("0.0;(0.0)", "\u221E");
090: assertTrue(value.doubleValue() == Double.POSITIVE_INFINITY);
091:
092: value = numberParse("0.0;(0.0)", "(\u221E)");
093: assertTrue(value.doubleValue() == Double.NEGATIVE_INFINITY);
094: }
095:
096: public void testPrecentParse() {
097:
098: Number value;
099:
100: value = numberParse("0.0;(0.0)", "123,4579%");
101: assertTrue(value.doubleValue() == (123.4579 / 100));
102:
103: value = numberParse("0.0;(0.0)", "(%123,4579)");
104: assertTrue(value.doubleValue() == (-123.4579 / 100));
105:
106: value = numberParse("0.0;(0.0)", "123,4579\u2030");
107: assertTrue(value.doubleValue() == (123.4579 / 1000));
108:
109: value = numberParse("0.0;(0.0)", "(\u2030123,4579)");
110: assertTrue(value.doubleValue() == (-123.4579 / 1000));
111: }
112:
113: public void testPrefixParse() {
114:
115: Number value;
116:
117: value = numberParse("0.0;(0.0)", "123,4579");
118: assertTrue(value.doubleValue() == 123.4579);
119:
120: value = numberParse("0.0;(0.0)", "(123,4579)");
121: assertTrue(value.doubleValue() == -123.4579);
122: }
123:
124: }
|