]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/icu/dev/test/translit/UnicodeMapTest.java
go
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / icu / dev / test / translit / UnicodeMapTest.java
1 //##header J2SE15
2 //#if defined(FOUNDATION10) || defined(J2SE13)
3 //#else
4 /*
5  *******************************************************************************
6  * Copyright (C) 1996-2009, International Business Machines Corporation and    *
7  * others. All Rights Reserved.                                                *
8  *******************************************************************************
9  */
10 package com.ibm.icu.dev.test.translit;
11
12 import com.ibm.icu.dev.test.*;
13 import com.ibm.icu.dev.test.util.UnicodeMap;
14 import com.ibm.icu.impl.Utility;
15 import java.util.*;
16
17 /**
18  * @test
19  * @summary General test of UnicodeSet
20  */
21 public class UnicodeMapTest extends TestFmwk {
22   
23   static final int MODIFY_TEST_LIMIT = 32;
24   static final int MODIFY_TEST_ITERATIONS = 100000;
25   
26   public static void main(String[] args) throws Exception {
27     new UnicodeMapTest().run(args);
28   }
29   
30   public void TestModify() {
31     Random random = new Random(0);
32     UnicodeMap unicodeMap = new UnicodeMap();
33     HashMap hashMap = new HashMap();
34     String[] values = {null, "the", "quick", "brown", "fox"};
35     for (int count = 1; count <= MODIFY_TEST_ITERATIONS; ++count) {
36       String value = values[random.nextInt(values.length)];
37       int start = random.nextInt(MODIFY_TEST_LIMIT); // test limited range
38       int end = random.nextInt(MODIFY_TEST_LIMIT);
39       if (start > end) {
40         int temp = start;
41         start = end;
42         end = temp;
43       }
44       int modCount = count & 0xFF;
45       if (modCount == 0 && isVerbose()) {
46         logln("***"+count);
47         logln(unicodeMap.toString());
48       }
49       unicodeMap.putAll(start, end, value);
50       if (modCount == 1 && isVerbose()) {
51         logln(">>>\t" + Utility.hex(start) + ".." + Utility.hex(end) + "\t" + value);
52         logln(unicodeMap.toString());
53       }
54       for (int i = start; i <= end; ++i) {
55         hashMap.put(new Integer(i), value);
56       }
57       if (!hasSameValues(unicodeMap, hashMap)) {
58         errln("Failed at " + count);
59       }
60     }
61   }
62
63   private boolean hasSameValues(UnicodeMap unicodeMap, HashMap hashMap) {
64     for (int i = 0; i < MODIFY_TEST_LIMIT; ++i) {
65       Object unicodeMapValue = unicodeMap.getValue(i);
66       Object hashMapValue = hashMap.get(new Integer(i));
67       if (unicodeMapValue != hashMapValue) {
68         return false;
69       }
70     }
71     return true;
72   }
73 }
74 //#endif