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 18 public class TestTripleCache extends GraphTestBase 19 { 20 public TestTripleCache( String name ) 21 { super( name ); } 22 23 public static TestSuite suite() 24 { return new TestSuite( TestTripleCache.class ); } 25 26 protected static Triple [] someTriples = makeTriples(); 27 28 protected static Triple [] makeTriples() 29 { 30 Node [] S = { node( "x" ), node( "gooseberry" ), node( "_who" ) }; 31 Node [] P = { node( "p" ), node( "ramshackle" ), node( "_what" ) }; 32 Node [] O = { node( "o" ), node( "42" ), node( "'alpha'greek" ), node( "_o" ) }; 33 int here = 0; 34 Triple [] result = new Triple[S.length * P.length * O.length]; 35 for (int i = 0; i < S.length; i += 1) 36 for (int j = 0; j < P.length; j += 1) 37 for (int k = 0; k < O.length; k += 1) 38 result[here++] = new Triple( S[i], P[j], O[k] ); 39 return result; 40 } 41 42 public void testEmptyTripleCache() 43 { 44 TripleCache tc = new TripleCache(); 45 for (int i = 0; i < someTriples.length; i += 1) 46 { 47 Triple t = someTriples[i]; 48 assertEquals( null, tc.get( t.getSubject(), t.getPredicate(), t.getObject() ) ); 49 } 50 } 51 52 public void testPutReturnsTriple() 53 { 54 TripleCache tc = new TripleCache(); 55 for (int i = 0; i < someTriples.length; i += 1) 56 assertSame( someTriples[i], tc.put( someTriples[i] ) ); 57 } 58 59 public void testPutinTripleCache() 60 { 61 TripleCache tc = new TripleCache(); 62 for (int i = 0; i < someTriples.length; i += 1) 63 { 64 Triple t = someTriples[i]; 65 tc.put( t ); 66 assertEquals( t, tc.get( t.getSubject(), t.getPredicate(), t.getObject() ) ); 67 } 68 } 69 70 public void testCacheClash() 71 { 72 TripleCache tc = new TripleCache(); 73 Triple A = new Triple( node( "eg:Yx" ), node( "p" ), node( "o" ) ); 74 Triple B = new Triple( node( "eg:ZY" ), node( "p" ), node( "o" ) ); 75 assertEquals( A.hashCode(), B.hashCode() ); 76 tc.put( A ); 77 assertEquals( null, tc.get( B.getSubject(), B.getPredicate(), B.getObject() ) ); 78 } 79 } 80 81 | Popular Tags |