1 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 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 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 86 | Popular Tags |