ICU-2912 icu4j tests should be more reproducible

X-SVN-Rev: 12082
This commit is contained in:
Doug Felt 2003-05-23 17:37:23 +00:00
parent b90239700b
commit f89b98bac7
10 changed files with 111 additions and 34 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/TestFmwk.java,v $
* $Date: 2003/05/16 23:37:01 $
* $Revision: 1.44 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.45 $
*
*****************************************************************************************
*/
@ -62,6 +62,12 @@ public class TestFmwk extends AbstractTestLog {
}
}
// use this instead of new random so we get a consistent seed
// for our tests
protected Random createRandom() {
return new Random(params.seed);
}
/**
* A test that has no test methods itself, but instead runs other tests.
*

View File

@ -50,7 +50,7 @@ public class CollationMonkeyTest extends TestFmwk {
return;
}
Random rand = new Random();
Random rand = createRandom(); // use test framework's random seed
int s = rand.nextInt(0x7fff) % source.length();
int t = rand.nextInt(0x7fff) % source.length();
int slen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
@ -127,7 +127,7 @@ public class CollationMonkeyTest extends TestFmwk {
* the numbers will be different every time we run.
*/
Random rand = new Random();
Random rand = createRandom(); // use test framework's random seed
int s = rand.nextInt(0x7fff) % source.length();
int t = rand.nextInt(0x7fff) % source.length();
int slen = Math.abs(rand.nextInt(0x7fff) % source.length() - source.length()) % source.length();
@ -319,4 +319,4 @@ public class CollationMonkeyTest extends TestFmwk {
target += "]";
return target;
}
}
}

View File

@ -4,8 +4,8 @@
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/DateFormatRoundTripTest.java,v $
* $Date: 2003/05/14 19:03:15 $
* $Revision: 1.4 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.5 $
*
*****************************************************************************************
*/
@ -36,7 +36,7 @@ public class DateFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
private int SPARSENESS = 18;
private int TRIALS = 4;
private int DEPTH = 5;
private Random ran = new Random();
private Random ran;
public static void main(String[] args) throws Exception {
new DateFormatRoundTripTest().run(args);
@ -45,7 +45,8 @@ public class DateFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
public void TestDateFormatRoundTrip() {
dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
getFieldCal = Calendar.getInstance();
ran = createRandom(); // use test framework's random seed
final Locale[] avail = DateFormat.getAvailableLocales();
int locCount = avail.length;
logln("DateFormat available locales: " + locCount);
@ -269,4 +270,4 @@ public class DateFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
a *= 365.25 * 24 * 60 * 60 * 1000;
return new Date((long)a);
}
}
}

View File

