KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestIntersection.java,v 1.7 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.graph.*;
10 import com.hp.hpl.jena.graph.compose.Intersection;
11 import com.hp.hpl.jena.graph.test.*;
12 import com.hp.hpl.jena.rdf.model.*;
13 import junit.framework.*;
14
15 public class TestIntersection extends GraphTestBase
16     {
17     public TestIntersection( String JavaDoc name )
18         { super( name ); }
19         
20     public static TestSuite suite()
21         { return new TestSuite( TestIntersection.class ); }
22         
23     public void testIntersection()
24         {
25         Graph g1 = graphWith( "x R y; p R q" );
26         Graph g2 = graphWith( "r A s; x R y" );
27         Intersection i = new Intersection( g1, g2 );
28         assertContains( "Intersection", "x R y", i );
29         assertOmits( "Intersection", i, "p R q" );
30         assertOmits( "Intersection", i, "r A s" );
31         if (i.size() != 1)
32             fail( "oops: size of intersection is not 1" );
33         i.add( triple( "cats eat cheese" ) );
34         assertContains( "Intersection.L", "cats eat cheese", g1 );
35         assertContains( "Intersection.R", "cats eat cheese", g2 );
36     /* */
37         Graph L = graphWith( "a pings b; b pings c; c pings a" );
38         Graph R = graphWith( "c pings a; b pings c; x captures y" );
39         Graph join = new Intersection( L, R );
40         Model mJoin = modelFor( join );
41         Model mL = modelFor( L );
42         mL.remove( mJoin );
43         // mustHaveNone( L, "L after removal", "c pings a; b pings c; x captures y" );
44
// mustHave( L, "L after removal", "a pings b" );
45
if (!modelFor( R ).isIsomorphicWith( modelFor( graphWith( "c pings a; b pings c; x captures y" ) ) ))
46             {
47             show( "oops: R has changed", R );
48             fail( "" );
49             }
50         if (!mL.isIsomorphicWith( modelFor( graphWith( "a pings b" ) ) ))
51             {
52             show( "oops: L is", L );
53             fail( "oops: mL should be `a pings b`" );
54             }
55         }
56     }
57 /*
58     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
59     All rights reserved.
60
61     Redistribution and use in source and binary forms, with or without
62     modification, are permitted provided that the following conditions
63     are met:
64
65     1. Redistributions of source code must retain the above copyright
66        notice, this list of conditions and the following disclaimer.
67
68     2. Redistributions in binary form must reproduce the above copyright
69        notice, this list of conditions and the following disclaimer in the
70        documentation and/or other materials provided with the distribution.
71
72     3. The name of the author may not be used to endorse or promote products
73        derived from this software without specific prior written permission.
74
75     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
76     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
77     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
78     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
79     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
80     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
81     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
82     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
83     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
84     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 */

86
Popular Tags