001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestTripleCache.java,v 1.5 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.test;
008:
009: import junit.framework.*;
010:
011: import com.hp.hpl.jena.graph.*;
012:
013: /**
014: TestTripleCache
015:
016: @author kers
017: */
018: public class TestTripleCache extends GraphTestBase {
019: public TestTripleCache(String name) {
020: super (name);
021: }
022:
023: public static TestSuite suite() {
024: return new TestSuite(TestTripleCache.class);
025: }
026:
027: protected static Triple[] someTriples = makeTriples();
028:
029: protected static Triple[] makeTriples() {
030: Node[] S = { node("x"), node("gooseberry"), node("_who") };
031: Node[] P = { node("p"), node("ramshackle"), node("_what") };
032: Node[] O = { node("o"), node("42"), node("'alpha'greek"),
033: node("_o") };
034: int here = 0;
035: Triple[] result = new Triple[S.length * P.length * O.length];
036: for (int i = 0; i < S.length; i += 1)
037: for (int j = 0; j < P.length; j += 1)
038: for (int k = 0; k < O.length; k += 1)
039: result[here++] = new Triple(S[i], P[j], O[k]);
040: return result;
041: }
042:
043: public void testEmptyTripleCache() {
044: TripleCache tc = new TripleCache();
045: for (int i = 0; i < someTriples.length; i += 1) {
046: Triple t = someTriples[i];
047: assertEquals(null, tc.get(t.getSubject(), t.getPredicate(),
048: t.getObject()));
049: }
050: }
051:
052: public void testPutReturnsTriple() {
053: TripleCache tc = new TripleCache();
054: for (int i = 0; i < someTriples.length; i += 1)
055: assertSame(someTriples[i], tc.put(someTriples[i]));
056: }
057:
058: public void testPutinTripleCache() {
059: TripleCache tc = new TripleCache();
060: for (int i = 0; i < someTriples.length; i += 1) {
061: Triple t = someTriples[i];
062: tc.put(t);
063: assertEquals(t, tc.get(t.getSubject(), t.getPredicate(), t
064: .getObject()));
065: }
066: }
067:
068: public void testCacheClash() {
069: TripleCache tc = new TripleCache();
070: Triple A = new Triple(node("eg:Yx"), node("p"), node("o"));
071: Triple B = new Triple(node("eg:ZY"), node("p"), node("o"));
072: assertEquals(A.hashCode(), B.hashCode());
073: tc.put(A);
074: assertEquals(null, tc.get(B.getSubject(), B.getPredicate(), B
075: .getObject()));
076: }
077: }
078:
079: /*
080: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
081: All rights reserved.
082:
083: Redistribution and use in source and binary forms, with or without
084: modification, are permitted provided that the following conditions
085: are met:
086:
087: 1. Redistributions of source code must retain the above copyright
088: notice, this list of conditions and the following disclaimer.
089:
090: 2. Redistributions in binary form must reproduce the above copyright
091: notice, this list of conditions and the following disclaimer in the
092: documentation and/or other materials provided with the distribution.
093:
094: 3. The name of the author may not be used to endorse or promote products
095: derived from this software without specific prior written permission.
096:
097: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
098: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
099: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
100: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
101: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
102: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
103: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
106: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
107: */
|