@ -1,7 +1,7 @@
/***************************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/IntlTestDateFormat.java,v $
* $Date: 2003/05/14 19:03:15 $
* $Revision: 1.6 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.7 $
*
*****************************************************************************************
*/
@ -48,7 +48,8 @@ public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
private DateFormat fFormat = DateFormat.getInstance();
private String fTestName = new String("getInstance");
private int fLimit = 3; // How many iterations it should take to reach convergence
private Random random; // initialized in randDouble
public IntlTestDateFormat() {
//Constructure
}
@ -202,6 +203,9 @@ public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
// Return a random double from 0.01 to 1, inclusive
private double randDouble() {
if (random == null) {
random = createRandom();
}
// Assume 8-bit (or larger) rand values. Also assume
// that the system rand() function is very poor, which it always is.
// double d;
@ -222,8 +226,7 @@ public class IntlTestDateFormat extends com.ibm.icu.dev.test.TestFmwk {
// else if (e > -1.0) d /= pow(10.0, e+1);
// }
// return d;
Random rand = new Random();
return rand.nextDouble();
return random.nextDouble();
}
public void TestAvailableLocales() {

View File

@ -4,8 +4,8 @@
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/IntlTestNumberFormat.java,v $
* $Date: 2003/05/19 21:08:58 $
* $Revision: 1.5 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.6 $
*
*****************************************************************************************
*/
@ -136,8 +136,9 @@ public class IntlTestNumberFormat extends com.ibm.icu.dev.test.TestFmwk {
tryIt(-100);
tryIt(-1913860352);
Random random = createRandom(); // use test framework's random seed
for (int j = 0; j < 10; j++) {
double d = Math.random()*2e10 - 1e10;
double d = random.nextDouble()*2e10 - 1e10;
tryIt(d);
}

View File

@ -4,8 +4,8 @@
* others. All Rights Reserved. *
*******************************************************************************
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/format/NumberFormatRoundTripTest.java,v $
* $Date: 2003/05/14 19:03:16 $
* $Revision: 1.3 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.4 $
*
*****************************************************************************************
*/
@ -19,6 +19,7 @@ package com.ibm.icu.dev.test.format;
import com.ibm.icu.text.*;
import java.util.Locale;
import java.util.Random;
/**
* Performs round-trip tests for NumberFormat
@ -83,8 +84,12 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
/**
* Return a random value from -range..+range.
*/
private Random random;
public double randomDouble(double range) {
return Math.random() * range;
if (random == null) {
random = createRandom(); // use test framework's random seed
}
return random.nextDouble() * range;
}
public void _test(NumberFormat fmt) {
@ -231,4 +236,4 @@ public class NumberFormatRoundTripTest extends com.ibm.icu.dev.test.TestFmwk {
return Math.abs(error);
}
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/BasicTest.java,v $
* $Date: 2003/05/14 19:03:17 $
* $Revision: 1.29 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.30 $
*
*****************************************************************************************
*/
@ -1486,8 +1486,7 @@ public class BasicTest extends TestFmwk {
/* random checks of long strings */
//srand((unsigned)time( NULL ));
Random rand = new Random();
Random rand = createRandom(); // use test framework's random
for (count = 0; count < 50; count ++)
{

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/normalizer/NormalizationMonkeyTest.java,v $
* $Date: 2003/01/28 18:55:34 $
* $Revision: 1.2 $
* $Date: 2003/05/23 17:37:22 $
* $Revision: 1.3 $
*
*****************************************************************************************
*/
@ -25,14 +25,13 @@ public class NormalizationMonkeyTest extends TestFmwk {
int loopCount = 100;
int maxCharCount = 20;
int maxCodePoint = 0x10ffff;
Random random = null;
Random random = null; // initialized in getTestSource
UnicodeNormalizer unicode_NFD;
UnicodeNormalizer unicode_NFC;
UnicodeNormalizer unicode_NFKD;
UnicodeNormalizer unicode_NFKC;
public NormalizationMonkeyTest() {
random = new Random();
unicode_NFD = new UnicodeNormalizer(UnicodeNormalizer.D, true);
unicode_NFC = new UnicodeNormalizer(UnicodeNormalizer.C, true);
unicode_NFKD = new UnicodeNormalizer(UnicodeNormalizer.KD, true);
@ -86,6 +85,9 @@ public class NormalizationMonkeyTest extends TestFmwk {
}
String getTestSource() {
if (random == null) {
random = createRandom(); // use test framework's random seed
}
String source = "";
int i = 0;
while (i < (random.nextInt(maxCharCount) + 1)) {
@ -99,4 +101,4 @@ public class NormalizationMonkeyTest extends TestFmwk {
}
return source;
}
}
}

View File

@ -48,4 +48,64 @@ public class CurrencyTest extends TestFmwk {
errln("FAIL: getAvailableLocales returned null");
}
}
/**
* Test registration.
*/
public void TestRegistration() {
final Currency jpy = Currency.getInstance("JPY");
final Currency usd = Currency.getInstance(Locale.US);
Locale fu_FU = new Locale("fu", "FU", "");
Object key1 = Currency.registerInstance(jpy, Locale.US);
Object key2 = Currency.registerInstance(jpy, fu_FU);
Currency nus = Currency.getInstance(Locale.US);
if (!nus.equals(jpy)) {
errln("expected " + jpy + " but got: " + nus);
}
// converage, make sure default factory works
Currency nus1 = Currency.getInstance(Locale.JAPAN);
if (!nus1.equals(jpy)) {
errln("expected " + jpy + " but got: " + nus1);
}
Locale[] locales = Currency.getAvailableLocales();
boolean found = false;
for (int i = 0; i < locales.length; ++i) {
if (locales[i].equals(fu_FU)) {
found = true;
break;
}
}
if (!found) {
errln("did not find locale" + fu_FU + " in currency locales");
}
if (!Currency.unregister(key1)) {
errln("unable to unregister currency using key1");
}
if (!Currency.unregister(key2)) {
errln("unable to unregister currency using key2");
}
Currency nus2 = Currency.getInstance(Locale.US);
if (!nus2.equals(usd)) {
errln("expected " + usd + " but got: " + nus2);
}
locales = Currency.getAvailableLocales();
found = false;
for (int i = 0; i < locales.length; ++i) {
if (locales[i].equals(fu_FU)) {
found = true;
break;
}
}
if (found) {
errln("found locale" + fu_FU + " in currency locales after unregister");
}
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/util/ICUServiceThreadTest.java,v $
* $Date: 2003/05/14 19:03:17 $
* $Revision: 1.8 $
* $Date: 2003/05/23 17:37:23 $
* $Revision: 1.9 $
*
*******************************************************************************
*/
@ -89,7 +89,7 @@ public class ICUServiceThreadTest extends TestFmwk
Collator col = Collator.getInstance(locale);
return service.getDisplayNames(locale, col, null);
}
private static final Random r = new Random();
private static final Random r = new Random(); // this is a multi thread test, can't 'unrandomize'
private static String getCLV() {
String c = countries[r.nextInt(countries.length)];