2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.dev.test.format;
\r
9 import java.util.Locale;
\r
11 import com.ibm.icu.dev.test.TestFmwk;
\r
12 import com.ibm.icu.text.RuleBasedNumberFormat;
\r
14 public class RbnfRoundTripTest extends TestFmwk {
\r
15 public static void main(String[] args) {
\r
16 RbnfRoundTripTest test = new RbnfRoundTripTest();
\r
21 catch (Throwable e) {
\r
22 System.out.println("Entire test failed because of exception: "
\r
24 e.printStackTrace();
\r
29 * Perform an exhaustive round-trip test on the English spellout rules
\r
31 public void TestEnglishSpelloutRT() {
\r
32 RuleBasedNumberFormat formatter
\r
33 = new RuleBasedNumberFormat(Locale.US,
\r
34 RuleBasedNumberFormat.SPELLOUT);
\r
36 doTest(formatter, -12345678, 12345678);
\r
40 * Perform an exhaustive round-trip test on the duration-formatting rules
\r
42 public void TestDurationsRT() {
\r
43 RuleBasedNumberFormat formatter
\r
44 = new RuleBasedNumberFormat(Locale.US,
\r
45 RuleBasedNumberFormat.DURATION);
\r
47 doTest(formatter, 0, 12345678);
\r
51 * Perform an exhaustive round-trip test on the Spanish spellout rules
\r
53 public void TestSpanishSpelloutRT() {
\r
54 RuleBasedNumberFormat formatter
\r
55 = new RuleBasedNumberFormat(new Locale("es", "es",
\r
56 ""), RuleBasedNumberFormat.SPELLOUT);
\r
58 doTest(formatter, -12345678, 12345678);
\r
62 * Perform an exhaustive round-trip test on the French spellout rules
\r
64 public void TestFrenchSpelloutRT() {
\r
65 RuleBasedNumberFormat formatter
\r
66 = new RuleBasedNumberFormat(Locale.FRANCE,
\r
67 RuleBasedNumberFormat.SPELLOUT);
\r
69 doTest(formatter, -12345678, 12345678);
\r
73 * Perform an exhaustive round-trip test on the Swiss French spellout rules
\r
75 public void TestSwissFrenchSpelloutRT() {
\r
76 RuleBasedNumberFormat formatter
\r
77 = new RuleBasedNumberFormat(new Locale("fr", "CH",
\r
78 ""), RuleBasedNumberFormat.SPELLOUT);
\r
80 doTest(formatter, -12345678, 12345678);
\r
84 * Perform an exhaustive round-trip test on the Italian spellout rules
\r
86 public void TestItalianSpelloutRT() {
\r
87 RuleBasedNumberFormat formatter
\r
88 = new RuleBasedNumberFormat(Locale.ITALIAN,
\r
89 RuleBasedNumberFormat.SPELLOUT);
\r
91 doTest(formatter, -999999, 999999);
\r
95 * Perform an exhaustive round-trip test on the German spellout rules
\r
97 public void TestGermanSpelloutRT() {
\r
98 RuleBasedNumberFormat formatter
\r
99 = new RuleBasedNumberFormat(Locale.GERMANY,
\r
100 RuleBasedNumberFormat.SPELLOUT);
\r
102 doTest(formatter, 0, 12345678);
\r
106 * Perform an exhaustive round-trip test on the Swedish spellout rules
\r
108 public void TestSwedishSpelloutRT() {
\r
109 RuleBasedNumberFormat formatter
\r
110 = new RuleBasedNumberFormat(new Locale("sv", "SE",
\r
111 ""), RuleBasedNumberFormat.SPELLOUT);
\r
113 doTest(formatter, 0, 12345678);
\r
117 * Perform an exhaustive round-trip test on the Dutch spellout rules
\r
119 public void TestDutchSpelloutRT() {
\r
120 RuleBasedNumberFormat formatter
\r
121 = new RuleBasedNumberFormat(new Locale("nl", "NL",
\r
122 ""), RuleBasedNumberFormat.SPELLOUT);
\r
124 doTest(formatter, -12345678, 12345678);
\r
128 * Perform an exhaustive round-trip test on the Japanese spellout rules
\r
130 public void TestJapaneseSpelloutRT() {
\r
131 RuleBasedNumberFormat formatter
\r
132 = new RuleBasedNumberFormat(Locale.JAPAN,
\r
133 RuleBasedNumberFormat.SPELLOUT);
\r
135 doTest(formatter, 0, 12345678);
\r
139 * Perform an exhaustive round-trip test on the Russian spellout rules
\r
141 public void TestRussianSpelloutRT() {
\r
142 RuleBasedNumberFormat formatter
\r
143 = new RuleBasedNumberFormat(new Locale("ru", "RU",
\r
144 ""), RuleBasedNumberFormat.SPELLOUT);
\r
146 doTest(formatter, 0, 12345678);
\r
150 * Perform an exhaustive round-trip test on the Greek spellout rules
\r
152 public void TestGreekSpelloutRT() {
\r
153 RuleBasedNumberFormat formatter
\r
154 = new RuleBasedNumberFormat(new Locale("el", "GR",
\r
155 ""), RuleBasedNumberFormat.SPELLOUT);
\r
157 doTest(formatter, 0, 12345678);
\r
161 * Perform an exhaustive round-trip test on the Greek spellout rules
\r
163 public void TestHebrewNumberingRT() {
\r
164 RuleBasedNumberFormat formatter
\r
165 = new RuleBasedNumberFormat(new Locale("he", "IL",
\r
166 ""), RuleBasedNumberFormat.NUMBERING_SYSTEM);
\r
168 formatter.setDefaultRuleSet("%hebrew");
\r
169 doTest(formatter, 0, 12345678);
\r
172 void doTest(RuleBasedNumberFormat formatter, long lowLimit,
\r
176 long increment = 1;
\r
177 for (long i = lowLimit; i <= highLimit; i += increment) {
\r
178 if (count % 1000 == 0)
\r
179 logln(Long.toString(i));
\r
181 if (Math.abs(i) < 5000)
\r
183 else if (Math.abs(i) < 500000)
\r
186 increment = 267437;
\r
188 String text = formatter.format(i);
\r
189 long rt = formatter.parse(text).longValue();
\r
192 errln("Round-trip failed: " + i + " -> " + text +
\r
199 if (lowLimit < 0) {
\r
202 String text = formatter.format(d);
\r
203 double rt = formatter.parse(text).doubleValue();
\r
206 errln("Round-trip failed: " + d + " -> " + text +
\r
213 catch (Throwable e) {
\r
214 errln("Test failed with exception: " + e.toString());
\r
215 e.printStackTrace();
\r