ICU-13088 Added logKnownIssue for skipping percent instance parsing for Persian(fa) locale in ICU4J IntlTestNumberFormat/TestMonster.

X-SVN-Rev: 39974
This commit is contained in:
Yoshito Umaoka 2017-03-31 18:55:11 +00:00
parent a18a97cacf
commit 9c4ef57677

View file

@ -7,7 +7,7 @@
*******************************************************************************
*/
/**
/**
* Port From: ICU4C v1.8.1 : format : IntlTestNumberFormat
* Source File: $ICU4CRoot/source/test/intltest/tsnmfmt.cpp
**/
@ -27,7 +27,7 @@ import com.ibm.icu.text.NumberFormat;
* NumberFormat.
*/
public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
public NumberFormat fNumberFormat;
/**
@ -35,18 +35,20 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
*/
private void _testLocale(Locale locale) {
String localeName = locale + " (" + locale.getDisplayName() + ")";
logln("Number test " + localeName);
fNumberFormat = NumberFormat.getInstance(locale);
_testFormat();
logln("Currency test " + localeName);
fNumberFormat = NumberFormat.getCurrencyInstance(locale);
_testFormat();
logln("Percent test " + localeName);
fNumberFormat = NumberFormat.getPercentInstance(locale);
_testFormat();
if (!locale.getLanguage().equals("fa") && !logKnownIssue("13088", "Negative number with percent cannot be parsed in Persian locale")) {
_testFormat();
}
if (locale.toString().compareTo("en_US_POSIX") != 0 ) {
logln("Scientific test " + localeName);
@ -54,7 +56,7 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
_testFormat();
}
}
/**
* call _testFormat for currency, percent and plain number instances
*/
@ -62,52 +64,52 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
public void TestLocale() {
Locale locale = Locale.getDefault();
String localeName = locale + " (" + locale.getDisplayName() + ")";
logln("Number test " + localeName);
fNumberFormat = NumberFormat.getInstance(locale);
_testFormat();
logln("Currency test " + localeName);
fNumberFormat = NumberFormat.getCurrencyInstance(locale);
_testFormat();
logln("Percent test " + localeName);
fNumberFormat = NumberFormat.getPercentInstance(locale);
_testFormat();
}
/**
* call tryIt with many variations, called by testLocale
*/
private void _testFormat() {
if (fNumberFormat == null){
errln("**** FAIL: Null format returned by createXxxInstance.");
return;
}
DecimalFormat s = (DecimalFormat)fNumberFormat;
logln("pattern :" + s.toPattern());
tryIt(-2.02147304840132e-68);
tryIt(3.88057859588817e-68);
tryIt(3.88057859588817e-68);
tryIt(-2.64651110485945e+65);
tryIt(9.29526819488338e+64);
tryIt(-2.02147304840132e-100);
tryIt(3.88057859588817e-096);
tryIt(3.88057859588817e-096);
tryIt(-2.64651110485945e+306);
tryIt(9.29526819488338e+250);
tryIt(9.29526819488338e+250);
tryIt(-9.18228054496402e+64);
tryIt(-9.69413034454191e+64);
tryIt(-9.18228054496402e+255);
tryIt(-9.69413034454191e+273);
tryIt(1.234e-200);
tryIt(-2.3e-168);
tryIt(Double.NaN);
tryIt(Double.POSITIVE_INFINITY);
tryIt(Double.NEGATIVE_INFINITY);
@ -125,14 +127,14 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
tryIt(Integer.MAX_VALUE);
tryIt((double)Integer.MIN_VALUE);
tryIt((double)Integer.MAX_VALUE);
tryIt((double)Integer.MIN_VALUE - 1.0);
tryIt((double)Integer.MAX_VALUE + 1.0);
tryIt(Integer.MIN_VALUE - 1.0);
tryIt(Integer.MAX_VALUE + 1.0);
tryIt(5.0 / 9.0 * 1e-20);
tryIt(4.0 / 9.0 * 1e-20);
tryIt(5.0 / 9.0 * 1e+20);
tryIt(4.0 / 9.0 * 1e+20);
tryIt(2147483647.);
tryIt(0);
tryIt(0.0);
@ -143,19 +145,19 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
tryIt(-10);
tryIt(-100);
tryIt(-1913860352);
Random random = createRandom(); // use test framework's random seed
for (int j = 0; j < 10; j++) {
double d = random.nextDouble()*2e10 - 1e10;
tryIt(d);
}
}
/**
* Perform tests using aNumber and fNumberFormat, called in many variations
*/
public void tryIt(double aNumber) {
public void tryIt(double aNumber) {
final int DEPTH = 10;
double[] number = new double[DEPTH];
String[] string = new String[DEPTH];
@ -163,7 +165,7 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
int stringMatch = 0;
boolean dump = false;
int i;
for (i = 0; i < DEPTH; i++) {
if (i == 0) {
number[i] = aNumber;
@ -176,7 +178,7 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
break;
}
}
string[i] = fNumberFormat.format(number[i]);
if (i > 0)
{
@ -199,16 +201,16 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
}
if (numberMatch > 0 && stringMatch > 0)
break;
if (i == DEPTH)
--i;
if (stringMatch > 2 || numberMatch > 2)
{
errln("**** FAIL: No string and/or number match within 2 iterations.");
dump = true;
}
if (dump)
{
for (int k=0; k<=i; ++k)
@ -219,13 +221,13 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
}
}
}
/**
* perform tests using aNumber and fNumberFormat, called in many variations
**/
public void tryIt(int aNumber) {
long number;
String stringNum = fNumberFormat.format(aNumber);
try {
number = fNumberFormat.parse(stringNum).longValue();
@ -233,14 +235,14 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
errln("**** FAIL: Parse of " + stringNum + " failed.");
return;
}
if (number != aNumber) {
errln("**** FAIL: Parse of " + stringNum + " failed. Got:" + number
+ " Expected:" + aNumber);
}
}
/**
* test NumberFormat::getAvailableLocales
**/
@ -263,10 +265,10 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
else
errln("**** FAIL: Zero available locales or null array pointer");
}
/**
* call testLocale for all locales
**/
**/
@Test
public void TestMonster() {
final String SEP = "============================================================\n";
@ -295,7 +297,7 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
_testLocale(locales[i]);
}
}
logln(SEP);
}
}