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