001: /*
002: (c) Copyright 2002, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestDyadic.java,v 1.12 2008/01/02 12:07:21 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.compose.test;
008:
009: import com.hp.hpl.jena.util.iterator.*;
010: import com.hp.hpl.jena.graph.*;
011: import com.hp.hpl.jena.graph.compose.Dyadic;
012: import com.hp.hpl.jena.graph.test.*;
013:
014: import java.util.*;
015: import junit.framework.*;
016:
017: /**
018: @author kers
019: */
020: public class TestDyadic extends GraphTestBase {
021: public TestDyadic(String name) {
022: super (name);
023: }
024:
025: public static TestSuite suite() {
026: return new TestSuite(TestDyadic.class);
027: }
028:
029: static private ExtendedIterator things(final String x) {
030: return new NiceIterator() {
031: private StringTokenizer tokens = new StringTokenizer(x);
032:
033: public boolean hasNext() {
034: return tokens.hasMoreTokens();
035: }
036:
037: public Object next() {
038: return tokens.nextToken();
039: }
040: };
041: }
042:
043: public void testDyadic() {
044: ExtendedIterator it1 = things("now is the time");
045: ExtendedIterator it2 = things("now is the time");
046: ExtendedIterator mt1 = things("");
047: ExtendedIterator mt2 = things("");
048: assertEquals("mt1.hasNext()", false, mt1.hasNext());
049: assertEquals("mt2.hasNext()", false, mt2.hasNext());
050: assertEquals("andThen(mt1,mt2).hasNext()", false, mt1.andThen(
051: mt2).hasNext());
052: assertEquals("butNot(it1,it2).hasNext()", false, Dyadic.butNot(
053: it1, it2).hasNext());
054: assertEquals("x y z @butNot z", true, Dyadic.butNot(
055: things("x y z"), things("z")).hasNext());
056: assertEquals("x y z @butNot a", true, Dyadic.butNot(
057: things("x y z"), things("z")).hasNext());
058: }
059:
060: public void testDyadicOperands() {
061: Graph g = Factory.createGraphMem(), h = Factory
062: .createGraphMem();
063: Dyadic d = new Dyadic(g, h) {
064: public ExtendedIterator graphBaseFind(TripleMatch m) {
065: return null;
066: }
067: };
068: assertSame(g, d.getL());
069: assertSame(h, d.getR());
070: }
071: }
072:
073: /*
074: (c) Copyright 2002, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
075: All rights reserved.
076:
077: Redistribution and use in source and binary forms, with or without
078: modification, are permitted provided that the following conditions
079: are met:
080:
081: 1. Redistributions of source code must retain the above copyright
082: notice, this list of conditions and the following disclaimer.
083:
084: 2. Redistributions in binary form must reproduce the above copyright
085: notice, this list of conditions and the following disclaimer in the
086: documentation and/or other materials provided with the distribution.
087:
088: 3. The name of the author may not be used to endorse or promote products
089: derived from this software without specific prior written permission.
090:
091: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
092: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
093: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
094: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
095: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
096: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
097: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
098: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
099: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
100: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101: */
|