1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ******************************************************************************* 6 * Copyright (C) 1996-2010, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 package android.icu.dev.test.format; 11 12 import java.util.Locale; 13 14 import org.junit.Test; 15 import org.junit.runner.RunWith; 16 import org.junit.runners.JUnit4; 17 18 import android.icu.dev.test.TestFmwk; 19 import android.icu.text.RuleBasedNumberFormat; 20 import android.icu.testsharding.MainTestShard; 21 22 @MainTestShard 23 @RunWith(JUnit4.class) 24 public class RbnfRoundTripTest extends TestFmwk { 25 /** 26 * Perform an exhaustive round-trip test on the English spellout rules 27 */ 28 @Test 29 public void TestEnglishSpelloutRT() { 30 RuleBasedNumberFormat formatter 31 = new RuleBasedNumberFormat(Locale.US, 32 RuleBasedNumberFormat.SPELLOUT); 33 34 doTest(formatter, -12345678, 12345678); 35 } 36 37 /** 38 * Perform an exhaustive round-trip test on the duration-formatting rules 39 */ 40 @Test 41 public void TestDurationsRT() { 42 RuleBasedNumberFormat formatter 43 = new RuleBasedNumberFormat(Locale.US, 44 RuleBasedNumberFormat.DURATION); 45 46 doTest(formatter, 0, 12345678); 47 } 48 49 /** 50 * Perform an exhaustive round-trip test on the Spanish spellout rules 51 */ 52 @Test 53 public void TestSpanishSpelloutRT() { 54 RuleBasedNumberFormat formatter 55 = new RuleBasedNumberFormat(new Locale("es", "es", 56 ""), RuleBasedNumberFormat.SPELLOUT); 57 58 doTest(formatter, -12345678, 12345678); 59 } 60 61 /** 62 * Perform an exhaustive round-trip test on the French spellout rules 63 */ 64 @Test 65 public void TestFrenchSpelloutRT() { 66 RuleBasedNumberFormat formatter 67 = new RuleBasedNumberFormat(Locale.FRANCE, 68 RuleBasedNumberFormat.SPELLOUT); 69 70 doTest(formatter, -12345678, 12345678); 71 } 72 73 /** 74 * Perform an exhaustive round-trip test on the Swiss French spellout rules 75 */ 76 @Test 77 public void TestSwissFrenchSpelloutRT() { 78 RuleBasedNumberFormat formatter 79 = new RuleBasedNumberFormat(new Locale("fr", "CH", 80 ""), RuleBasedNumberFormat.SPELLOUT); 81 82 doTest(formatter, -12345678, 12345678); 83 } 84 85 /** 86 * Perform an exhaustive round-trip test on the Italian spellout rules 87 */ 88 @Test 89 public void TestItalianSpelloutRT() { 90 RuleBasedNumberFormat formatter 91 = new RuleBasedNumberFormat(Locale.ITALIAN, 92 RuleBasedNumberFormat.SPELLOUT); 93 94 doTest(formatter, -999999, 999999); 95 } 96 97 /** 98 * Perform an exhaustive round-trip test on the German spellout rules 99 */ 100 @Test 101 public void TestGermanSpelloutRT() { 102 RuleBasedNumberFormat formatter 103 = new RuleBasedNumberFormat(Locale.GERMANY, 104 RuleBasedNumberFormat.SPELLOUT); 105 106 doTest(formatter, 0, 12345678); 107 } 108 109 /** 110 * Perform an exhaustive round-trip test on the Swedish spellout rules 111 */ 112 @Test 113 public void TestSwedishSpelloutRT() { 114 RuleBasedNumberFormat formatter 115 = new RuleBasedNumberFormat(new Locale("sv", "SE", 116 ""), RuleBasedNumberFormat.SPELLOUT); 117 118 doTest(formatter, 0, 12345678); 119 } 120 121 /** 122 * Perform an exhaustive round-trip test on the Dutch spellout rules 123 */ 124 @Test 125 public void TestDutchSpelloutRT() { 126 RuleBasedNumberFormat formatter 127 = new RuleBasedNumberFormat(new Locale("nl", "NL", 128 ""), RuleBasedNumberFormat.SPELLOUT); 129 130 doTest(formatter, -12345678, 12345678); 131 } 132 133 /** 134 * Perform an exhaustive round-trip test on the Japanese spellout rules 135 */ 136 @Test 137 public void TestJapaneseSpelloutRT() { 138 RuleBasedNumberFormat formatter 139 = new RuleBasedNumberFormat(Locale.JAPAN, 140 RuleBasedNumberFormat.SPELLOUT); 141 142 doTest(formatter, 0, 12345678); 143 } 144 145 /** 146 * Perform an exhaustive round-trip test on the Russian spellout rules 147 */ 148 @Test 149 public void TestRussianSpelloutRT() { 150 RuleBasedNumberFormat formatter 151 = new RuleBasedNumberFormat(new Locale("ru", "RU", 152 ""), RuleBasedNumberFormat.SPELLOUT); 153 154 doTest(formatter, 0, 12345678); 155 } 156 157 /** 158 * Perform an exhaustive round-trip test on the Greek spellout rules 159 */ 160 @Test 161 public void TestGreekSpelloutRT() { 162 RuleBasedNumberFormat formatter 163 = new RuleBasedNumberFormat(new Locale("el", "GR", 164 ""), RuleBasedNumberFormat.SPELLOUT); 165 166 doTest(formatter, 0, 12345678); 167 } 168 169 /** 170 * Perform an exhaustive round-trip test on the Greek spellout rules 171 */ 172 @Test 173 public void TestHebrewNumberingRT() { 174 RuleBasedNumberFormat formatter 175 = new RuleBasedNumberFormat(new Locale("he", "IL", 176 ""), RuleBasedNumberFormat.NUMBERING_SYSTEM); 177 178 formatter.setDefaultRuleSet("%hebrew"); 179 doTest(formatter, 0, 12345678); 180 } 181 182 void doTest(RuleBasedNumberFormat formatter, long lowLimit, 183 long highLimit) { 184 try { 185 long count = 0; 186 long increment = 1; 187 for (long i = lowLimit; i <= highLimit; i += increment) { 188 if (count % 1000 == 0) 189 logln(Long.toString(i)); 190 191 if (Math.abs(i) < 5000) 192 increment = 1; 193 else if (Math.abs(i) < 500000) 194 increment = 2737; 195 else 196 increment = 267437; 197 198 String text = formatter.format(i); 199 long rt = formatter.parse(text).longValue(); 200 201 if (rt != i) { 202 errln("Round-trip failed: " + i + " -> " + text + 203 " -> " + rt); 204 } 205 206 ++count; 207 } 208 209 if (lowLimit < 0) { 210 double d = 1.234; 211 while (d < 1000) { 212 String text = formatter.format(d); 213 double rt = formatter.parse(text).doubleValue(); 214 215 if (rt != d) { 216 errln("Round-trip failed: " + d + " -> " + text + 217 " -> " + rt); 218 } 219 d *= 10; 220 } 221 } 222 } 223 catch (Throwable e) { 224 errln("Test failed with exception: " + e.toString()); 225 e.printStackTrace(); 226 } 227 } 228 } 229 230