use of org.apache.jena.graph.compose.Difference in project jena by apache.
the class DifferenceTest method testDifference.
@ContractTest
public void testDifference() {
Graph g1 = graphWith("x R y; p R q");
Graph g2 = graphWith("r Foo s; x R y");
Graph d = new Difference(g1, g2);
assertOmits("Difference", d, "x R y");
assertContains("Difference", "p R q", d);
assertOmits("Difference", d, "r Foo 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");
}
use of org.apache.jena.graph.compose.Difference in project jena by apache.
the class TestDifference method testAdd.
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(graphWith(""), diff);
// case 1: add to the left operand
diff.add(triple("p S q"));
assertIsomorphic(graphWith("p S q"), diff);
assertIsomorphic(graphWith("x R y; p S q"), l);
assertIsomorphic(graphWith("x R y; x R z"), r);
// case 2: remove from the right, and add to the left operand
diff.add(triple("x R z"));
assertIsomorphic(graphWith("x R z; p S q"), diff);
assertIsomorphic(graphWith("x R y; x R z; p S q"), l);
assertIsomorphic(graphWith("x R y"), r);
// case 3: remove from the right operand
diff.add(triple("x R y"));
assertIsomorphic(graphWith("x R y; x R z; p S q"), diff);
assertIsomorphic(graphWith("x R y; x R z; p S q"), l);
assertIsomorphic(graphWith(""), r);
}
use of org.apache.jena.graph.compose.Difference in project jena by apache.
the class TestDifference method testDelete.
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(graphWith("x R z"), diff);
// case 1: remove non-existent triple is a no-op
diff.delete(triple("p S q"));
assertIsomorphic(graphWith("x R z"), diff);
assertIsomorphic(graphWith("x R y; x R z"), l);
assertIsomorphic(graphWith("x R y"), r);
// case 2: remove triple that exists in both - removes from left
diff.delete(triple("x R y"));
assertIsomorphic(graphWith("x R z"), diff);
assertIsomorphic(graphWith("x R z"), l);
assertIsomorphic(graphWith("x R y"), r);
// case 3: remove triple that exists in left is removed
diff.delete(triple("x R z"));
assertIsomorphic(graphWith(""), diff);
assertIsomorphic(graphWith(""), l);
assertIsomorphic(graphWith("x R y"), r);
}
use of org.apache.jena.graph.compose.Difference in project jena by apache.
the class TestDifference method testDifferenceReflectsChangesToOperands.
public void testDifferenceReflectsChangesToOperands() {
Graph l = graphWith("x R y");
Graph r = graphWith("x R y");
Difference diff = new Difference(l, r);
assertIsomorphic(graphWith(""), diff);
r.delete(triple("x R y"));
assertIsomorphic(graphWith("x R y"), diff);
l.add(triple("x R z"));
assertIsomorphic(graphWith("x R y; x R z"), diff);
r.add(triple("x R z"));
assertIsomorphic(graphWith("x R y"), diff);
}
Aggregations