1 6 package com.hp.hpl.jena.graph.compose.test; 7 8 import junit.framework.TestSuite; 9 10 import com.hp.hpl.jena.graph.Graph; 11 import com.hp.hpl.jena.graph.compose.DisjointUnion; 12 import com.hp.hpl.jena.graph.test.GraphTestBase; 13 14 18 public class TestDisjointUnion extends GraphTestBase 19 { 20 public TestDisjointUnion( String name ) 21 { super( name ); } 22 23 public static TestSuite suite() 24 { return new TestSuite( TestDisjointUnion.class ); } 25 26 public void testEmptyUnion() 27 { 28 DisjointUnion du = new DisjointUnion( Graph.emptyGraph, Graph.emptyGraph ); 29 assertEquals( true, du.isEmpty() ); 30 } 31 32 public void testLeftUnion() 33 { 34 Graph g = graphWith( "" ); 35 testSingleComponent( g, new DisjointUnion( g, Graph.emptyGraph ) ); 36 } 37 38 public void testRightUnion() 39 { 40 Graph g = graphWith( "" ); 41 testSingleComponent( g, new DisjointUnion( Graph.emptyGraph, g ) ); 42 } 43 44 protected void testSingleComponent( Graph g, DisjointUnion du ) 45 { 46 graphAdd( g, "x R y; a P b; x Q b" ); 47 assertIsomorphic( g, du ); 48 graphAdd( g, "roses growOn you" ); 49 assertIsomorphic( g, du ); 50 g.delete( triple( "a P b" ) ); 51 assertIsomorphic( g, du ); 52 } 53 54 public void testBothComponents() 55 { 56 Graph L = graphWith( "" ), R = graphWith( "" ); 57 Graph du = new DisjointUnion( L, R ); 58 assertIsomorphic( Graph.emptyGraph, du ); 59 L.add( triple( "x P y" ) ); 60 assertIsomorphic( graphWith( "x P y" ), du ); 61 R.add( triple( "A rdf:type Route" ) ); 62 assertIsomorphic( graphWith( "x P y; A rdf:type Route" ), du ); 63 } 64 65 public void testRemoveBoth() 66 { 67 Graph L = graphWith( "x R y; a P b" ), R = graphWith( "x R y; p Q r" ); 68 Graph du = new DisjointUnion( L, R ); 69 du.delete( triple( "x R y" ) ); 70 assertIsomorphic( graphWith( "a P b" ), L ); 71 assertIsomorphic( graphWith( "p Q r" ), R ); 72 } 73 74 public void testAddLeftOnlyIfNecessary() 75 { 76 Graph L = graphWith( "" ), R = graphWith( "x R y" ); 77 Graph du = new DisjointUnion( L, R ); 78 graphAdd( du, "x R y" ); 79 assertEquals( true, L.isEmpty() ); 80 graphAdd( du, " a P b" ); 81 assertIsomorphic( graphWith( "a P b" ), L ); 82 assertIsomorphic( graphWith( "x R y" ), R ); 83 } 84 } 85 86 87 | Popular Tags |