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