mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 01:11:02 +00:00
ICU-5520 fix some minor problems, add test
X-SVN-Rev: 20683
This commit is contained in:
parent
5d7deb743d
commit
89d5004e8b
1 changed files with 75 additions and 0 deletions
75
icu4j/src/com/ibm/icu/dev/test/translit/UnicodeMapTest.java
Normal file
75
icu4j/src/com/ibm/icu/dev/test/translit/UnicodeMapTest.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2006, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.translit;
|
||||
import com.ibm.icu.lang.*;
|
||||
import com.ibm.icu.lang.UCharacterEnums.ECharacterCategory;
|
||||
import com.ibm.icu.text.*;
|
||||
import com.ibm.icu.dev.test.*;
|
||||
import com.ibm.icu.dev.test.util.UnicodeMap;
|
||||
import com.ibm.icu.impl.PrettyPrinter;
|
||||
import com.ibm.icu.impl.Utility;
|
||||
import com.ibm.icu.impl.SortedSetRelation;
|
||||
import java.util.*;
|
||||
import java.text.ParsePosition;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary General test of UnicodeSet
|
||||
*/
|
||||
public class UnicodeMapTest extends TestFmwk {
|
||||
|
||||
static final int MODIFY_TEST_LIMIT = 32;
|
||||
static final int MODIFY_TEST_ITERATIONS = 100000;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new UnicodeMapTest().run(args);
|
||||
}
|
||||
|
||||
public void TestModify() {
|
||||
Random random = new Random(0);
|
||||
UnicodeMap unicodeMap = new UnicodeMap();
|
||||
HashMap hashMap = new HashMap();
|
||||
String[] values = {null, "the", "quick", "brown", "fox"};
|
||||
for (int count = 1; count <= MODIFY_TEST_ITERATIONS; ++count) {
|
||||
String value = values[random.nextInt(values.length)];
|
||||
int start = random.nextInt(MODIFY_TEST_LIMIT); // test limited range
|
||||
int end = random.nextInt(MODIFY_TEST_LIMIT);
|
||||
if (start > end) {
|
||||
int temp = start;
|
||||
start = end;
|
||||
end = temp;
|
||||
}
|
||||
int modCount = count & 0xFF;
|
||||
if (modCount == 0 && isVerbose()) {
|
||||
logln("***"+count);
|
||||
logln(unicodeMap.toString());
|
||||
}
|
||||
unicodeMap.putAll(start, end, value);
|
||||
if (modCount == 1 && isVerbose()) {
|
||||
logln(">>>\t" + Utility.hex(start) + ".." + Utility.hex(end) + "\t" + value);
|
||||
logln(unicodeMap.toString());
|
||||
}
|
||||
for (int i = start; i <= end; ++i) {
|
||||
hashMap.put(new Integer(i), value);
|
||||
}
|
||||
if (!hasSameValues(unicodeMap, hashMap)) {
|
||||
errln("Failed at " + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) {
|
||||
for (int i = 0; i < MODIFY_TEST_LIMIT; ++i) {
|
||||
Object unicodeMapValue = unicodeMap.getValue(i);
|
||||
Object hashMapValue = hashMap.get(new Integer(i));
|
||||
if (unicodeMapValue != hashMapValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue