KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > tree > KeyTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: KeyTest.java,v 1.15 2006/10/30 21:14:52 bostic Exp $
7  */

8
9 package com.sleepycat.je.tree;
10
11 import junit.framework.TestCase;
12
13 public class KeyTest extends TestCase {
14     public void setUp() {
15     }
16
17     public void tearDown() {
18     }
19
20     public void testKeyComparisonPerformance() {
21     byte[] key1 = "abcdefghijabcdefghij".getBytes();
22     byte[] key2 = "abcdefghijabcdefghij".getBytes();
23
24     for (int i = 0; i < 1000000; i++) {
25         assertTrue(Key.compareKeys(key1, key2, null) == 0);
26     }
27     }
28
29     public void testKeyComparison() {
30     byte[] key1 = "aaa".getBytes();
31     byte[] key2 = "aab".getBytes();
32     assertTrue(Key.compareKeys(key1, key2, null) < 0);
33     assertTrue(Key.compareKeys(key2, key1, null) > 0);
34     assertTrue(Key.compareKeys(key1, key1, null) == 0);
35
36     key1 = "aa".getBytes();
37     key2 = "aab".getBytes();
38     assertTrue(Key.compareKeys(key1, key2, null) < 0);
39     assertTrue(Key.compareKeys(key2, key1, null) > 0);
40
41     key1 = "".getBytes();
42     key2 = "aab".getBytes();
43     assertTrue(Key.compareKeys(key1, key2, null) < 0);
44     assertTrue(Key.compareKeys(key2, key1, null) > 0);
45     assertTrue(Key.compareKeys(key1, key1, null) == 0);
46
47     key1 = "".getBytes();
48     key2 = "".getBytes();
49     assertTrue(Key.compareKeys(key1, key2, null) == 0);
50
51     byte[] ba1 = { -1, -1, -1 };
52     byte[] ba2 = { 0x7f, 0x7f, 0x7f };
53     assertTrue(Key.compareKeys(ba1, ba2, null) > 0);
54
55     try {
56         Key.compareKeys(key1, null, null);
57         fail("NullPointerException not caught");
58     } catch (NullPointerException JavaDoc NPE) {
59     }
60     }
61 }
62
Popular Tags