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 NumberFormat_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: /**
034: * Add as many tests as you like.
035: */
036: public void testBasicFormat() {
037: String str = NumberFormat.getFormat("0.0000").format(
038: 123.45789179565757f);
039: assertTrue(str.equals("123,4579"));
040: }
041:
042: public void testCurrency() {
043: String str;
044:
045: str = NumberFormat.getFormat("\u00a4#,##0.00;-\u00a4#,##0.00")
046: .format(1234.56);
047: assertTrue(str.equals("\u20AC1\u00A0234,56"));
048: str = NumberFormat.getFormat("\u00a4#,##0.00;-\u00a4#,##0.00")
049: .format(-1234.56);
050: assertTrue(str.equals("-\u20AC1\u00A0234,56"));
051:
052: str = NumberFormat.getFormat(
053: "\u00a4\u00a4 #,##0.00;-\u00a4\u00a4 #,##0.00").format(
054: 1234.56);
055: assertTrue(str.equals("EUR 1\u00A0234,56"));
056: str = NumberFormat.getFormat(
057: "\u00a4\u00a4 #,##0.00;\u00a4\u00a4 -#,##0.00").format(
058: -1234.56);
059: assertTrue(str.equals("EUR -1\u00A0234,56"));
060:
061: NumberFormat formatter = NumberFormat.getFormat(
062: "\u00a4#,##0.00;-\u00a4#,##0.00", "BRL");
063: str = formatter.format(1234.56);
064: assertTrue(str.equals("R$1\u00A0234,56"));
065: str = formatter.format(-1234.56);
066: assertTrue(str.equals("-R$1\u00A0234,56"));
067:
068: formatter = NumberFormat.getFormat(
069: "\u00a4\u00a4 #,##0.00;(\u00a4\u00a4 #,##0.00)", "BRL");
070: str = formatter.format(1234.56);
071: assertTrue(str.equals("BRL 1\u00A0234,56"));
072: str = formatter.format(-1234.56);
073: assertTrue(str.equals("(BRL 1\u00A0234,56)"));
074: }
075:
076: public void testExponential() {
077: String str;
078:
079: str = NumberFormat.getFormat("0.####E0").format(0.01234);
080: assertTrue(str.equals("1,234E-2"));
081: str = NumberFormat.getFormat("00.000E00").format(0.01234);
082: assertTrue(str.equals("12,340E-03"));
083: str = NumberFormat.getFormat("##0.######E000").format(0.01234);
084: assertTrue(str.equals("12,34E-003"));
085: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(
086: 0.01234);
087: assertTrue(str.equals("1,234E-2"));
088:
089: str = NumberFormat.getFormat("0.####E0").format(123456789);
090: assertTrue(str.equals("1,2346E8"));
091: str = NumberFormat.getFormat("00.000E00").format(123456789);
092: assertTrue(str.equals("12,346E07"));
093: str = NumberFormat.getFormat("##0.######E000")
094: .format(123456789);
095: assertTrue(str.equals("123,456789E006"));
096: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(
097: 123456789);
098: assertTrue(str.equals("1,235E8"));
099:
100: str = NumberFormat.getFormat("0.####E0").format(1.23e300);
101: assertTrue(str.equals("1,23E300"));
102: str = NumberFormat.getFormat("00.000E00").format(1.23e300);
103: assertTrue(str.equals("12,300E299"));
104: str = NumberFormat.getFormat("##0.######E000").format(1.23e300);
105: assertTrue(str.equals("1,23E300"));
106: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(
107: 1.23e300);
108: assertTrue(str.equals("1,23E300"));
109:
110: str = NumberFormat.getFormat("0.####E0").format(
111: -3.141592653e-271);
112: assertTrue(str.equals("-3,1416E-271"));
113: str = NumberFormat.getFormat("00.000E00").format(
114: -3.141592653e-271);
115: assertTrue(str.equals("-31,416E-272"));
116: str = NumberFormat.getFormat("##0.######E000").format(
117: -3.141592653e-271);
118: assertTrue(str.equals("-314,159265E-273"));
119: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(
120: -3.141592653e-271);
121: assertTrue(str.equals("[3,142E-271]"));
122:
123: str = NumberFormat.getFormat("0.####E0").format(0);
124: assertTrue(str.equals("0E0"));
125: str = NumberFormat.getFormat("00.000E00").format(0);
126: assertTrue(str.equals("00,000E00"));
127: str = NumberFormat.getFormat("##0.######E000").format(0);
128: assertTrue(str.equals("0E000"));
129: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(0);
130: assertTrue(str.equals("0E0"));
131:
132: str = NumberFormat.getFormat("0.####E0").format(-1);
133: assertTrue(str.equals("-1E0"));
134: str = NumberFormat.getFormat("00.000E00").format(-1);
135: assertTrue(str.equals("-10,000E-01"));
136: str = NumberFormat.getFormat("##0.######E000").format(-1);
137: assertTrue(str.equals("-1E000"));
138: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(-1);
139: assertTrue(str.equals("[1E0]"));
140:
141: str = NumberFormat.getFormat("0.####E0").format(1);
142: assertTrue(str.equals("1E0"));
143: str = NumberFormat.getFormat("00.000E00").format(1);
144: assertTrue(str.equals("10,000E-01"));
145: str = NumberFormat.getFormat("##0.######E000").format(1);
146: assertTrue(str.equals("1E000"));
147: str = NumberFormat.getFormat("0.###E0;[0.###E0]").format(1);
148: assertTrue(str.equals("1E0"));
149:
150: str = NumberFormat.getFormat("#E0").format(12345.0);
151: assertTrue(str.equals("1E4"));
152: str = NumberFormat.getFormat("0E0").format(12345.0);
153: assertTrue(str.equals("1E4"));
154: str = NumberFormat.getFormat("##0.###E0").format(12345.0);
155: assertTrue(str.equals("12,345E3"));
156: str = NumberFormat.getFormat("##0.###E0").format(12345.00001);
157: assertTrue(str.equals("12,345E3"));
158: str = NumberFormat.getFormat("##0.###E0").format(12345);
159: assertTrue(str.equals("12,345E3"));
160:
161: str = NumberFormat.getFormat("##0.####E0").format(789.12345e-9);
162: assertTrue(str.equals("789,1235E-9"));
163: str = NumberFormat.getFormat("##0.####E0").format(780.e-9);
164: assertTrue(str.equals("780E-9"));
165: str = NumberFormat.getFormat(".###E0").format(45678.0);
166: assertTrue(str.equals(",457E5"));
167: str = NumberFormat.getFormat(".###E0").format(0);
168: assertTrue(str.equals(",0E0"));
169:
170: str = NumberFormat.getFormat("#E0").format(45678000);
171: assertTrue(str.equals("5E7"));
172: str = NumberFormat.getFormat("##E0").format(45678000);
173: assertTrue(str.equals("46E6"));
174: str = NumberFormat.getFormat("####E0").format(45678000);
175: assertTrue(str.equals("4568E4"));
176: str = NumberFormat.getFormat("0E0").format(45678000);
177: assertTrue(str.equals("5E7"));
178: str = NumberFormat.getFormat("00E0").format(45678000);
179: assertTrue(str.equals("46E6"));
180: str = NumberFormat.getFormat("000E0").format(45678000);
181: assertTrue(str.equals("457E5"));
182: str = NumberFormat.getFormat("###E0").format(0.0000123);
183: assertTrue(str.equals("12E-6"));
184: str = NumberFormat.getFormat("###E0").format(0.000123);
185: assertTrue(str.equals("123E-6"));
186: str = NumberFormat.getFormat("###E0").format(0.00123);
187: assertTrue(str.equals("1E-3"));
188: str = NumberFormat.getFormat("###E0").format(0.0123);
189: assertTrue(str.equals("12E-3"));
190: str = NumberFormat.getFormat("###E0").format(0.123);
191: assertTrue(str.equals("123E-3"));
192: str = NumberFormat.getFormat("###E0").format(1.23);
193: assertTrue(str.equals("1E0"));
194: str = NumberFormat.getFormat("###E0").format(12.3);
195: assertTrue(str.equals("12E0"));
196: str = NumberFormat.getFormat("###E0").format(123.0);
197: assertTrue(str.equals("123E0"));
198: str = NumberFormat.getFormat("###E0").format(1230.0);
199: assertTrue(str.equals("1E3"));
200: }
201:
202: public void testGrouping() {
203: String str;
204:
205: str = NumberFormat.getFormat("#,###").format(1234567890);
206: assertTrue(str.equals("1\u00a0234\u00a0567\u00a0890"));
207: str = NumberFormat.getFormat("#,####").format(1234567890);
208: assertTrue(str.equals("12\u00a03456\u00a07890"));
209:
210: str = NumberFormat.getFormat("#").format(1234567890);
211: assertTrue(str.equals("1234567890"));
212: }
213:
214: public void testPerMill() {
215: String str;
216:
217: str = NumberFormat.getFormat("###.###\u2030").format(0.4857);
218: assertTrue(str.equals("485,7\u2030"));
219: }
220:
221: public void testQuotes() {
222: String str;
223:
224: str = NumberFormat.getFormat("a'fo''o'b#").format(123);
225: assertTrue(str.equals("afo'ob123"));
226:
227: str = NumberFormat.getFormat("a''b#").format(123);
228: assertTrue(str.equals("a'b123"));
229: }
230:
231: public void testStandardFormat() {
232: String str;
233:
234: str = NumberFormat.getCurrencyFormat().format(1234.579);
235: assertTrue(str.equals("1\u00A0234,58 \u20AC"));
236: str = NumberFormat.getDecimalFormat().format(1234.579);
237: assertTrue(str.equals("1\u00A0234,579"));
238: str = NumberFormat.getPercentFormat().format(1234.579);
239: assertTrue(str.equals("123\u00A0458\u00A0%"));
240: str = NumberFormat.getScientificFormat().format(1234.579);
241: assertTrue(str.equals("1,235E3"));
242: }
243:
244: public void testZeros() {
245: String str;
246:
247: str = NumberFormat.getFormat("#.#").format(0);
248: assertTrue(str.equals("0"));
249: str = NumberFormat.getFormat("#.").format(0);
250: assertTrue(str.equals("0,"));
251: str = NumberFormat.getFormat(".#").format(0);
252: assertTrue(str.equals(",0"));
253: str = NumberFormat.getFormat("#").format(0);
254: assertTrue(str.equals("0"));
255:
256: str = NumberFormat.getFormat("#0.#").format(0);
257: assertTrue(str.equals("0"));
258: str = NumberFormat.getFormat("#0.").format(0);
259: assertTrue(str.equals("0,"));
260: str = NumberFormat.getFormat("#.0").format(0);
261: assertTrue(str.equals(",0"));
262: str = NumberFormat.getFormat("#").format(0);
263: assertTrue(str.equals("0"));
264: }
265: }
|