KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > compose > test > TestDyadic


1 /*
2   (c) Copyright 2002, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestDyadic.java,v 1.8 2005/02/21 11:52:07 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.graph.compose.test;
8
9 import com.hp.hpl.jena.util.iterator.*;
10 import com.hp.hpl.jena.graph.*;
11 import com.hp.hpl.jena.graph.compose.Dyadic;
12 import com.hp.hpl.jena.graph.test.*;
13 import com.hp.hpl.jena.mem.GraphMem;
14
15
16 import java.util.*;
17 import junit.framework.*;
18
19 /**
20     @author kers
21 */

22 public class TestDyadic extends GraphTestBase
23     {
24     public TestDyadic( String JavaDoc name )
25         { super( name ); }
26         
27     public static TestSuite suite()
28         { return new TestSuite( TestDyadic.class ); }
29         
30     static private ExtendedIterator things( final String JavaDoc x )
31         {
32         return new NiceIterator()
33             {
34             private StringTokenizer tokens = new StringTokenizer( x );
35             public boolean hasNext() { return tokens.hasMoreTokens(); }
36             public Object JavaDoc next() { return tokens.nextToken(); }
37             };
38         }
39         
40     public void testDyadic()
41         {
42         ExtendedIterator it1 = things( "now is the time" );
43         ExtendedIterator it2 = things( "now is the time" );
44         ExtendedIterator mt1 = things( "" );
45         ExtendedIterator mt2 = things( "" );
46         assertEquals( "mt1.hasNext()", false, mt1.hasNext() );
47         assertEquals( "mt2.hasNext()", false, mt2.hasNext() );
48         assertEquals( "andThen(mt1,mt2).hasNext()", false, mt1.andThen( mt2 ).hasNext() );
49         assertEquals( "butNot(it1,it2).hasNext()", false, Dyadic.butNot( it1, it2 ).hasNext() );
50         assertEquals( "x y z @butNot z", true, Dyadic.butNot( things( "x y z" ), things( "z" ) ).hasNext() );
51         assertEquals( "x y z @butNot a", true, Dyadic.butNot( things( "x y z" ), things( "z" ) ).hasNext() );
52         }
53     
54     public void testDyadicOperands()
55         {
56         Graph g = new GraphMem(), h = new GraphMem();
57         Dyadic d = new Dyadic( g, h )
58             {
59             public ExtendedIterator graphBaseFind( TripleMatch m ) { return null; }
60             };
61         assertSame( g, d.getL() );
62         assertSame( h, d.getR() );
63         }
64     }
65
66 /*
67     (c) Copyright 2002, 2004, 2005 Hewlett-Packard Development Company, LP
68     All rights reserved.
69
70     Redistribution and use in source and binary forms, with or without
71     modification, are permitted provided that the following conditions
72     are met:
73
74     1. Redistributions of source code must retain the above copyright
75        notice, this list of conditions and the following disclaimer.
76
77     2. Redistributions in binary form must reproduce the above copyright
78        notice, this list of conditions and the following disclaimer in the
79        documentation and/or other materials provided with the distribution.
80
81     3. The name of the author may not be used to endorse or promote products
82        derived from this software without specific prior written permission.
83
84     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
85     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
86     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
88     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
89     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
93     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94 */

95
Popular Tags