]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/translit/UnicodeMapTest.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / translit / UnicodeMapTest.java
1 //##header\r
2 //#if defined(FOUNDATION10) || defined(J2SE13)\r
3 //#else\r
4 /*\r
5  *******************************************************************************\r
6  * Copyright (C) 1996-2009, International Business Machines Corporation and    *\r
7  * others. All Rights Reserved.                                                *\r
8  *******************************************************************************\r
9  */\r
10 package com.ibm.icu.dev.test.translit;\r
11 \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
15 import java.util.*;\r
16 \r
17 /**\r
18  * @test\r
19  * @summary General test of UnicodeSet\r
20  */\r
21 public class UnicodeMapTest extends TestFmwk {\r
22   \r
23   static final int MODIFY_TEST_LIMIT = 32;\r
24   static final int MODIFY_TEST_ITERATIONS = 100000;\r
25   \r
26   public static void main(String[] args) throws Exception {\r
27     new UnicodeMapTest().run(args);\r
28   }\r
29   \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
39       if (start > end) {\r
40         int temp = start;\r
41         start = end;\r
42         end = temp;\r
43       }\r
44       int modCount = count & 0xFF;\r
45       if (modCount == 0 && isVerbose()) {\r
46         logln("***"+count);\r
47         logln(unicodeMap.toString());\r
48       }\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
53       }\r
54       for (int i = start; i <= end; ++i) {\r
55         hashMap.put(new Integer(i), value);\r
56       }\r
57       if (!hasSameValues(unicodeMap, hashMap)) {\r
58         errln("Failed at " + count);\r
59       }\r
60     }\r
61   }\r
62 \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
68         return false;\r
69       }\r
70     }\r
71     return true;\r
72   }\r
73 }\r
74 //#endif\r