1 6 7 package com.hp.hpl.jena.graph.test; 8 9 import junit.framework.*; 10 11 import com.hp.hpl.jena.graph.*; 12 13 19 public class TestNodeCache extends GraphTestBase 20 { 21 public TestNodeCache( String name ) 22 { super( name ); } 23 24 public static TestSuite suite() 25 { return new TestSuite( TestNodeCache.class ); } 26 27 32 public static void main( String [] ignoredArguments ) 33 { 34 String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 35 String [] strings = new String [32000]; 36 for (int i = 0; i < alphabet.length(); i += 1) 37 for (int j = 0; j < alphabet.length(); j += 1) 38 { 39 String s = "" + alphabet.charAt( i ) + alphabet.charAt( j ); 40 if (i == 10 && j == 10) System.err.println( s ); 41 int hash = s.hashCode(); 42 if (strings[hash] == null) strings[hash] = s; 43 else System.out.println( ">> " + strings[hash] + " and " + s + " both hash to " + hash ); 44 } 45 } 46 47 50 public void testClashettes() 51 { 52 assertEquals( "eg:aa".hashCode(), "eg:bB".hashCode() ); 53 assertEquals( "eg:ab".hashCode(), "eg:bC".hashCode() ); 54 assertEquals( "eg:ac".hashCode(), "eg:bD".hashCode() ); 55 assertEquals( "eg:Yv".hashCode(), "eg:ZW".hashCode() ); 56 assertEquals( "eg:Yx".hashCode(), "eg:ZY".hashCode() ); 57 } 58 59 62 protected static String [] someURIs = inventURIs(); 63 64 protected static String [] inventURIs() 65 { 66 String [] a = { "a", "mig", "spoo-", "gilbert", "124c41+" }; 67 String [] b = { "b", "class", "procedure", "spindizzy", "rake" }; 68 String [] c = { "c", "bucket", "42", "+1", "#mark" }; 69 int here = 0; 70 String [] result = new String [a.length * b.length * c.length]; 71 for (int i = 0; i < a.length; i += 1) 72 for (int j = 0; j < b.length; j += 1) 73 for (int k = 0; k < c.length; k += 1) 74 result[here++] = "eg:" + a[i] + b[j] + c[k]; 75 return result; 76 } 77 78 81 public void testNewCacheEmpty() 82 { 83 NodeCache c = new NodeCache(); 84 for (int i = 0; i < someURIs.length; i += 1) assertEquals( null, c.get( someURIs[i] ) ); 85 } 86 87 90 public void testNewCacheUpdates() 91 { 92 NodeCache c = new NodeCache(); 93 for (int i = 0; i < someURIs.length; i += 1) 94 { 95 Node it = Node.createURI( someURIs[i] ); 96 c.put( someURIs[i], it ); 97 assertEquals( it, c.get( someURIs[i] ) ); 98 } 99 } 100 101 104 public void testClashing() 105 { 106 String A = "eg:aa", B = "eg:bB"; 107 assertEquals( A.hashCode(), B.hashCode() ); 108 109 NodeCache c = new NodeCache(); 110 c.put( A, Node.createURI( A ) ); 111 assertEquals( null, c.get( B ) ); 112 c.put( B, Node.createURI( B ) ); 113 assertEquals( Node.createURI( B ), c.get( B ) ); 114 } 115 116 } 117 118 | Popular Tags |