]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/styledtext/TestFastIntBinarySearch.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / styledtext / TestFastIntBinarySearch.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.styledtext;\r
14 \r
15 final class TestFastIntBinarySearch {\r
16 \r
17     static final String COPYRIGHT =\r
18                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
19     public static void main(String[] args) {\r
20 \r
21         boolean result = new TestFastIntBinarySearch().test();\r
22         System.out.println(result? "PASSED" : "FAILED");\r
23     }\r
24 \r
25     public boolean test() {\r
26 \r
27         boolean result = true;\r
28         int[] test = {-5, -3, 0, 2, 5};\r
29         FastIntBinarySearch fibs = new FastIntBinarySearch(test);\r
30 \r
31         for (int i=0; i < 2; i++) {\r
32             int beforeAny = fibs.findIndex(-6);\r
33             if (beforeAny != -1) {\r
34                 result = false;\r
35             }\r
36             \r
37             int atEnd = fibs.findIndex(5);\r
38             if (atEnd != test.length-1) {\r
39                 result = false;\r
40             }\r
41             \r
42             int afterAny = fibs.findIndex(6);\r
43             if (afterAny != test.length-1) {\r
44                 result = false;\r
45             }\r
46             \r
47             int exactly = fibs.findIndex(-3);\r
48             if (exactly != 1) {\r
49                 result = false;\r
50             }\r
51             \r
52             fibs = new FastIntBinarySearch(new int[] {20, 40});\r
53             fibs.setData(test);\r
54         }\r
55         \r
56         return result;\r
57     }\r
58 }