2 //#if defined(FOUNDATION10) || defined(J2SE13)
\r
5 *******************************************************************************
\r
6 * Copyright (C) 1996-2009, International Business Machines Corporation and *
\r
7 * others. All Rights Reserved. *
\r
8 *******************************************************************************
\r
10 package com.ibm.icu.dev.test.translit;
\r
12 import com.ibm.icu.dev.test.*;
\r
13 import com.ibm.icu.dev.test.util.UnicodeMap;
\r
14 import com.ibm.icu.impl.Utility;
\r
19 * @summary General test of UnicodeSet
\r
21 public class UnicodeMapTest extends TestFmwk {
\r
23 static final int MODIFY_TEST_LIMIT = 32;
\r
24 static final int MODIFY_TEST_ITERATIONS = 100000;
\r
26 public static void main(String[] args) throws Exception {
\r
27 new UnicodeMapTest().run(args);
\r
30 public void TestModify() {
\r
31 Random random = new Random(0);
\r
32 UnicodeMap unicodeMap = new UnicodeMap();
\r
33 HashMap hashMap = new HashMap();
\r
34 String[] values = {null, "the", "quick", "brown", "fox"};
\r
35 for (int count = 1; count <= MODIFY_TEST_ITERATIONS; ++count) {
\r
36 String value = values[random.nextInt(values.length)];
\r
37 int start = random.nextInt(MODIFY_TEST_LIMIT); // test limited range
\r
38 int end = random.nextInt(MODIFY_TEST_LIMIT);
\r
44 int modCount = count & 0xFF;
\r
45 if (modCount == 0 && isVerbose()) {
\r
47 logln(unicodeMap.toString());
\r
49 unicodeMap.putAll(start, end, value);
\r
50 if (modCount == 1 && isVerbose()) {
\r
51 logln(">>>\t" + Utility.hex(start) + ".." + Utility.hex(end) + "\t" + value);
\r
52 logln(unicodeMap.toString());
\r
54 for (int i = start; i <= end; ++i) {
\r
55 hashMap.put(new Integer(i), value);
\r
57 if (!hasSameValues(unicodeMap, hashMap)) {
\r
58 errln("Failed at " + count);
\r
63 private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) {
\r
64 for (int i = 0; i < MODIFY_TEST_LIMIT; ++i) {
\r
65 Object unicodeMapValue = unicodeMap.getValue(i);
\r
66 Object hashMapValue = hashMap.get(new Integer(i));
\r
67 if (unicodeMapValue != hashMapValue) {
\r