You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2014/11/10 11:51:47 UTC
[48/50] [abbrv] jena git commit: JENA-808 : Upgrades for composit
graphs. Remove deprecation.
JENA-808 : Upgrades for composit graphs. Remove deprecation.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/bc6c1fb7
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/bc6c1fb7
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/bc6c1fb7
Branch: refs/heads/hadoop-rdf
Commit: bc6c1fb7a7c5b38120b6bdfdd5ef97d17ce3b82e
Parents: b3f4e4c
Author: Andy Seaborne <an...@apache.org>
Authored: Sat Nov 8 19:37:17 2014 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Sat Nov 8 19:37:17 2014 +0000
----------------------------------------------------------------------
.../com/hp/hpl/jena/graph/compose/Delta.java | 43 ++++--
.../hp/hpl/jena/graph/compose/Difference.java | 1 -
.../hp/hpl/jena/graph/compose/Intersection.java | 4 +-
.../hpl/jena/graph/compose/test/TestDelta.java | 149 ++++++++++++++-----
.../jena/graph/compose/test/TestDifference.java | 119 +++++++++++----
.../hpl/jena/graph/compose/test/TestDyadic.java | 5 +-
.../graph/compose/test/TestIntersection.java | 138 +++++++++++------
.../jena/graph/compose/test/TestPackage.java | 9 +-
.../hpl/jena/graph/compose/test/TestUnion.java | 120 +++++++++++----
9 files changed, 415 insertions(+), 173 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Delta.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Delta.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Delta.java
index a977dfb..b7451f6 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Delta.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Delta.java
@@ -19,38 +19,46 @@
package com.hp.hpl.jena.graph.compose ;
import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.graph.impl.SimpleEventManager;
import com.hp.hpl.jena.util.iterator.* ;
/**
* Graph operation for wrapping a base graph and leaving it unchanged while
* recording all the attempted updates for later access.
+ *
+ * The behavior of this class is not well defined if triples are added to or
+ * removed from the base graph, the additions graph, or the deletions graph
+ * while this graph is in use.
*/
-@Deprecated
-public class Delta extends Dyadic implements Graph
+public class Delta extends CompositionBase implements Graph
{
private Graph base ;
+ private Graph additions ;
+ private Graph deletions ;
public Delta(Graph base)
{
- super(Factory.createGraphMem(), Factory.createGraphMem()) ;
+ super() ;
this.base = base ;
+ this.additions = Factory.createGraphMem();
+ this.deletions = Factory.createGraphMem();
}
/**
- * Answer the graph of all triples added
+ * Answer the graph of all triples added.
*/
public Graph getAdditions()
{
- return L ;
+ return additions ;
}
/**
- * Answer the graph of all triples removed
+ * Answer the graph of all triples removed.
*/
public Graph getDeletions()
{
- return R ;
+ return deletions ;
}
/**
@@ -60,9 +68,9 @@ public class Delta extends Dyadic implements Graph
@Override
public void performAdd(Triple t)
{
- if (!base.contains(t))
- L.add(t) ;
- R.delete(t) ;
+ if (!base.contains(t))
+ additions.add(t) ;
+ deletions.delete(t) ;
}
/**
@@ -71,9 +79,9 @@ public class Delta extends Dyadic implements Graph
@Override
public void performDelete(Triple t)
{
- L.delete(t) ;
- if (base.contains(t))
- R.add(t) ;
+ additions.delete(t) ;
+ if (base.contains(t))
+ deletions.add(t) ;
}
/**
@@ -81,9 +89,10 @@ public class Delta extends Dyadic implements Graph
* add the ones that have been added.
*/
@Override
- protected ExtendedIterator<Triple> _graphBaseFind(TripleMatch tm)
+ protected ExtendedIterator<Triple> graphBaseFind(TripleMatch tm)
{
- return base.find(tm).filterDrop(ifIn(GraphUtil.findAll(R))).andThen(L.find(tm)) ;
+ ExtendedIterator<Triple> iterator = base.find(tm).filterDrop(ifIn(GraphUtil.findAll(deletions))).andThen(additions.find(tm)) ;
+ return SimpleEventManager.notifyingRemove( this, iterator ) ;
}
@Override
@@ -91,11 +100,13 @@ public class Delta extends Dyadic implements Graph
{
super.close() ;
base.close() ;
+ additions.close() ;
+ deletions.close() ;
}
@Override
public int graphBaseSize()
{
- return base.size() + L.size() - R.size() ;
+ return base.size() + additions.size() - deletions.size() ;
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Difference.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Difference.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Difference.java
index 38e3d67..8aa9e72 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Difference.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Difference.java
@@ -25,7 +25,6 @@ import com.hp.hpl.jena.util.iterator.*;
Class representing the dynamic set difference L - R of two graphs. This is updatable;
the updates are written through to one or other of the base graphs.
*/
-@Deprecated
public class Difference extends Dyadic implements Graph
{
/**
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Intersection.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Intersection.java b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Intersection.java
index f04df47..c917bc8 100644
--- a/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Intersection.java
+++ b/jena-core/src/main/java/com/hp/hpl/jena/graph/compose/Intersection.java
@@ -29,10 +29,8 @@ import com.hp.hpl.jena.util.iterator.*;
/**
- an implementation of a dynamic intersection of two models.
+ The dynamic intersection of two graphs L and R. <code>add()</code> affects both L and R, whereas <code>delete()</code> affects L only.
*/
-
-@Deprecated
public class Intersection extends Dyadic implements Graph
{
public Intersection( Graph L, Graph R )
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDelta.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDelta.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDelta.java
index 2be1574..2eb517f 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDelta.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDelta.java
@@ -22,45 +22,116 @@ import junit.framework.TestSuite ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.compose.Delta ;
+import com.hp.hpl.jena.graph.test.AbstractTestGraph;
-@SuppressWarnings("deprecation")
-public class TestDelta extends TestDyadic
- {
-
- public TestDelta( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestDelta.class ); }
-
- @Override
- public Graph getGraph()
- {
- Graph gBase = graphWith( "" );
+public class TestDelta extends AbstractTestGraph
+{
+
+ private static final String DEFAULT_TRIPLES = "x R y; p S q";
+
+ public TestDelta( String name )
+ {
+ super( name );
+ }
+
+ public static TestSuite suite()
+ {
+ return new TestSuite( TestDelta.class );
+ }
+
+ @Override
+ public Graph getGraph()
+ {
+ Graph gBase = graphWith( "" );
return new Delta( gBase );
- }
-
- public void testDelta()
- {
- Graph x = graphWith( "x R y" );
- assertContains( "x", "x R y", x );
- x.delete( triple( "x R y" ) );
- assertOmits( "x", x, "x R y" );
- /* */
- Graph base = graphWith( "x R y; p S q; I like cheese; pins pop balloons" );
- Graph save = graphWith( "x R y; p S q; I like cheese; pins pop balloons" );
+ }
+
+ public void testDeltaMirrorsBase()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES );
+ Delta delta = new Delta( base );
+ assertIsomorphic(base, delta);
+ }
+
+ public void testAddGoesToAdditions()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES );
Delta delta = new Delta( base );
- assertContainsAll( "Delta", delta, "x R y; p S q; I like cheese; pins pop balloons" );
- assertContainsAll( "Delta", base, "x R y; p S q; I like cheese; pins pop balloons" );
- /* */
- delta.add( triple( "pigs fly winglessly" ) );
- delta.delete( triple( "I like cheese" ) );
- /* */
- assertContainsAll( "changed Delta", delta, "x R y; p S q; pins pop balloons; pigs fly winglessly" );
- assertOmits( "changed delta", delta, "I like cheese" );
- assertContains( "delta additions", "pigs fly winglessly", delta.getAdditions() );
- assertOmits( "delta additions", delta.getAdditions(), "I like cheese" );
- assertContains( "delta deletions", "I like cheese", delta.getDeletions() );
- assertOmits( "delta deletions", delta.getDeletions(), "pigs fly winglessly" );
- }
- }
+ delta.add( triple( "x R z" ) );
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "x R z" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "" ), delta.getDeletions());
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES + "; x R z" ), delta);
+ }
+
+ public void testDeleteGoesToDeletions()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES );
+ Delta delta = new Delta( base );
+ delta.delete( triple( "x R y" ) );
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "x R y" ), delta.getDeletions());
+ assertIsomorphic(graphWith( "p S q" ), delta);
+ }
+
+ public void testRedundantAddNoOp()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES );
+ Delta delta = new Delta( base ) ;
+ delta.add( triple( "x R y" ) ) ;
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "" ), delta.getDeletions());
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), delta);
+ }
+
+ public void testRedundantDeleteNoOp()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES ) ;
+ Delta delta = new Delta( base ) ;
+ delta.delete( triple( "a T b" ) ) ;
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "" ), delta.getDeletions());
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), delta);
+ }
+
+ public void testAddThenDelete()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES ) ;
+ Delta delta = new Delta( base ) ;
+ delta.add( triple( "a T b" ) ) ;
+ delta.delete( triple( "a T b" ) ) ;
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "" ), delta.getDeletions());
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), delta);
+ }
+
+ public void testDeleteThenAdd()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES ) ;
+ Delta delta = new Delta( base ) ;
+ delta.delete( triple( "p S q" ) ) ;
+ delta.add( triple( "p S q" ) ) ;
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "" ), delta.getDeletions());
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), delta);
+ }
+
+ public void testAddAndDelete()
+ {
+ Graph base = graphWith( DEFAULT_TRIPLES ) ;
+ Delta delta = new Delta( base ) ;
+ delta.delete( triple( "a T b" ) ) ;
+ delta.add( triple( "x R z" ) ) ;
+ delta.delete( triple( "p S q" ) ) ;
+ delta.add( triple( "a T b" ) ) ;
+ assertIsomorphic(graphWith( DEFAULT_TRIPLES ), base);
+ assertIsomorphic(graphWith( "a T b; x R z" ), delta.getAdditions());
+ assertIsomorphic(graphWith( "p S q" ), delta.getDeletions());
+ assertIsomorphic(graphWith( "x R y ; x R z; a T b" ), delta);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDifference.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDifference.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDifference.java
index 6af2c9c..0da6e70 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDifference.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDifference.java
@@ -23,34 +23,93 @@ import junit.framework.TestSuite ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.compose.Difference ;
-@SuppressWarnings("deprecation")
-public class TestDifference extends TestDyadic
- {
- public TestDifference( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestDifference.class ); }
-
- @Override
- public Graph getGraph()
- {
- Graph gBase = graphWith( "" ), g1 = graphWith( "" );
+public class TestDifference extends TestDyadic
+{
+ public TestDifference( String name )
+ { super( name ); }
+
+ public static TestSuite suite()
+ { return new TestSuite( TestDifference.class ); }
+
+ @Override
+ public Graph getGraph()
+ {
+ Graph gBase = graphWith( "" ), g1 = graphWith( "" );
return new Difference( gBase, g1 );
- }
-
- public void testDifference()
- {
- Graph g1 = graphWith( "x R y; p R q" );
- Graph g2 = graphWith( "r A s; x R y" );
- Difference d = new Difference( g1, g2 );
- assertOmits( "Difference", d, "x R y" );
- assertContains( "Difference", "p R q", d );
- assertOmits( "Difference", d, "r A s" );
- if (d.size() != 1)
- fail( "oops: size of difference is not 1" );
- d.add( triple( "cats eat cheese" ) );
- assertContains( "Difference.L", "cats eat cheese", g1 );
- assertOmits( "Difference.R", g2, "cats eat cheese" );
- }
- }
+ }
+
+ public Difference differenceOf(String s1, String s2) {
+ return new Difference( graphWith( s1 ), graphWith( s2 ) );
+ }
+
+ public void testStaticDifference() {
+ assertIsomorphic( differenceOf( "", "" ), graphWith( "" ) );
+ assertIsomorphic( differenceOf( "x R y", "" ), graphWith( "x R y" ) );
+ assertIsomorphic( differenceOf( "", "x R y" ), graphWith( "" ) );
+ assertIsomorphic( differenceOf( "x R y", "x R y" ), graphWith( "" ) );
+ assertIsomorphic( differenceOf( "x R y; p R q", "r A s; x R y" ), graphWith( "p R q" ) );
+ }
+
+ public void testDifferenceReflectsChangesToOperands() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "x R y" );
+ Difference diff = new Difference( l, r );
+ assertIsomorphic( diff, graphWith( "" ) );
+ r.delete( triple( "x R y" ) );
+ assertIsomorphic( diff, graphWith( "x R y" ) );
+ l.add( triple( "x R z" ) );
+ assertIsomorphic( diff, graphWith( "x R y; x R z" ) );
+ r.add( triple( "x R z" ) );
+ assertIsomorphic( diff, graphWith( "x R y" ) );
+ }
+
+ public void testAdd() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "x R y; x R z" );
+ Difference diff = new Difference( l, r );
+ assertIsomorphic( diff, graphWith( "" ) );
+
+ // case 1: add to the left operand
+ diff.add( triple( "p S q" ) );
+ assertIsomorphic( diff, graphWith( "p S q" ) );
+ assertIsomorphic( l, graphWith( "x R y; p S q" ) );
+ assertIsomorphic( r, graphWith( "x R y; x R z" ) );
+
+ // case 2: remove from the right, and add to the left operand
+ diff.add( triple( "x R z" ) );
+ assertIsomorphic( diff, graphWith( "x R z; p S q" ) );
+ assertIsomorphic( l, graphWith( "x R y; x R z; p S q" ) );
+ assertIsomorphic( r, graphWith( "x R y" ) );
+
+ // case 3: remove from the right operand
+ diff.add( triple( "x R y" ) );
+ assertIsomorphic( diff, graphWith( "x R y; x R z; p S q" ) );
+ assertIsomorphic( l, graphWith( "x R y; x R z; p S q" ) );
+ assertIsomorphic( r, graphWith( "" ) );
+ }
+
+ public void testDelete() {
+ Graph l = graphWith( "x R y; x R z" );
+ Graph r = graphWith( "x R y" );
+ Difference diff = new Difference( l, r );
+ assertIsomorphic( diff, graphWith( "x R z" ) );
+
+ // case 1: remove non-existent triple is a no-op
+ diff.delete( triple( "p S q" ) );
+ assertIsomorphic( diff, graphWith( "x R z" ) );
+ assertIsomorphic( l, graphWith( "x R y; x R z" ) );
+ assertIsomorphic( r, graphWith( "x R y" ) );
+
+ // case 2: remove triple that exists in both - removes from left
+ diff.delete( triple( "x R y" ) );
+ assertIsomorphic( diff, graphWith( "x R z" ) );
+ assertIsomorphic( l, graphWith( "x R z" ) );
+ assertIsomorphic( r, graphWith( "x R y" ) );
+
+ // case 3: remove triple that exists in left is removed
+ diff.delete( triple( "x R z" ) );
+ assertIsomorphic( diff, graphWith( "" ) );
+ assertIsomorphic( l, graphWith( "" ) );
+ assertIsomorphic( r, graphWith( "x R y" ) );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDyadic.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDyadic.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDyadic.java
index 6568157..bf802cd 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDyadic.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestDyadic.java
@@ -47,7 +47,10 @@ public abstract class TestDyadic extends AbstractTestGraph
};
}
- public void testDyadic()
+ /**
+ * Test the things() iterator generating utility function.
+ */
+ public void testThings()
{
ExtendedIterator<String> it1 = things( "now is the time" );
ExtendedIterator<String> it2 = things( "now is the time" );
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestIntersection.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestIntersection.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestIntersection.java
index ed53373..cf519b4 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestIntersection.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestIntersection.java
@@ -18,50 +18,104 @@
package com.hp.hpl.jena.graph.compose.test;
-import junit.framework.TestSuite ;
+import junit.framework.TestSuite;
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.GraphUtil ;
-import com.hp.hpl.jena.graph.compose.Intersection ;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.compose.Intersection;
-@SuppressWarnings("deprecation")
public class TestIntersection extends TestDyadic
- {
- public TestIntersection( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestIntersection.class ); }
-
- @Override
- public Graph getGraph()
- {
- Graph gBase = graphWith( "" ), g1 = graphWith( "" );
+{
+ public TestIntersection( String name )
+ { super( name ); }
+
+ public static TestSuite suite()
+ { return new TestSuite( TestIntersection.class ); }
+
+ @Override
+ public Graph getGraph()
+ {
+ Graph gBase = graphWith( "" ), g1 = graphWith( "" );
return new Intersection( gBase, g1 );
- }
-
- public void testIntersection()
- {
- Graph g1 = graphWith( "x R y; p R q" );
- Graph g2 = graphWith( "r A s; x R y" );
- Intersection i = new Intersection( g1, g2 );
- assertContains( "Intersection", "x R y", i );
- assertOmits( "Intersection", i, "p R q" );
- assertOmits( "Intersection", i, "r A s" );
- if (i.size() != 1)
- fail( "oops: size of intersection is not 1" );
- i.add( triple( "cats eat cheese" ) );
- assertContains( "Intersection.L", "cats eat cheese", g1 );
- assertContains( "Intersection.R", "cats eat cheese", g2 );
- }
+ }
+
+ public Intersection intersectionOf(String s1, String s2) {
+ return new Intersection( graphWith( s1 ), graphWith( s2 ) );
+ }
+
+ public void testStaticIntersection() {
+ assertIsomorphic( graphWith( "" ), intersectionOf( "", "" ) );
+ assertIsomorphic( graphWith( "" ), intersectionOf( "x R y", "" ) );
+ assertIsomorphic( graphWith( "" ), intersectionOf( "", "x R y" ) );
+ assertIsomorphic( graphWith( "x R y" ), intersectionOf( "x R y", "x R y" ) );
+ assertIsomorphic( graphWith( "x R y" ), intersectionOf( "x R y; p R q", "r A s; x R y" ) );
+ }
+
+ public void testIntersectionReflectsChangesToOperands() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "p S q" );
+ Intersection isec = new Intersection( l, r );
+ assertIsomorphic( graphWith( "" ), isec );
+
+ // add to the left what is already in the right
+ l.add( triple( "p S q" ) );
+ assertIsomorphic( graphWith( "p S q" ), isec );
+
+ // add to the right what is already in the left
+ r.add( triple( "x R y" ) );
+ assertIsomorphic( graphWith( "p S q; x R y" ), isec );
+
+ // add to a single graph is not reflected
+ l.add( triple( "p S o" ) );
+ r.add( triple( "x R z" ) );
+ assertIsomorphic( graphWith( "p S q; x R y" ), isec );
+
+ // remove from the left
+ l.delete( triple( "x R y" ) );
+ assertIsomorphic( graphWith( "p S q" ), isec );
+
+ // remove from the right
+ r.delete( triple( "p S q" ) );
+ assertIsomorphic( graphWith( "" ), isec );
+ }
+
+ public void testAdd() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "p S q" );
+ Intersection isec = new Intersection( l, r );
+ assertIsomorphic( graphWith( "" ), isec );
+
+ isec.add( triple( "r A s" ) );
+ assertIsomorphic( graphWith( "r A s" ), isec );
+ assertIsomorphic( graphWith( "x R y; r A s" ), l );
+ assertIsomorphic( graphWith( "p S q; r A s" ), r );
+
+ isec.add( triple ( "x R y" ) );
+ assertIsomorphic( graphWith( "r A s; x R y" ), isec );
+ assertIsomorphic( graphWith( "x R y; r A s" ), l );
+ assertIsomorphic( graphWith( "p S q; r A s; x R y" ), r );
+
+ isec.add( triple ( "p S q" ) );
+ assertIsomorphic( graphWith( "p S q; r A s; x R y" ), isec );
+ assertIsomorphic( graphWith( "p S q; r A s; x R y" ), l );
+ assertIsomorphic( graphWith( "p S q; r A s; x R y" ), r );
+ }
- public void testDeleteDoesNotUpdateR()
- {
- Graph L = graphWith( "a pings b; b pings c; c pings a" );
- Graph R = graphWith( "c pings a; b pings c; x captures y" );
- Graph join = new Intersection( L, R );
- GraphUtil.deleteFrom(L, R) ;
- assertIsomorphic( "R should not change", graphWith( "c pings a; b pings c; x captures y" ), R );
- assertIsomorphic( graphWith( "a pings b" ), L );
- }
- }
+ public void testDelete() {
+ Graph l = graphWith( "r A s; x R y" );
+ Graph r = graphWith( "x R y; p S q" );
+ Intersection isec = new Intersection( l, r );
+ assertIsomorphic( graphWith( "x R y" ), isec );
+
+ // removing non-contained triples is a no-op
+ isec.delete( triple( "r A s" ) );
+ assertIsomorphic( graphWith( "r A s; x R y" ), l);
+ isec.delete( triple( "p S q" ) );
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+
+ // removing a contained triple removes it from the left operand
+ isec.delete( triple( "x R y" ) );
+ assertIsomorphic( graphWith( "" ), isec );
+ assertIsomorphic( graphWith( "r A s" ), l );
+ assertIsomorphic( graphWith( "x R y; p S q" ), r );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestPackage.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestPackage.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestPackage.java
index a877875..ec1c892 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestPackage.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestPackage.java
@@ -32,14 +32,9 @@ import junit.framework.*;
public class TestPackage extends TestCase {
- @SuppressWarnings("deprecation")
public static TestSuite suite() {
TestSuite result = new TestSuite();
- /*
- suite( result, Intersection.class );
- suite( result, Union.class );
- suite( result, Difference.class );
- */
+
GraphModelFactory gmf = new GraphModelFactory(){
@Override
@@ -81,7 +76,6 @@ public class TestPackage extends TestCase {
{
result.addTest( atp.testAt(i) );
}
- //suite.addTestSuite( new PlainModelTestSuite( ))
/* */
result.addTest( TestDelta.suite() );
result.addTest( TestUnion.suite() );
@@ -95,7 +89,6 @@ public class TestPackage extends TestCase {
return result;
}
-
private static abstract class GraphModelFactory implements TestingModelFactory
{
abstract Graph getGraph();
http://git-wip-us.apache.org/repos/asf/jena/blob/bc6c1fb7/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestUnion.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestUnion.java b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestUnion.java
index e86cad8..cfc8e8e 100755
--- a/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestUnion.java
+++ b/jena-core/src/test/java/com/hp/hpl/jena/graph/compose/test/TestUnion.java
@@ -24,37 +24,91 @@ import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.compose.Union ;
public class TestUnion extends TestDyadic
- {
- public TestUnion( String name )
- { super( name ); }
-
- public static TestSuite suite()
- { return new TestSuite( TestUnion.class ); }
-
- @Override
- public Graph getGraph()
- {
- Graph gBase = graphWith( "" ), g1 = graphWith( "" );
+{
+ public TestUnion( String name )
+ { super( name ); }
+
+ public static TestSuite suite()
+ { return new TestSuite( TestUnion.class ); }
+
+ @Override
+ public Graph getGraph()
+ {
+ Graph gBase = graphWith( "" ), g1 = graphWith( "" );
return new Union( gBase, g1 );
- }
-
- public void testUnion()
- {
- Graph g1 = graphWith( "x R y; p R q" );
- Graph g2 = graphWith( "r A s; x R y" );
- Union u = new Union( g1, g2 );
- assertContains( "Union", "x R y", u );
- assertContains( "Union", "p R q", u );
- assertContains( "Union", "r A s", u );
- if (u.size() != 3)
- fail( "oops: size of union is not 3" );
- u.add( triple( "cats eat cheese" ) );
- assertContains( "Union", "cats eat cheese", u );
- if
- (
- contains( g1, "cats eat cheese" ) == false
- && contains( g2, "cats eat cheese" ) == false
- )
- fail( "oops: neither g1 nor g2 contains `cats eat cheese`" );
- }
- }
+ }
+
+ public Union unionOf( String s1, String s2 )
+ {
+ return new Union( graphWith( s1 ), graphWith ( s2 ) );
+ }
+
+ public void testStaticUnion()
+ {
+ assertIsomorphic(graphWith( "" ), unionOf( "", "" ));
+ assertIsomorphic(graphWith( "x R y" ), unionOf( "x R y", "" ) );
+ assertIsomorphic(graphWith( "x R y" ), unionOf( "", "x R y" ) );
+ assertIsomorphic(graphWith( "x R y; x R z" ), unionOf( "x R y", "x R z" ) );
+ assertIsomorphic(graphWith( "x R y" ), unionOf( "x R y", "x R y" ) );
+ }
+
+ public void testUnionReflectsChangesToOperands() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "x R y" );
+ Union u = new Union( l, r );
+
+ assertIsomorphic( graphWith( "x R y" ), u );
+
+ l.add( triple( "x R z" ) );
+ assertIsomorphic( graphWith( "x R y; x R z" ), u );
+
+ l.delete( triple( "x R y" ) );
+ assertIsomorphic( graphWith( "x R y; x R z" ), u );
+
+ r.add( triple( "p S q" ) );
+ assertIsomorphic( graphWith( "x R y; x R z; p S q" ), u );
+
+ r.delete( triple( "x R y" ) );
+ assertIsomorphic( graphWith( "x R z; p S q" ), u );
+ }
+
+ public void testAdd() {
+ Graph l = graphWith( "x R y" );
+ Graph r = graphWith( "x R y; p S q" );
+ Union u = new Union( l, r );
+
+ u.add( triple("x R y") );
+ assertIsomorphic( graphWith( "x R y" ), l);
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+
+ u.add( triple("p S q") );
+ assertIsomorphic( graphWith( "x R y; p S q" ), l);
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+
+ u.add( triple("r A s") );
+ assertIsomorphic( graphWith( "x R y; p S q; r A s" ), l);
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+ }
+
+ public void testDelete() {
+ Graph l = graphWith( "x R y; x R z" );
+ Graph r = graphWith( "x R y; p S q" );
+ Union u = new Union( l, r );
+
+ u.delete( triple( "r A s" ) );
+ assertIsomorphic( graphWith( "x R y; x R z" ), l);
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+
+ u.delete( triple( "x R z" ) );
+ assertIsomorphic( graphWith( "x R y" ), l);
+ assertIsomorphic( graphWith( "x R y; p S q" ), r);
+
+ u.delete( triple ( "p S q" ) );
+ assertIsomorphic( graphWith( "x R y" ), l);
+ assertIsomorphic( graphWith( "x R y" ), r);
+
+ u.delete( triple ( "x R y" ) );
+ assertIsomorphic( graphWith( "" ), l);
+ assertIsomorphic( graphWith( "" ), r);
+ }
+}